From 6e652f8a589e6e9186ada0891758e3a84e954577 Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Thu, 19 Nov 2015 11:27:57 -0500 Subject: [PATCH] Validate size of split ciphertext array. --- src/EasyRSA.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/EasyRSA.php b/src/EasyRSA.php index a06bebb..56e8b5a 100644 --- a/src/EasyRSA.php +++ b/src/EasyRSA.php @@ -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'); } @@ -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); }