From 40f01de4561fff4c2d913643e671644c07c298b8 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 5 Dec 2022 11:28:52 +0100 Subject: Fix migration to non-empty secret Add a fallback for empty keys Signed-off-by: Carl Schwan (cherry picked from commit 754cb58b1259a58f626d47c2193b92c651d3b2d8) --- apps/files_external/lib/Lib/Auth/PublicKey/RSA.php | 5 ++++- apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php index 2d17b4e9698..199fdfcc6d6 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php @@ -60,7 +60,10 @@ class RSA extends AuthMechanism { $auth = new RSACrypt(); $auth->setPassword($this->config->getSystemValue('secret', '')); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { - throw new \RuntimeException('unable to load private key'); + $auth->setPassword(''); + if (!$auth->loadKey($storage->getBackendOption('private_key'))) { + throw new \RuntimeException('unable to load private key'); + } } $storage->setBackendOption('public_key_auth', $auth); } diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php index 886d16965f4..26cf0501eb6 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php @@ -58,7 +58,10 @@ class RSAPrivateKey extends AuthMechanism { $auth = new RSACrypt(); $auth->setPassword($this->config->getSystemValue('secret', '')); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { - throw new \RuntimeException('unable to load private key'); + $auth->setPassword(''); + if (!$auth->loadKey($storage->getBackendOption('private_key'))) { + throw new \RuntimeException('unable to load private key'); + } } $storage->setBackendOption('public_key_auth', $auth); } -- cgit v1.2.3 From 1c558d2f1541776bf30a8d79fe42389bd0c8c964 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 5 Dec 2022 15:26:36 +0100 Subject: Add comments Signed-off-by: Carl Schwan (cherry picked from commit 5e31ed4f526e943e695d994a6434ed71d1a45c1c) --- apps/files_external/lib/Lib/Auth/PublicKey/RSA.php | 1 + apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php | 1 + 2 files changed, 2 insertions(+) diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php index 199fdfcc6d6..d45db03b2da 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php @@ -60,6 +60,7 @@ class RSA extends AuthMechanism { $auth = new RSACrypt(); $auth->setPassword($this->config->getSystemValue('secret', '')); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { + // Add fallback routine for a time where secret was not enforced to be exists $auth->setPassword(''); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { throw new \RuntimeException('unable to load private key'); diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php index 26cf0501eb6..7d04aaaf057 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSAPrivateKey.php @@ -58,6 +58,7 @@ class RSAPrivateKey extends AuthMechanism { $auth = new RSACrypt(); $auth->setPassword($this->config->getSystemValue('secret', '')); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { + // Add fallback routine for a time where secret was not enforced to be exists $auth->setPassword(''); if (!$auth->loadKey($storage->getBackendOption('private_key'))) { throw new \RuntimeException('unable to load private key'); -- cgit v1.2.3