diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php index b3b53f11997b..a05286f1220e 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php @@ -60,9 +60,11 @@ public function __construct(IL10N $l, IConfig $config) { public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = null) { $auth = new RSACrypt(); $auth->setPassword($this->config->getSystemValue('secret', '')); - if (!$auth->loadKey($storage->getBackendOption('private_key'))) { + $privateKey = $storage->getBackendOption('private_key'); + if (!$auth->loadKey($privateKey)) { throw new \RuntimeException('unable to load private key'); } + $storage->setBackendOption('private_key', base64_encode($privateKey)); $storage->setBackendOption('public_key_auth', $auth); } diff --git a/lib/private/Files/External/FrontendDefinitionTrait.php b/lib/private/Files/External/FrontendDefinitionTrait.php index d4883e57e31a..cafe9b6363e6 100644 --- a/lib/private/Files/External/FrontendDefinitionTrait.php +++ b/lib/private/Files/External/FrontendDefinitionTrait.php @@ -150,7 +150,11 @@ public function validateStorageDefinition(IStorageConfig $storage) { if (!$parameter->validateValue($value)) { return false; } - $storage->setBackendOption($name, $value); + if (($name === 'public_key') || ($name === 'private_key')) { + $storage->setBackendOption($name, base64_encode($value)); + } else { + $storage->setBackendOption($name, $value); + } } } return true; diff --git a/lib/private/Files/External/StorageConfig.php b/lib/private/Files/External/StorageConfig.php index 74f991db70a6..14ac369af34b 100644 --- a/lib/private/Files/External/StorageConfig.php +++ b/lib/private/Files/External/StorageConfig.php @@ -222,6 +222,12 @@ public function setBackendOptions($backendOptions) { $backendOptions[$key] = $value; } if(is_string($backendOptions[$key])) { + if (($key === 'public_key') || ($key === 'private_key')) { + if (base64_decode($backendOptions[$key], true) === false) { + $backendOptions[$key] = base64_encode($backendOptions[$key]); + } + } + $backendOptions[$key] = str_replace(["\n", "\r"], "", $backendOptions[$key]); } } @@ -236,6 +242,13 @@ public function setBackendOptions($backendOptions) { */ public function getBackendOption($key) { if (isset($this->backendOptions[$key])) { + if (($key === 'private_key') || ($key === 'public_key')) { + $decodedString = base64_decode($this->backendOptions[$key], true); + if ($decodedString !== false) { + return $decodedString; + } + } + return $this->backendOptions[$key]; } return null;