Skip to content

Commit 3b9402e

Browse files
committed
Fix RSA-1.5 decrypt-failure fixture for OpenSSL < 3.2.
str_repeat('B', 256) accidentally validates as PKCS#1 with the test key when phpseclib delegates to OpenSSL, so use ciphertext >= modulus instead.
1 parent 5d35b2a commit 3b9402e

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

tests/decrypt-failure-uniform.phpt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ $oaep->loadKey(dirname(__FILE__) . '/privkey.pem', true);
5757
expectDecryptFailure('RSA_OAEP_BAD', $oaep, str_repeat('A', 256));
5858
expectDecryptFailure('RSA_OAEP_SHORT', $oaep, 'short');
5959

60-
/* RSA-1.5 unwrap: wrong ciphertext (RuntimeException). */
60+
/*
61+
* RSA-1.5 unwrap: ciphertext integer >= modulus (rejected by OpenSSL and by
62+
* phpseclib's pure-PHP PKCS#1 path). Do not use arbitrary fixed bytes of key
63+
* length: some of those (e.g. str_repeat('B', 256) with tests/privkey.pem)
64+
* accidentally satisfy PKCS#1 v1.5 type-2 padding after RSA decryption, so
65+
* openssl_private_decrypt succeeds on OpenSSL < 3.2 (where phpseclib still
66+
* delegates PKCS#1 decrypt to OpenSSL).
67+
*/
6168
$rsa15 = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type' => 'private'));
6269
$rsa15->loadKey(dirname(__FILE__) . '/privkey.pem', true);
63-
expectDecryptFailure('RSA15_BAD', $rsa15, str_repeat('B', 256));
70+
expectDecryptFailure('RSA15_BAD', $rsa15, str_repeat("\xff", 256));
6471

6572
/* Successful round-trip still works (control). */
6673
$ok = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);

0 commit comments

Comments
 (0)