Skip to content

Commit

Permalink
Fix problems with Blowfish migration. (NatLibFi#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Apr 24, 2023
1 parent 083f0ba commit 85d664e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function getSecureAlgorithmAndKey()
{
// Make example hash for AES
$alpha = 'abcdefghijklmnopqrstuvwxyz';
$chars = str_repeat($alpha . strtoupper($alpha) . '0123456789,.@#$%^&*', 4);
$chars = str_repeat($alpha . strtoupper($alpha) . '0123456789,.@#%^&*', 4);
return ['aes', substr(str_shuffle($chars), 0, 32)];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,22 @@ function ($select) {
$output->writeln("\tConverting hashes for " . count($users) . ' user(s).');
foreach ($users as $row) {
$pass = null;
if ($oldhash != 'none' && isset($row['cat_pass_enc'])) {
$oldcipher = new BlockCipher($oldCrypt);
$oldcipher->setKey($oldkey);
$pass = $oldcipher->decrypt($row['cat_pass_enc']);
if ($oldhash != 'none' && $row['cat_pass_enc'] ?? null !== null) {
try {
$oldcipher = new BlockCipher($oldCrypt);
$oldcipher->setKey($oldkey);
$pass = $oldcipher->decrypt($row['cat_pass_enc']);
} catch (\Exception $e) {
$output->writeln("Problem with user {$row['username']}: " . (string)$e);
continue;
}
} else {
$pass = $row['cat_password'];
}
$newcipher = new BlockCipher($newCrypt);
$newcipher->setKey($newkey);
$row['cat_password'] = null;
$row['cat_pass_enc'] = $newcipher->encrypt($pass);
$row['cat_pass_enc'] = $pass === null ? null : $newcipher->encrypt($pass);
$row->save();
}

Expand Down

0 comments on commit 85d664e

Please sign in to comment.