Skip to content

Commit 2580440

Browse files
authored
Merge pull request #198470 from RaitoBezarius/nc25-openssl
nextcloud25: use openssl 1.1 as a PHP extension to fix RC4 encryption
2 parents 8c6c94d + 35b146c commit 2580440

File tree

9 files changed

+227
-6
lines changed

9 files changed

+227
-6
lines changed

nixos/doc/manual/from_md/release-notes/rl-2211.section.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,23 @@
629629
binaries, use the <literal>p4d</literal> package instead.
630630
</para>
631631
</listitem>
632+
<listitem>
633+
<para>
634+
The <literal>openssl</literal>-extension for the PHP
635+
interpreter used by Nextcloud is built against OpenSSL 1.1 if
636+
<xref linkend="opt-system.stateVersion" /> is below
637+
<literal>22.11</literal>. This is to make sure that people
638+
using
639+
<link xlink:href="https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/encryption_configuration.html">server-side
640+
encryption</link> don’t loose access to their files.
641+
</para>
642+
<para>
643+
In any other case it’s safe to use OpenSSL 3 for PHP’s openssl
644+
extension. This can be done by setting
645+
<xref linkend="opt-services.nextcloud.enableBrokenCiphersForSSE" />
646+
to <literal>false</literal>.
647+
</para>
648+
</listitem>
632649
<listitem>
633650
<para>
634651
The <literal>coq</literal> package and versioned variants

