Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to AES-256-GCM for openssl_seal/open #25551

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions apps/encryption/lib/Crypto/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,25 @@ public function multiKeyDecrypt($encKeyFile, $shareKey, $privateKey) {
throw new MultiKeyDecryptException('Cannot multikey decrypt empty plain content');
}

$prev = null;

// We need to be able to extract the IV
if (strlen($encKeyFile) > 12) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean we'd always go into this block or do I miss something? Is there a case in which this is =< 12 for older files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure might be for older files yes...

$iv = substr($encKeyFile, -12);
$encrypted = substr($encKeyFile, 0, -12);

if (openssl_open($encrypted, $plainContent, $shareKey, $privateKey, 'aes-256-gcm', $iv)) {
return $plainContent;
}

$prev = new MultiKeyDecryptException('multikeydecrypt with share key failed (aes-256-gcm):' . openssl_error_string());
}

if (openssl_open($encKeyFile, $plainContent, $shareKey, $privateKey, 'RC4')) {
return $plainContent;
} else {
throw new MultiKeyDecryptException('multikeydecrypt with share key failed:' . openssl_error_string());
}

throw new MultiKeyDecryptException('multikeydecrypt with share key failed (rc4):' . openssl_error_string(), '', 0, $prev);
}

/**
Expand All @@ -732,7 +746,8 @@ public function multiKeyEncrypt($plainContent, array $keyFiles) {
$shareKeys = [];
$mappedShareKeys = [];

if (openssl_seal($plainContent, $sealed, $shareKeys, $keyFiles, 'RC4')) {
$iv = \random_bytes(12);
if (openssl_seal($plainContent, $sealed, $shareKeys, $keyFiles, 'aes-256-gcm', $iv)) {
$i = 0;

// Ensure each shareKey is labelled with its corresponding key id
Expand All @@ -743,11 +758,10 @@ public function multiKeyEncrypt($plainContent, array $keyFiles) {

return [
'keys' => $mappedShareKeys,
'data' => $sealed
'data' => $sealed . $iv,
];
} else {
throw new MultiKeyEncryptException('multikeyencryption failed ' . openssl_error_string());
}
throw new MultiKeyEncryptException('multikeyencryption failed ' . openssl_error_string());
}

public function useLegacyBase64Encoding(): bool {
Expand Down