Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] Handle errors in encryption:migrate-key-storage-format #44556

Draft
wants to merge 1 commit into
base: stable27
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions core/Command/Encryption/MigrateKeyStorage.php
Expand Up @@ -82,7 +82,7 @@
protected function updateKeys(string $root, OutputInterface $output): bool {
$output->writeln("Start to update the keys:");

$this->updateSystemKeys($root);
$this->updateSystemKeys($root, $output);
$this->updateUsersKeys($root, $output);
$this->config->deleteSystemValue('encryption.key_storage_migrated');
return true;
Expand All @@ -91,15 +91,15 @@
/**
* Move system key folder
*/
protected function updateSystemKeys(string $root): void {
protected function updateSystemKeys(string $root, OutputInterface $output): void {
if (!$this->rootView->is_dir($root . '/files_encryption')) {
return;
}

$this->traverseKeys($root . '/files_encryption', null);
$this->traverseKeys($root . '/files_encryption', null, $output);
}

private function traverseKeys(string $folder, ?string $uid) {
private function traverseKeys(string $folder, ?string $uid, OutputInterface $output) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OC\Core\Command\Encryption\MigrateKeyStorage::traverseKeys does not have a return type, expecting void
$listing = $this->rootView->getDirectoryContent($folder);

foreach ($listing as $node) {
Expand All @@ -115,6 +115,11 @@

$content = $this->rootView->file_get_contents($path);

if ($content === false) {
$output->writeln("<error>Failed to open path $path</error>");
continue;
}

try {
$this->crypto->decrypt($content);
continue;
Expand All @@ -133,12 +138,12 @@
}
}

private function traverseFileKeys(string $folder) {
private function traverseFileKeys(string $folder, OutputInterface $output) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OC\Core\Command\Encryption\MigrateKeyStorage::traverseFileKeys does not have a return type, expecting void
$listing = $this->rootView->getDirectoryContent($folder);

foreach ($listing as $node) {
if ($node['mimetype'] === 'httpd/unix-directory') {
$this->traverseFileKeys($folder . '/' . $node['name']);
$this->traverseFileKeys($folder . '/' . $node['name'], $output);
} else {
$endsWith = function ($haystack, $needle) {
$length = strlen($needle);
Expand All @@ -157,6 +162,11 @@

$content = $this->rootView->file_get_contents($path);

if ($content === false) {
$output->writeln("<error>Failed to open path $path</error>");
continue;
}

try {
$this->crypto->decrypt($content);
continue;
Expand Down Expand Up @@ -205,7 +215,7 @@
foreach ($users as $user) {
$progress->advance();
$this->setupUserFS($user);
$this->updateUserKeys($root, $user);
$this->updateUserKeys($root, $user, $output);
}
$offset += $limit;
} while (count($users) >= $limit);
Expand All @@ -220,16 +230,16 @@
* @param string $user
* @throws \Exception
*/
protected function updateUserKeys(string $root, string $user) {
protected function updateUserKeys(string $root, string $user, OutputInterface $output) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OC\Core\Command\Encryption\MigrateKeyStorage::updateUserKeys does not have a return type, expecting void
if ($this->userManager->userExists($user)) {
$source = $root . '/' . $user . '/files_encryption/OC_DEFAULT_MODULE';
if ($this->rootView->is_dir($source)) {
$this->traverseKeys($source, $user);
$this->traverseKeys($source, $user, $output);
}

$source = $root . '/' . $user . '/files_encryption/keys';
if ($this->rootView->is_dir($source)) {
$this->traverseFileKeys($source);
$this->traverseFileKeys($source, $output);
}
}
}
Expand Down