Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion apps/files_external/lib/Lib/Auth/PublicKey/RSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion lib/private/Files/External/FrontendDefinitionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions lib/private/Files/External/StorageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand All @@ -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;
Expand Down