Skip to content

Commit caf21ad

Browse files
committedMay 6, 2012
Fix #14087: Installation: create a cryptographically secure master salt
Commit 3f0f379 automatically generated a value for $g_crypto_master_salt during installation based on a very weak mechanism -- an MD5 hash of the current server time. This commit correctly generates a 256bit cryptographically secure salt instead, based on a much stronger source of randomness such as OpenSSL's PRNG or /dev/urandom on Linux systems. When a secure salt cannot be generated the user will need to manually define $g_crypto_master_salt post installation. Carriage return characters have also been removed from the default generated config_inc.php file. These characters are redundant and do not match the line termination standard used throughout MantisBT's code base.
1 parent 3f0f379 commit caf21ad

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed
 

‎admin/install.php

+21-14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
@require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
3535
require_api( 'install_helper_functions_api.php' );
36+
require_api( 'crypto_api.php' );
3637
$g_error_send_page_header = false; # bypass page headers in error handler
3738

3839
$g_failed = false;
@@ -712,7 +713,7 @@ function InsertData( $p_table, $p_data ) {
712713
if( $f_log_queries ) {
713714
if( $t_sql ) {
714715
foreach( $sqlarray as $sql ) {
715-
echo htmlentities( $sql ) . ";\r\n\r\n";
716+
echo htmlentities( $sql ) . ";\n\n";
716717
}
717718
}
718719
} else {
@@ -741,7 +742,7 @@ function InsertData( $p_table, $p_data ) {
741742
}
742743
if( $f_log_queries ) {
743744
# add a query to set the database version
744-
echo 'INSERT INTO ' . db_get_table( 'config' ) . ' ( value, type, access_reqd, config_id, project_id, user_id ) VALUES (\'' . $lastid . '\', 1, 90, \'database_version\', 0, 0 );' . "\r\n";
745+
echo 'INSERT INTO ' . db_get_table( 'config' ) . ' ( value, type, access_reqd, config_id, project_id, user_id ) VALUES (\'' . $lastid . '\', 1, 90, \'database_version\', 0, 0 );' . "\n";
745746
echo '</pre><br /><p style="color:red">Your database has not been created yet. Please create the database, then install the tables and data using the information above before proceeding.</p></td></tr>';
746747
}
747748
}
@@ -801,22 +802,28 @@ function InsertData( $p_table, $p_data ) {
801802
?>
802803
</td>
803804
<?php
804-
$t_config = '<?php' . "\r\n";
805-
$t_config .= "\t\$g_hostname = '$f_hostname';\r\n";
806-
$t_config .= "\t\$g_db_type = '$f_db_type';\r\n";
807-
$t_config .= "\t\$g_database_name = '$f_database_name';\r\n";
808-
$t_config .= "\t\$g_db_username = '$f_db_username';\r\n";
809-
$t_config .= "\t\$g_db_password = '$f_db_password';\r\n";
805+
$t_config = '<?php' . "\n";
806+
$t_config .= "\t\$g_hostname = '$f_hostname';\n";
807+
$t_config .= "\t\$g_db_type = '$f_db_type';\n";
808+
$t_config .= "\t\$g_database_name = '$f_database_name';\n";
809+
$t_config .= "\t\$g_db_username = '$f_db_username';\n";
810+
$t_config .= "\t\$g_db_password = '$f_db_password';\n";
810811

811812
if( $f_db_type == 'db2' ) {
812-
$t_config .= "\t\$g_db_schema = '$f_db_schema';\r\n";
813+
$t_config .= "\t\$g_db_schema = '$f_db_schema';\n";
813814
}
814815

815-
$t_config .= "\r\n";
816-
817-
# generate a crypto salt based on time of installation.
818-
$t_crypto_master_salt = md5((string)time());
819-
$t_config .= "\t\$g_crypto_master_salt = '$t_crypto_master_salt';\r\n";
816+
$t_config .= "\n";
817+
818+
/* Automatically generate a strong master salt/nonce for MantisBT
819+
* cryptographic purposes. If a strong source of randomness is not
820+
* available the user will have to manually set this value post
821+
* installation.
822+
*/
823+
$t_crypto_master_salt = crypto_generate_random_string(32);
824+
if ($t_crypto_master_salt !== null) {
825+
$t_config .= "\t\$g_crypto_master_salt = '$t_crypto_master_salt';\n";
826+
}
820827

821828
$t_write_failed = true;
822829

0 commit comments

Comments
 (0)
Please sign in to comment.