|
11 | 11 | use PhpMyAdmin\Sanitize; |
12 | 12 | use PhpMyAdmin\Setup\Index as SetupIndex; |
13 | 13 | use PhpMyAdmin\Url; |
14 | | -use PhpMyAdmin\Util; |
15 | 14 |
|
16 | 15 | use function __; |
17 | | -use function count; |
18 | 16 | use function function_exists; |
19 | 17 | use function htmlspecialchars; |
20 | | -use function implode; |
21 | 18 | use function ini_get; |
22 | | -use function preg_match; |
| 19 | +use function is_string; |
| 20 | +use function mb_strlen; |
| 21 | +use function sodium_crypto_secretbox_keygen; |
23 | 22 | use function sprintf; |
24 | | -use function strlen; |
| 23 | + |
| 24 | +use const SODIUM_CRYPTO_SECRETBOX_KEYBYTES; |
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * Performs various compatibility, security and consistency checks on current config |
@@ -247,9 +247,12 @@ protected function performConfigChecksServersSetBlowfishSecret( |
247 | 247 | $cookieAuthServer, |
248 | 248 | $blowfishSecretSet |
249 | 249 | ): array { |
250 | | - if ($cookieAuthServer && $blowfishSecret === null) { |
| 250 | + if ( |
| 251 | + $cookieAuthServer |
| 252 | + && (! is_string($blowfishSecret) || mb_strlen($blowfishSecret, '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) |
| 253 | + ) { |
251 | 254 | $blowfishSecretSet = true; |
252 | | - $this->cfg->set('blowfish_secret', Util::generateRandom(32)); |
| 255 | + $this->cfg->set('blowfish_secret', sodium_crypto_secretbox_keygen()); |
253 | 256 | } |
254 | 257 |
|
255 | 258 | return [ |
@@ -345,55 +348,21 @@ protected function performConfigChecksCookieAuthUsed( |
345 | 348 | ): void { |
346 | 349 | // $cfg['blowfish_secret'] |
347 | 350 | // it's required for 'cookie' authentication |
348 | | - if (! $cookieAuthUsed) { |
349 | | - return; |
350 | | - } |
351 | | - |
352 | | - if ($blowfishSecretSet) { |
353 | | - // 'cookie' auth used, blowfish_secret was generated |
354 | | - SetupIndex::messagesSet( |
355 | | - 'notice', |
356 | | - 'blowfish_secret_created', |
357 | | - Descriptions::get('blowfish_secret'), |
358 | | - Sanitize::sanitizeMessage(__( |
359 | | - 'You didn\'t have blowfish secret set and have enabled ' |
360 | | - . '[kbd]cookie[/kbd] authentication, so a key was automatically ' |
361 | | - . 'generated for you. It is used to encrypt cookies; you don\'t need to ' |
362 | | - . 'remember it.' |
363 | | - )) |
364 | | - ); |
365 | | - |
366 | | - return; |
367 | | - } |
368 | | - |
369 | | - $blowfishWarnings = []; |
370 | | - // check length |
371 | | - if (strlen($blowfishSecret) < 32) { |
372 | | - // too short key |
373 | | - $blowfishWarnings[] = __('Key is too short, it should have at least 32 characters.'); |
374 | | - } |
375 | | - |
376 | | - // check used characters |
377 | | - $hasDigits = (bool) preg_match('/\d/', $blowfishSecret); |
378 | | - $hasChars = (bool) preg_match('/\S/', $blowfishSecret); |
379 | | - $hasNonword = (bool) preg_match('/\W/', $blowfishSecret); |
380 | | - if (! $hasDigits || ! $hasChars || ! $hasNonword) { |
381 | | - $blowfishWarnings[] = Sanitize::sanitizeMessage( |
382 | | - __( |
383 | | - 'Key should contain letters, numbers [em]and[/em] special characters.' |
384 | | - ) |
385 | | - ); |
386 | | - } |
387 | | - |
388 | | - if (empty($blowfishWarnings)) { |
| 351 | + if (! $cookieAuthUsed || ! $blowfishSecretSet) { |
389 | 352 | return; |
390 | 353 | } |
391 | 354 |
|
| 355 | + // 'cookie' auth used, blowfish_secret was generated |
392 | 356 | SetupIndex::messagesSet( |
393 | | - 'error', |
394 | | - 'blowfish_warnings' . count($blowfishWarnings), |
| 357 | + 'notice', |
| 358 | + 'blowfish_secret_created', |
395 | 359 | Descriptions::get('blowfish_secret'), |
396 | | - implode('<br>', $blowfishWarnings) |
| 360 | + Sanitize::sanitizeMessage(__( |
| 361 | + 'You didn\'t have blowfish secret set and have enabled ' |
| 362 | + . '[kbd]cookie[/kbd] authentication, so a key was automatically ' |
| 363 | + . 'generated for you. It is used to encrypt cookies; you don\'t need to ' |
| 364 | + . 'remember it.' |
| 365 | + )) |
397 | 366 | ); |
398 | 367 | } |
399 | 368 |
|
|
0 commit comments