Repository navigation
Conversation
Cherry-pick of #797 (4.3.x), so that the next commit turns its deprecations into refusals. In 5.0.x, checkCekSize() already refuses a longer "dir" key, and deprecateLongerDirectKey() no longer exists: the deprecation of a "dir" key without "decrypt" is reported on its own after the try block. 5.0.x cannot decrypt a static key agreement yet: the fix of #770 (#775, 4.2.7) comes with the merge-up of 4.3.x. The static key agreement test therefore only builds the token, with the key of the recipient and the key of the sender. Refs #761 (cherry picked from commit 4f9f233)
…key_ops" Since 4.3.0, a "dir" key whose "key_ops" parameter lacks "encrypt" (to build) or "decrypt" (to decrypt), but contains another operation that was accepted so far, triggers a deprecation. Such a key is now refused: KeyChecker::checkDirectEncryptionKeyUsage() runs the check common to every mode, then throws an InvalidKeyException when the content operation is missing. The decrypter checks the key before using it, so it skips a refused key and tries the next one of the key set, as for the other key checks. A key restricted to key wrapping, such as an A128GCMKW key with ["wrapKey", "unwrapKey"], can no longer decrypt the "dir" content of #760 and return the CEK of the A128GCMKW token. Keys without "key_ops", and those refused by the common check, behave as before, with the same messages. KeyChecker::allowsOperation() is only used by KeyChecker now and becomes private. Refs #761
5.0.x now holds #797 (c82460f) through the merge-up of 4.3.x, so this branch is rebuilt as its description plans, through a merge instead of a new history: the cherry-pick of #797 (8404b4e) gives way to the code of 5.0.x, and the refusal (c819887) is kept. - JWEDecrypter: the deprecation of a "dir" key without "decrypt" goes with the refusal; the deprecation of a "dir" JWE with an empty AAD, from #796, stays. - KeyOperationsTest: the refusal versions of the tests are kept, and the static key agreement test decrypts the token again, as 5.0.x can now decrypt it; the constant of the empty AAD deprecation is no longer used and goes.
Spomky
added a commit
that referenced
this pull request
Nov 29, 2026
5.0.x now holds #796 (1d88a1a) through the merge-up of 4.3.x, so 5.0.x is merged into this branch as its description plans. The cherry-pick of #796 (f4b6da5) gives way to the code of 5.0.x, and the refusal (54617b0) is kept: - JWEBuilder and JWEDecrypter keep checkDirectEncryptionAADIsNotEmpty(), and the call to deprecateDirectEncryptionWithEmptyAAD() goes; the deprecation of a "dir" key without "decrypt" (#797) stays, #806 turns it into a refusal; - DirectEncryptionAdditionalAuthenticatedDataTest is the version of this branch; - KeyOperationsTest::aKeyWrappingKeyThatDecryptsDirectContentIsReported (#797) forges the token of #760 and expected its CEK: the token is now refused, so the test, renamed aKeyWrappingKeyCannotDecryptDirectContent as in #806, expects a failed decryption without deprecation.
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.
Second part of #761, for 5.0.0. It follows #797 (4.3.x, merged as c82460f), which deprecated these keys in 4.3.0. Draft until 4.3.x is merged up into 5.0.x: this branch is then rebuilt on top of the merge-up.
Why the branch cherry-picks #797 instead of merging it
The other 5.0.x drafts (#783, #786, #790) merge the commit of their 4.3.x pull request, which starts from the last merge-up of 4.3.x into 5.0.x (7dfbe15). #797 starts from 6d4d2ce, 37 commits later. Merging its commit would bring those commits along (63 files) with five conflicts, which amounts to half a merge-up. The first commit is therefore a cherry-pick of #797 (4f9f233), adapted to 5.0.x:
deprecateLongerDirectKey()no longer exists in 5.0.x, wherecheckCekSize()refuses a longerdirkey. The deprecation of adirkey withoutdecryptis reported on its own after thetryblock.epkand fails with "The header parameter "epk" is missing.", whatever the keys. The static key agreement test therefore only builds the token, with the key of the recipient and the key of the sender.The second commit turns the deprecations into refusals. Once the merge-up is done, the rebuild drops the cherry-pick, keeps the second commit, and brings back the decryption half of the static key agreement test.
The change
With #797 (4.3.0), a
dirkey whosekey_opsparameter lacksencrypt(to build) ordecrypt(to decrypt) triggers a deprecation if it contains another operation accepted so far:wrapKeyorderiveKeyto build,unwrapKeyorderiveBitsto decrypt. In 5.0.0, such a key is refused with anInvalidKeyException:KeyChecker::checkDirectEncryptionKeyUsage()runs the check common to every mode, then requires the content operation. The builder and the decrypter call it fordir,checkKeyAgreementKeyUsage()for the key agreement algorithms (from fix(encryption): read "key_ops" according to the key management mode #797), andcheckKeyUsage()for the other modes.tryblock, before using it. A refused key is passed to theonErrorcallback and skipped, and the next key of the set is tried. A key restricted to key wrapping can no longer decrypt the forgeddirJWE of Hardening: refuse a JSON "dir" JWE without protected header and "aad", whose content can be an A*GCMKW encrypted key #760, which returns the CEK of an A128GCMKW token.key_opsbehave as before, and so do keys that the common check already refuses, with the same messages.KeyChecker::allowsOperation()is internal and becomes private, since onlyKeyCheckeruses it now.The net diff against 5.0.x adds no
trigger_deprecation()call, so the "Done when" grep of #717 is not affected.Behaviour changes, against 5.0.x
dir,key_opswithoutencryptbut withwrapKeyorderiveKeyInvalidKeyExceptiondir,key_opswithoutdecryptbut withunwrapKeyorderiveBitsInvalidKeyExceptionpassed toonErrorkey_opswithderiveBitsbut none ofencrypt,wrapKey,deriveKeyInvalidKeyExceptionkey_opswithderiveKeybut none ofdecrypt,unwrapKey,deriveBitsThe first two rows are the BC break. The last two come from #797.
Three messages change:
dirkey with a wrongalgand without the content operation now reports thekey_opserror instead of "Key is only allowed for algorithm …". The exception class is the same.deriveKeyorderiveBitsand is refused for itsalgnow reports "Key is only allowed for algorithm …".deriveKeynow passes the key check and then reaches theepkfailure described above. That goes away with the merge-up.Verification
KeyOperationsTesthas 30 cases, all green.diroperation sets, 5 withoutencryptand 5 withoutdecrypt;decrypt;deriveBitsto build andderiveKeyto decrypt.API. The public and protected API of
src/(443 types), dumped by reflection, is identical apart from two new static methods of the internalKeyChecker:checkKeyAgreementKeyUsage()andcheckDirectEncryptionKeyUsage().Probe 1, the one used for fix(encryption): read "key_ops" according to the key management mode #797: 8 key management algorithms × 12
key_opsvalues, built and decrypted, plus the sender key for ECDH-SS and ECDH-SS+A128KW, and the Hardening: refuse a JSON "dir" JWE without protected header and "aad", whose content can be an A*GCMKW encrypted key #760 token. Of the 217 outcomes, 19 differ:diroutcomes go from accepted to refused;epkbug instead of the key check;Probe 2: 25 unusual keys × 5 algorithms. The keys include
key_opsas a string, asnull, as a map, as nested arrays, with booleans, integers, other casing, duplicates or padded values, anduseandalgcombined withkey_ops. Of the 275 outcomes, 32 differ:diroutcomes go from accepted to refused, all of them keys that 4.3 deprecates;No thrown exception changes class. The error passed to
onErroronly changes class for ECDH-SS withderiveKey, which now reaches theepkbug.phpqa,phpunit-11): 2,283 tests, with the 4 skipped and 2 incomplete tests of the base. ECS, Rector, PHPStan and Deptrac are clean with the currentphpqa:8.4image, and the PHPStan baseline is unchanged.infection.json.dist, as in CI, 17 are killed and 24 are skipped. With 60 seconds, all 41 are killed. A first run let aPublicVisibilitymutant ofallowsOperation()escape, which is why the method is now private.For the migration guide
Refs #761