-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[Bug] Nextcloud Encryption breaks with OpenSSL 3.x due to legacy RC4 usage #32003
Comments
I ran into this after upgrading to Ubuntu 22.04 LTS with Nextcloud 24rc1. Is there a plan to migrate to a nonlegacy cipher for server-side encryption? |
Same Issue here.
|
Hello, I can confirm that the changes to the openssl.cnf as suggested by @MartB got everything working again, so thank you for that. Will this affect every Nextcloud-User with enabled encryption, or just those who have enabled Thank you for your work, have a nice day, |
This comment was marked as resolved.
This comment was marked as resolved.
@lum4chi Just follow the code for a bit you will eventually end up at the RC4 line i quoted. They indeed need to be added without the ##, as outlined in the comment from the developers
@brotkastn I never had |
Hi. @MartB the openssl.cnf that must be modified is that one present in /etc/ssl folder? Because I have tried to modify this file but encrypted files still not could be decrypted. Thank you |
@antoniotvr a safe bet is to refer to your specific distribution manual. If this does not work for whatever reason and your php is using the same openssl as your system, running For Fedora 36 it is |
@MartB thank you. The OPENSSLDIR is /usr/lib/ssl and the openssl.cnf is a symbolic link to that one contained in /etc/ssl folder. /usr/lib/ssl# ls -l I don't know why I have activated legacy_sect as you have indicated but still not works. Thank you |
Wouldn't it be better for NextCloud to upgrade to a current secure encryption rather than requiring that we enable one that is basically as good as plaintext? |
Exactly and that's the reason I labeled the above as a workaround only. RC4 was acceptable in the past, but security and packaging issues like this one, make it impossible to justify continued usage. |
Isn't this the PR that will fix this? |
A possibility could be to wrap // define as a constant to speed up decryptions
define("REPLACE_RC4_ALGO", checkReplaceRC4Algo());
function checkReplaceRC4Algo() {
// with OpenSSL v3 we assume that we have to replace the RC4 algo
$result = (OPENSSL_VERSION_NUMBER >= 0x30000000);
if ($result) {
// maybe someone has re-enabled the legacy support in OpenSSL v3
$result = (false === openssl_encrypt("test", "rc4", "test", OPENSSL_RAW_DATA, null, $tag, null, 0));
}
return $result;
}
// hands-down implementation of RC4
function rc4($data, $secret) {
$result = false;
// initialize $state
$state = [];
for ($i = 0x00; $i <= 0xFF; $i++) {
$state[$i] = $i;
}
// mix $secret into $state
$indexA = 0x00;
$indexB = 0x00;
for ($i = 0x00; $i <= 0xFF; $i++) {
$indexB = ($indexB + ord($secret[$indexA]) + $state[$i]) % 0x100;
$tmp = $state[$i];
$state[$i] = $state[$indexB];
$state[$indexB] = $tmp;
$indexA = ($indexA + 0x01) % strlen($secret);
}
// decrypt $data with $state
$indexA = 0x00;
$indexB = 0x00;
$result = "";
for ($i = 0x00; $i < strlen($data); $i++) {
$indexA = ($indexA + 0x01) % 0x100;
$indexB = ($state[$indexA] + $indexB) % 0x100;
$tmp = $state[$indexA];
$state[$indexA] = $state[$indexB];
$state[$indexB] = $tmp;
$result .= chr(ord($data[$i]) ^ $state[($state[$indexA] + $state[$indexB]) % 0x100]);
}
return $result;
}
function wrapped_openssl_open($data, &$output, $encrypted_key, $private_key, $cipher_algo, $iv = null) {
$result = false;
if ((0 === strcasecmp($cipher_algo, "rc4")) && REPLACE_RC4_ALGO) {
if (openssl_private_decrypt($encrypted_key, $intermediate, $private_key, OPENSSL_PKCS1_PADDING)) {
$output = rc4($data, $intermediate);
$result = (false !== $output);
}
} else {
$result = openssl_open($data, $output, $encrypted_key, $private_key, $cipher_algo, $iv);
}
return $result;
} |
The workaround works great. It has some issues in the webpage, but at least I could save my data. For ubuntu server users, the file is in /usr/lib/ssl/openssl.cnf Please post in this thread in case they fixed the status quo. Won't update or touch it while it ain't totally broken. |
On the two Ubuntu 22.04 servers I've looked at the file is /usr/lib/ssl/openssl.cnf |
I experienced this as well tonight after an upgrade to 22.04 and can confirm the mentioned fix works. Hopefully developers can do something about it. |
Since OpenSSL 3.x will soon be the preferred SSL Library in most Distributions this issue should be fixed in the near future I think! Would be great to hear some comment from a Dev on that Topic! |
Problem still exists in Nextcloud 25.0.0 RC3 and RC4 requiring the overrides from @MartB Note: On Debian / Ubuntu based systems, the changes / additions need to be added to
|
This is not helpful in fixing or diagnosing the problem.
I am dependent on the service I am hosting and have broken my MariaDB to an unfixable degree once, so I had to reformat everything. However I would like to get rid of the current legacy limitations in the web view. |
@Noob3103 I can confirm you this is not an ARM specific issue, running on x86_64 (on a server) I've encountered the same issue. As long as your OpenSSL version is updated to a certain version, the RC4 is deprecated and breaks the server side encryption on the webview. |
@Noob3103 Also for people who are trying out the workaround on php8.1-fpm, you may need to restart it via the following command to reload the OpenSSL config.
|
Same issue, same workaround at now!, NC 25.0.2 Ubuntu 22.04 |
I thought it might be interesting for the participants of this issue to know that I developed a fix for it in #35916. |
I am surprised that this is still not fixed. |
It will be in NC 26. |
Is there a way to apply the workaround to Docker? I can't find the specified directories anywhere. |
that would be very helpful! |
Should be fixed by #36173 (NC26) |
For anyone else running PHP via PHP-FPM, you need to restart the PHP-FPM service to reload the openssl config. My changes to my openssl.cnf weren't taking for some reason - took me a while to realize what was going on. |
That would be very helpful indeed, because there is no workaround for docker image at the time :( |
But there is, you can pass whatever to docker image, just have a config locally on your machine that you mount. I am using Unraid and Nextcloud linuxserver image |
Just fyi: I am not deploying Nextcloud anymore, so expect no feedback from me. From looking at the code in #36173, a temporary workaround has been implemented. Feel free to close, thanks for contributing everyone! |
I updated to v26 and reverted the OpenSSL changes in my config. Nextcloud seems to work fine now with OpenSSL 3.x |
I had the issue for a few weeks running linuxserver.io's NextCloud docker image. This morning I got a notification there was a upgrade available (v26). After upgrading the issue has disappeared. The con of using docker images are that they are quite static. Since editing the OpenSSL config seemed hard in my case, I just decided to wait for v26 and it paid off! 👍 |
Fixed by #36173 (NC v26) |
ℹ️ Should be fixed by #36173 (NC26)
server/apps/encryption/lib/Crypto/Crypt.php
Line 689 in 6fa62e9
Completely breaks the encryption on any system with the default openssl 3.0 config (legacy ciphers are now disabled).
Error example if this inevitably starts happening for fedora 36 et. al
Workaround (from within the distribution openssl.conf)
The text was updated successfully, but these errors were encountered: