Repository navigation
Merge release 4.2.9 into 4.3.x - #833
Merged
Merged
Conversation
…r value
RsaAnalyzer counted the modulus as 8 × octets and read the exponent with
unpack('l'), so leading zero octets (RFC 7518 §2 forbids them, Base64urlUInt)
let a key with n = 15 and e = 1 pass with no message. Both values are now read
as big-endian integers with BigInteger.
ESKeyAnalyzer checked the point with Curve::contains(), which reduces modulo p,
so a coordinate >= p passed while OpenSSL refuses the key. Coordinates are now
required to be lower than the field prime.
RsaAnalyzer converted "n" and "e" into big integers. The analyzed keys may come from a third party and nothing bounds their length: without GMP, a modulus of 2048 octets cost 0.57 s with BCMath and 109 s in pure PHP, and 32 KiB cost 155 s with BCMath. The bit length of the modulus is now read from its octets, leading zero octets ignored, as RSAKey does. The exponent is converted only when it fits in three octets: a longer value is at least 2^24. The verdicts are those of the previous commit. The new tests cover the bounds: 2047 and 2048-bit moduli, exponents with leading zero octets or longer than four octets.
ESKeyAnalyzer reported coordinates of the wrong size, then converted them into big integers anyway. Without GMP, coordinates of 1 KiB cost 27.5 s in pure PHP and 8 KiB cost 2 s with BCMath. The analysis now stops after the size message, as it does for empty coordinates, and the curve is created once.
…ding fix(key-mgmt): analyze RSA n and e and EC coordinates by their integer value
RSAKey bounded the public exponent "e" to 64 bits above a modulus of 3072 bits only, as OpenSSL does, and to the length of the modulus below it. A key of 3072 bits whose exponent was as long as its modulus was therefore accepted, and the public operation PS*, RSA-OAEP and RSA1_5 compute in PHP costs as many squarings as "e" has bits: with GMP, a PS256 signature under such a key, which the sender of a DPoP proof chooses, took 30.9 ms to reject, against 0.7 ms with a 64-bit exponent; with BCMath, 1.48 s against 52 ms. The exponent is now refused beyond 64 bits whatever the modulus, and beyond the length of the modulus as before. The dearest key left is one of 16384 bits with a 64-bit exponent: 8.6 ms with GMP, 1.18 s with BCMath, as before this change. A key with a larger exponent is refused although FIPS 186-5 allows exponents below 2^256: generators draw 65537, and Go and BoringSSL already refuse exponents above 2^31 - 1 and 33 bits.
…ports on 4.2.x The phpqa image rebuilt on 2026-11-20 ships PHPStan 2.3.7, which reports a mixed value as the condition of the ternaries of the processHeaders() methods of JSONFlattenedSerializer and JSONGeneralSerializer and of the if of MixedPublicAndPrivateKeys: the Static Analysis job failed on 4.2.x whatever the change. The baseline, generated by castor phpstan-baseline, gains those three entries and nothing else.
fix(core): bound the RSA public exponent to 64 bits whatever the modulus
PS256, PS384 and PS512 verification and RSA-OAEP, RSA-OAEP-256 and RSA1_5 encryption raised the signature or the encoded message to the public exponent with brick/math. Without GMP, that costs seconds even with ordinary keys, whoever provides them: in pure PHP, a PS256 verification took 3 s with an RSA-2048 key and 15 s with an RSA-4096 key, and with BCMath a 3072-bit key whose exponent is as long as the modulus took 0.9 s. RSAKey::applyPublicKey() now computes input^e mod n with OpenSSL (OPENSSL_NO_PADDING) when the extension is loaded, and with brick/math otherwise. OpenSSL applies its own limits to the key, and the cost no longer depends on the calculator: about 0.2 ms per operation with an RSA-2048 key, with GMP, with BCMath or with neither. The public key is handed to OpenSSL as a PEM, which is now written without pki-framework, whose DER lengths go through brick/math: toPEM() for a public key drops from 0.23 ms to 0.03 ms, which RS256, RS384 and RS512 benefit from as well, and the PEM is the same byte for byte. With GMP, a PS256 verification with an RSA-2048 key takes 0.19 ms, against 0.11 ms before. Private key operations are unchanged. An input as large as the modulus, or a key that OpenSSL refuses (a public exponent as long as the modulus but larger), now raises a RuntimeException. Reported by Anthropic's OSS Scanner (ANT-2026-9EHC9J38 and ANT-2026-WD2XF3WZ). (cherry picked from commit 9323191)
RSA-OAEP, RSA-OAEP-256 and RSA1_5 decryption raised the encrypted key to the private exponent with brick/math. The sender of a token chooses that encrypted key, and the key it is encrypted to is public, so anyone could make an application pay for a private key operation with each token: with an RSA-2048 key, about 130 s in pure PHP and 0.12 s with BCMath, against 3 ms with GMP. RSAKey::applyPrivateKey() now computes input^d mod n with OpenSSL (OPENSSL_NO_PADDING) when the extension is loaded, and with brick/math otherwise. The key is handed to OpenSSL by its members through openssl_pkey_new(), so a key without its CRT members works as before, and OpenSSL blinds the operation. A forged token now costs about 2 ms with any calculator. The padding checks stay in PHP and are unchanged. An input as large as the modulus still raises a RuntimeException, now with a message.
PS256, PS384 and PS512 signing applied the private key with brick/math: with an RSA-2048 key, about 125 s per signature in pure PHP and 0.15 s with BCMath. It now goes through RSAKey::applyPrivateKey(), like RSA-OAEP and RSA1_5 decryption, and costs a few milliseconds with any calculator. The signatures are the same: only the RSA primitive moves to OpenSSL.
* commit 'd5787015': Sign with RSA-PSS through OpenSSL Compute the RSA private operation with OpenSSL Compute the RSA public operation with OpenSSL
…n 8.2 reports on 4.2.x symfony/dependency-injection 8.2.0 declares the $config argument of ContainerBuilder::prependExtensionConfig() as array<string, mixed>, while ConfigurationHelper::updateJoseConfiguration() passes an array<mixed>. The Static Analysis job therefore fails on 4.2.x whatever the change, and the tests it gates are skipped. 4.3.x got the same entry in #832. The baseline, generated by castor phpstan-baseline with the current image, gains that entry and nothing else.
Brings 4.2.8 (#825, #828) and 4.2.9 into 4.3.x. Conflicts resolved: - RSAKey: the 4.2.x code (exponent bounded to 64 bits whatever the modulus, applyPrivateKey() and its OpenSSL members) with the Jose InvalidKeyException and RuntimeException of 4.3.x; - RSACrypt and Signature\Algorithm\Util\RSA: the 4.3.x imports without BigInteger, and the private helpers removed as on 4.2.x; - RsaAnalyzer: the 4.2.x version, which no longer needs InvalidKeyException; - RSAKeyTest: the 4.3.x imports plus array_flip and array_intersect_key, and the new tests; - JWKAnalyzerTest: (new JWKFactory())->ec() instead of the deprecated JWKFactory::createECKey().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release Notes for 4.2.9
4.2.x bugfix release (patch)
4.2.9