Skip to content

Commit

Permalink
Merge pull request #12678 from nextcloud/encryption-emergency-recovery
Browse files Browse the repository at this point in the history
Allow to disable the signature check
  • Loading branch information
schiessle authored Dec 18, 2018
2 parents 6f994be + 34d4c2b commit a374d88
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/encryption/lib/Crypto/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,15 @@ public function symmetricDecryptFileContent($keyFileContents, $passPhrase, $ciph
* @throws GenericEncryptionException
*/
private function checkSignature($data, $passPhrase, $expectedSignature) {
$enforceSignature = !$this->config->getSystemValue('encryption_skip_signature_check', false);

$signature = $this->createSignature($data, $passPhrase);
if (!hash_equals($expectedSignature, $signature)) {
$isCorrectHash = hash_equals($expectedSignature, $signature);

if (!$isCorrectHash && $enforceSignature) {
throw new GenericEncryptionException('Bad Signature', $this->l->t('Bad Signature'));
} else if (!$isCorrectHash && !$enforceSignature) {
$this->logger->info("Signature check skipped", ['app' => 'encryption']);
}
}

Expand Down Expand Up @@ -557,11 +563,13 @@ private function splitMetaData($catFile, $cipher) {
* @throws GenericEncryptionException
*/
private function hasSignature($catFile, $cipher) {
$skipSignatureCheck = $this->config->getSystemValue('encryption_skip_signature_check', false);

$meta = substr($catFile, -93);
$signaturePosition = strpos($meta, '00sig00');

// enforce signature for the new 'CTR' ciphers
if ($signaturePosition === false && stripos($cipher, 'ctr') !== false) {
if (!$skipSignatureCheck && $signaturePosition === false && stripos($cipher, 'ctr') !== false) {
throw new GenericEncryptionException('Missing Signature', $this->l->t('Missing Signature'));
}

Expand Down

0 comments on commit a374d88

Please sign in to comment.