Skip to content

Commit

Permalink
Converts the CryptoExceptions into session messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
VangelisP committed Jun 5, 2023
1 parent 03ab15f commit 5de66c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Civi/Crypto/CryptoRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,13 @@ public function findKey($keyIds) {
return $this->keys[$matchKeyId];
}
}

throw new CryptoException("Failed to find key by ID or tag (" . implode(' ', $keyIds) . ")");
\CRM_Core_Session::setStatus(ts('Failed to find key by ID or tag (%1)', [
1 => implode(' ', $keyIds),
]),
'',
'alert',
['expires' => 0]
);
}

/**
Expand Down Expand Up @@ -294,7 +299,13 @@ public function findSuite($name) {
return $this->cipherSuites[$name];
}
else {
throw new CryptoException('Unknown cipher suite ' . $name);
\CRM_Core_Session::setStatus(ts('Unknown cipher suite', [
1 => $name,
]),
'',
'alert',
['expires' => 0]
);
}
}

Expand Down
4 changes: 4 additions & 0 deletions Civi/Crypto/CryptoToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public function decrypt($token, $keyIdOrTag = '*') {
throw new CryptoException("Cannot decrypt token. Unexpected key: {$tokenData['k']}");
}

if (is_null($key) || !isset($key)) {
return $plainText;
}

/** @var \Civi\Crypto\CipherSuiteInterface $cipherSuite */
$cipherSuite = $registry->findSuite($key['suite']);
$plainText = $cipherSuite->decrypt($tokenData['t'], $key);
Expand Down

0 comments on commit 5de66c1

Please sign in to comment.