nixos/doc/manual/release-notes/rl-2211.section.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ Available as [services.patroni](options.html#opt-services.patroni.enable).
204204

205205
- The `p4` package now only includes the open-source Perforce Helix Core command-line client and APIs. It no longer installs the unfree Helix Core Server binaries `p4d`, `p4broker`, and `p4p`. To install the Helix Core Server binaries, use the `p4d` package instead.
206206

207+
- The `openssl`-extension for the PHP interpreter used by Nextcloud is built against OpenSSL 1.1 if
208+
[](#opt-system.stateVersion) is below `22.11`. This is to make sure that people using [server-side encryption](https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/encryption_configuration.html)
209+
don't loose access to their files.
210+
211+
In any other case it's safe to use OpenSSL 3 for PHP's openssl extension. This can be done by setting
212+
[](#opt-services.nextcloud.enableBrokenCiphersForSSE) to `false`.
213+
207214
- The `coq` package and versioned variants starting at `coq_8_14` no
208215
longer include CoqIDE, which is now available through
209216
`coqPackages.coqide`. It is still possible to get CoqIDE as part of

nixos/modules/services/web-apps/nextcloud.nix

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ let
1313
phpPackage = cfg.phpPackage.buildEnv {
1414
extensions = { enabled, all }:
1515
(with all;
16-
enabled
16+
# disable default openssl extension
17+
(lib.filter (e: e.pname != "php-openssl") enabled)
18+
# use OpenSSL 1.1 for RC4 Nextcloud encryption if user
19+
# has acknowledged the brokeness of the ciphers (RC4).
20+
# TODO: remove when https://github.com/nextcloud/server/issues/32003 is fixed.
21+
++ (if cfg.enableBrokenCiphersForSSE then [ cfg.phpPackage.extensions.openssl-legacy ] else [ cfg.phpPackage.extensions.openssl ])
1722
++ optional cfg.enableImagemagick imagick
1823
# Optionally enabled depending on caching settings
1924
++ optional cfg.caching.apcu apcu
@@ -80,6 +85,40 @@ in {
8085

8186
options.services.nextcloud = {
8287
enable = mkEnableOption (lib.mdDoc "nextcloud");
88+
89+
enableBrokenCiphersForSSE = mkOption {
90+
type = types.bool;
91+
default = versionOlder stateVersion "22.11";
92+
defaultText = literalExpression "versionOlder system.stateVersion \"22.11\"";
93+
description = lib.mdDoc ''
94+
This option enables using the OpenSSL PHP extension linked against OpenSSL 1.1
95+
rather than latest OpenSSL (≥ 3), this is not recommended unless you need
96+
it for server-side encryption (SSE). SSE uses the legacy RC4 cipher which is
97+
considered broken for several years now. See also [RFC7465](https://datatracker.ietf.org/doc/html/rfc7465).
98+
99+
This cipher has been disabled in OpenSSL ≥ 3 and requires
100+
a specific legacy profile to re-enable it.
101+
102+
If you deploy Nextcloud using OpenSSL ≥ 3 for PHP and have
103+
server-side encryption configured, you will not be able to access
104+
your files anymore. Enabling this option can restore access to your files.
105+
Upon testing we didn't encounter any data corruption when turning
106+
this on and off again, but this cannot be guaranteed for
107+
each Nextcloud installation.
108+
109+
It is `true` by default for systems with a [](#opt-system.stateVersion) below
110+
`22.11` to make sure that existing installations won't break on update. On newer
111+
NixOS systems you have to explicitly enable it on your own.
112+
113+
Please note that this only provides additional value when using
114+
external storage such as S3 since it's not an end-to-end encryption.
115+
If this is not the case,
116+
it is advised to [disable server-side encryption](https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/encryption_configuration.html#disabling-encryption) and set this to `false`.
117+
118+
In the future, Nextcloud may move to AES-256-GCM, by then,
119+
this option will be removed.
120+
'';
121+
};
83122
hostName = mkOption {
84123
type = types.str;
85124
description = lib.mdDoc "FQDN for the nextcloud instance.";
@@ -649,6 +688,23 @@ in {
649688
++ (optional (versionOlder cfg.package.version "23") (upgradeWarning 22 "22.05"))
650689
++ (optional (versionOlder cfg.package.version "24") (upgradeWarning 23 "22.05"))
651690
++ (optional (versionOlder cfg.package.version "25") (upgradeWarning 24 "22.11"))
691+
++ (optional cfg.enableBrokenCiphersForSSE ''
692+
You're using PHP's openssl extension built against OpenSSL 1.1 for Nextcloud.
693+
This is only necessary if you're using Nextcloud's server-side encryption.
694+
Please keep in mind that it's using the broken RC4 cipher.
695+
696+
If you don't use that feature, you can switch to OpenSSL 3 and get
697+
rid of this warning by declaring
698+
699+
services.nextcloud.enableBrokenCiphersForSSE = false;
700+
701+
If you need to use server-side encryption you can ignore this waring.
702+
Otherwise you'd have to disable server-side encryption first in order
703+
to be able to safely disable this option and get rid of this warning.
704+
See <https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/encryption_configuration.html#disabling-encryption> on how to achieve this.
705+
706+
For more context, here is the implementing pull request: https://github.com/NixOS/nixpkgs/pull/198470
707+
'')
652708
++ (optional isUnsupportedMariadb ''
653709
You seem to be using MariaDB at an unsupported version (i.e. at least 10.6)!
654710
Please note that this isn't supported officially by Nextcloud. You can either

nixos/modules/services/web-apps/nextcloud.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@
170170
</listitem>
171171
</itemizedlist>
172172
</listitem>
173+
<listitem>
174+
<formalpara>
175+
<title>Server-side encryption</title>
176+
<para>
177+
Nextcloud supports <link xlink:href="https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/encryption_configuration.html">server-side encryption (SSE)</link>.
178+
This is not an end-to-end encryption, but can be used to encrypt files that will be persisted
179+
to external storage such as S3. Please note that this won't work anymore when using OpenSSL 3
180+
for PHP's openssl extension because this is implemented using the legacy cipher RC4.
181+
If <xref linkend="opt-system.stateVersion" /> is <emphasis>above</emphasis> <literal>22.05</literal>,
182+
this is disabled by default. To turn it on again and for further information please refer to
183+
<xref linkend="opt-services.nextcloud.enableBrokenCiphersForSSE" />.
184+
</para>
185+
</formalpara>
186+
</listitem>
173187
</itemizedlist>
174188
</section>
175189

nixos/tests/nextcloud/basic.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ in {
3737
"d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
3838
];
3939

40+
system.stateVersion = "22.11"; # stateVersion >=21.11 to make sure that we use OpenSSL3
41+
4042
services.nextcloud = {
4143
enable = true;
4244
datadir = "/var/lib/nextcloud-data";
@@ -99,6 +101,10 @@ in {
99101
# This is just to ensure the nextcloud-occ program is working
100102
nextcloud.succeed("nextcloud-occ status")
101103
nextcloud.succeed("curl -sSf http://nextcloud/login")
104+
# Ensure that no OpenSSL 1.1 is used.
105+
nextcloud.succeed(
106+
"${nodes.nextcloud.services.phpfpm.pools.nextcloud.phpPackage}/bin/php -i | grep 'OpenSSL Library Version' | awk -F'=>' '{ print $2 }' | awk '{ print $2 }' | grep -v 1.1"
107+
)
102108
nextcloud.succeed(
103109
"${withRcloneEnv} ${copySharedFile}"
104110
)
@@ -108,5 +114,6 @@ in {
108114
"${withRcloneEnv} ${diffSharedFile}"
109115
)
110116
assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")
117+
nextcloud.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud-data/data/root/files/test-shared-file")
111118
'';
112119
})) args

nixos/tests/nextcloud/default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ with pkgs.lib;
88
foldl
99
(matrix: ver: matrix // {
1010
"basic${toString ver}" = import ./basic.nix { inherit system pkgs; nextcloudVersion = ver; };
11+
"openssl-sse${toString ver}" = import ./openssl-sse.nix {
12+
inherit system pkgs;
13+
nextcloudVersion = ver;
14+
};
1115
"with-postgresql-and-redis${toString ver}" = import ./with-postgresql-and-redis.nix {
1216
inherit system pkgs;
1317
nextcloudVersion = ver;
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
args@{ pkgs, nextcloudVersion ? 25, ... }:
2+
3+
(import ../make-test-python.nix ({ pkgs, ...}: let
4+
adminuser = "root";
5+
adminpass = "notproduction";
6+
nextcloudBase = {
7+
networking.firewall.allowedTCPPorts = [ 80 ];
8+
system.stateVersion = "22.05"; # stateVersions <22.11 use openssl 1.1 by default
9+
services.nextcloud = {
10+
enable = true;
11+
config.adminpassFile = "${pkgs.writeText "adminpass" adminpass}";
12+
package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
13+
};
14+
};
15+
in {
16+
name = "nextcloud-openssl";
17+
meta = with pkgs.lib.maintainers; {
18+
maintainers = [ ma27 ];
19+
};
20+
nodes.nextcloudwithopenssl1 = {
21+
imports = [ nextcloudBase ];
22+
services.nextcloud.hostName = "nextcloudwithopenssl1";
23+
};
24+
nodes.nextcloudwithopenssl3 = {
25+
imports = [ nextcloudBase ];
26+
services.nextcloud = {
27+
hostName = "nextcloudwithopenssl3";
28+
enableBrokenCiphersForSSE = false;
29+
};
30+
};
31+
testScript = { nodes, ... }: let
32+
withRcloneEnv = host: pkgs.writeScript "with-rclone-env" ''
33+
#!${pkgs.runtimeShell}
34+
export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
35+
export RCLONE_CONFIG_NEXTCLOUD_URL="http://${host}/remote.php/webdav/"
36+
export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
37+
export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
38+
export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
39+
"''${@}"
40+
'';
41+
withRcloneEnv1 = withRcloneEnv "nextcloudwithopenssl1";
42+
withRcloneEnv3 = withRcloneEnv "nextcloudwithopenssl3";
43+
copySharedFile1 = pkgs.writeScript "copy-shared-file" ''
44+
#!${pkgs.runtimeShell}
45+
echo 'hi' | ${withRcloneEnv1} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
46+
'';
47+
copySharedFile3 = pkgs.writeScript "copy-shared-file" ''
48+
#!${pkgs.runtimeShell}
49+
echo 'bye' | ${withRcloneEnv3} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file2
50+
'';
51+
openssl1-node = nodes.nextcloudwithopenssl1.config.system.build.toplevel;
52+
openssl3-node = nodes.nextcloudwithopenssl3.config.system.build.toplevel;
53+
in ''
54+
nextcloudwithopenssl1.start()
55+
nextcloudwithopenssl1.wait_for_unit("multi-user.target")
56+
nextcloudwithopenssl1.succeed("nextcloud-occ status")
57+
nextcloudwithopenssl1.succeed("curl -sSf http://nextcloudwithopenssl1/login")
58+
59+
with subtest("With OpenSSL 1 SSE can be enabled and used"):
60+
nextcloudwithopenssl1.succeed("nextcloud-occ app:enable encryption")
61+
nextcloudwithopenssl1.succeed("nextcloud-occ encryption:enable")
62+
63+
with subtest("Upload file and ensure it's encrypted"):
64+
nextcloudwithopenssl1.succeed("${copySharedFile1}")
65+
nextcloudwithopenssl1.succeed("grep -E '^HBEGIN:oc_encryption_module' /var/lib/nextcloud/data/root/files/test-shared-file")
66+
nextcloudwithopenssl1.succeed("${withRcloneEnv1} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file | grep hi")
67+
68+
with subtest("Switch to OpenSSL 3"):
69+
nextcloudwithopenssl1.succeed("${openssl3-node}/bin/switch-to-configuration test")
70+
nextcloudwithopenssl1.wait_for_open_port(80)
71+
nextcloudwithopenssl1.succeed("nextcloud-occ status")
72+
73+
with subtest("Existing encrypted files cannot be read, but new files can be added"):
74+
nextcloudwithopenssl1.fail("${withRcloneEnv3} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file >&2")
75+
nextcloudwithopenssl1.succeed("nextcloud-occ encryption:disable")
76+
nextcloudwithopenssl1.succeed("${copySharedFile3}")
77+
nextcloudwithopenssl1.succeed("grep bye /var/lib/nextcloud/data/root/files/test-shared-file2")
78+
nextcloudwithopenssl1.succeed("${withRcloneEnv3} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file2 | grep bye")
79+
80+
with subtest("Switch back to OpenSSL 1.1 and ensure that encrypted files are readable again"):
81+
nextcloudwithopenssl1.succeed("${openssl1-node}/bin/switch-to-configuration test")
82+
nextcloudwithopenssl1.wait_for_open_port(80)
83+
nextcloudwithopenssl1.succeed("nextcloud-occ status")
84+
nextcloudwithopenssl1.succeed("nextcloud-occ encryption:enable")
85+
nextcloudwithopenssl1.succeed("${withRcloneEnv1} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file2 | grep bye")
86+
nextcloudwithopenssl1.succeed("${withRcloneEnv1} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file | grep hi")
87+
nextcloudwithopenssl1.succeed("grep -E '^HBEGIN:oc_encryption_module' /var/lib/nextcloud/data/root/files/test-shared-file")
88+
nextcloudwithopenssl1.succeed("grep bye /var/lib/nextcloud/data/root/files/test-shared-file2")
89+
90+
with subtest("Ensure that everything can be decrypted"):
91+
nextcloudwithopenssl1.succeed("echo y | nextcloud-occ encryption:decrypt-all >&2")
92+
nextcloudwithopenssl1.succeed("${withRcloneEnv1} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file2 | grep bye")
93+
nextcloudwithopenssl1.succeed("${withRcloneEnv1} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file | grep hi")
94+
nextcloudwithopenssl1.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud/data/root/files/test-shared-file")
95+
96+
with subtest("Switch to OpenSSL 3 ensure that all files are usable now"):
97+
nextcloudwithopenssl1.succeed("${openssl3-node}/bin/switch-to-configuration test")
98+
nextcloudwithopenssl1.wait_for_open_port(80)
99+
nextcloudwithopenssl1.succeed("nextcloud-occ status")
100+
nextcloudwithopenssl1.succeed("${withRcloneEnv3} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file2 | grep bye")
101+
nextcloudwithopenssl1.succeed("${withRcloneEnv3} ${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file | grep hi")
102+
103+
nextcloudwithopenssl1.shutdown()
104+
'';
105+
})) args

pkgs/development/interpreters/php/generic.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ let
9191
[ ]
9292
allExtensionFunctions;
9393

94-
getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name;
94+
getExtName = ext: ext.extensionName;
9595

9696
# Recursively get a list of all internal dependencies
9797
# for a list of extensions.

pkgs/top-level/php-packages.nix

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ lib.makeScope pkgs.newScope (self: with self; {
7373
# will mark the extension as a zend extension or not.
7474
mkExtension = lib.makeOverridable
7575
({ name
76-
, configureFlags ? [ "--enable-${name}" ]
76+
, configureFlags ? [ "--enable-${extName}" ]
7777
, internalDeps ? [ ]
7878
, postPhpize ? ""
7979
, buildInputs ? [ ]
8080
, zendExtension ? false
8181
, doCheck ? true
82+
, extName ? name
8283
, ...
8384
}@args: stdenv.mkDerivation ((builtins.removeAttrs args [ "name" ]) // {
8485
pname = "php-${name}";
85-
extensionName = name;
86+
extensionName = extName;
8687

8788
outputs = [ "out" "dev" ];
8889

@@ -105,7 +106,7 @@ lib.makeScope pkgs.newScope (self: with self; {
105106

106107
cdToExtensionRootPhase = ''
107108
# Go to extension source root.
108-
cd "ext/${name}"
109+
cd "ext/${extName}"
109110
'';
110111

111112
preConfigure = ''
@@ -141,7 +142,7 @@ lib.makeScope pkgs.newScope (self: with self; {
141142
runHook preInstall
142143
143144
mkdir -p $out/lib/php/extensions
144-
cp modules/${name}.so $out/lib/php/extensions/${name}.so
145+
cp modules/${extName}.so $out/lib/php/extensions/${extName}.so
145146
mkdir -p $dev/include
146147
${rsync}/bin/rsync -r --filter="+ */" \
147148
--filter="+ *.h" \
@@ -416,6 +417,16 @@ lib.makeScope pkgs.newScope (self: with self; {
416417
configureFlags = [ "--with-openssl" ];
417418
doCheck = false;
418419
}
420+
# This provides a legacy OpenSSL PHP extension
421+
# For situations where OpenSSL 3 do not support a set of features
422+
# without a specific openssl.cnf file
423+
{
424+
name = "openssl-legacy";
425+
extName = "openssl";
426+
buildInputs = [ openssl_1_1 ];
427+
configureFlags = [ "--with-openssl" ];
428+
doCheck = false;
429+
}
419430
{ name = "pcntl"; }
420431
{ name = "pdo"; doCheck = false; }
421432
{

0 commit comments

Comments
 (0)