Skip to content
Open
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
9 changes: 8 additions & 1 deletion apps/encryption/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\UseSession;
use OCP\AppFramework\Http\DataResponse;
use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ISession;
Expand Down Expand Up @@ -76,7 +77,13 @@ public function updatePrivateKeyPassword($oldPassword, $newPassword) {

if ($passwordCorrect !== false) {
$encryptedKey = $this->keyManager->getPrivateKey($uid);
$decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword, $uid);
try {
$decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword, $uid);
} catch (GenericEncryptionException) {
// A wrong passphrase does not only make decrypting return false, it can
// also fail the signature check or the decryption itself
$decryptedKey = false;
}

if ($decryptedKey) {
$encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid);
Expand Down
23 changes: 23 additions & 0 deletions apps/encryption/tests/Controller/SettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace OCA\Encryption\Tests\Controller;

use OC\Encryption\Exceptions\DecryptionFailedException;
use OCA\Encryption\Controller\SettingsController;
use OCA\Encryption\Crypto\Crypt;
use OCA\Encryption\KeyManager;
Expand Down Expand Up @@ -147,6 +148,28 @@ public function testUpdatePrivateKeyPasswordWrongOldPassword(): void {
$data['message']);
}

/**
* test updatePrivateKeyPassword() if decrypting the private key with the given
* old password fails with an exception instead of returning false
*/
public function testUpdatePrivateKeyPasswordUndecryptableKey(): void {
$this->userManagerMock
->expects($this->once())
->method('checkPassword')
->willReturn(true);

$this->cryptMock
->expects($this->once())
->method('decryptPrivateKey')
->willThrowException(new DecryptionFailedException('Decryption failed'));

$result = $this->controller->updatePrivateKeyPassword('old', 'new');

$this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
$this->assertSame('The old password was not correct, please try again.',
$result->getData()['message']);
}

/**
* test updatePrivateKeyPassword() with the correct old and new password
*/
Expand Down
Loading