Skip to content

Commit

Permalink
Validate size of split ciphertext array.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Nov 19, 2015
1 parent fde3f98 commit 6e652f8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/EasyRSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public static function encrypt($plaintext, $rsaPublicKey)
public static function decrypt($ciphertext, $rsaPrivateKey)
{
$split = explode(self::SEPARATOR, $ciphertext);
if (\count($split) !== 4) {
throw new \Exception('Invalid ciphertext message');
}
if (!\hash_equals($split[0], self::VERSION_TAG)) {
throw new \Exception('Invalid version tag');
}
Expand Down Expand Up @@ -169,6 +172,7 @@ protected static function rsaDecrypt($ciphertext, $rsaPrivateKey)
$rsa = new RSA();
$rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
$rsa->setMGFHash('sha256');

$rsa->loadKey($rsaPrivateKey);
return $rsa->decrypt($ciphertext);
}
Expand Down

0 comments on commit 6e652f8

Please sign in to comment.