Skip to content

Commit

Permalink
fixup! New SSE key format
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Aug 12, 2020
1 parent 91c72ea commit aa38724
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions core/Command/Encryption/MigrateKeyStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function traverseKeys(string $folder, ?string $uid) {
}

$data = [
'key' => $content,
'key' => base64_encode($content),
'uid' => $uid,
];

Expand Down Expand Up @@ -190,9 +190,11 @@ private function traverseFileKeys(string $folder) {
}

$data = [
'key' => base64_encode($this->crypto->encrypt($content))
'key' => base64_encode($content)
];

$enc = base64_encode($this->crypto->encrypt(json_encode($data)));

$this->rootView->file_put_contents($path, json_encode($data));
}
}
Expand Down
14 changes: 9 additions & 5 deletions lib/private/Encryption/Keys/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(View $view, Util $util, ICrypto $crypto, IConfig $co
*/
public function getUserKey($uid, $keyId, $encryptionModuleId) {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return $this->getKeyWithUid($path, $uid);
return base64_decode($this->getKeyWithUid($path, $uid));
}

/**
Expand All @@ -119,7 +119,7 @@ public function getFileKey($path, $keyId, $encryptionModuleId) {
*/
public function getSystemUserKey($keyId, $encryptionModuleId) {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, null);
return $this->getKeyWithUid($path, null);
return base64_decode($this->getKeyWithUid($path, null));
}

/**
Expand All @@ -128,7 +128,7 @@ public function getSystemUserKey($keyId, $encryptionModuleId) {
public function setUserKey($uid, $keyId, $key, $encryptionModuleId) {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return $this->setKey($path, [
'key' => $key,
'key' => base64_encode($key),
'uid' => $uid,
]);
}
Expand All @@ -149,7 +149,7 @@ public function setFileKey($path, $keyId, $key, $encryptionModuleId) {
public function setSystemUserKey($keyId, $key, $encryptionModuleId) {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, null);
return $this->setKey($path, [
'key' => $key,
'key' => base64_encode($key),
'uid' => null,
]);
}
Expand Down Expand Up @@ -233,7 +233,11 @@ private function getKeyWithUid(string $path, ?string $uid): string {
throw new ServerNotAvailableException('Key is invalid');
}

if (!isset($data['uid']) || $data['uid'] !== $uid) {
if ($data['key'] === '') {
return '';
}

if (!array_key_exists('uid', $data) || $data['uid'] !== $uid) {
// If the migration is done we error out
if ($this->config->getSystemValueBool('encryption.key_storage_migrated', true)) {
throw new ServerNotAvailableException('Key has been modified');
Expand Down

0 comments on commit aa38724

Please sign in to comment.