Ignore unknown kty in KeySet.import_key_set (RFC 7517 §5)#103
Open
RalphBragg wants to merge 1 commit into
Open
Ignore unknown kty in KeySet.import_key_set (RFC 7517 §5)#103RalphBragg wants to merge 1 commit into
RalphBragg wants to merge 1 commit into
Conversation
import_key_set raised InvalidKeyTypeError on the first key whose kty was not in the registry, failing the whole set. Skip a key whose kty is present but unrecognised, per RFC 7517 Section 5, so classical keys published alongside a post-quantum key (ML-DSA, kty AKP) remain usable.
Author
|
Tracking issue: #104. This PR fixes it. |
Member
|
I think you can just use try-catch InvalidKeyTypeError, instead of detect it yourself. |
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.
What
KeySet.import_key_setnow skips a key whosektyis present but not in the registry, instead of raisingInvalidKeyTypeErrorand failing the whole set.Why
Today
import_key_setimports each key eagerly, so the first key with an unrecognisedktyraises (Invalid key type: '...') and the entire set fails. RFC 7517 §5 says a processor SHOULD ignore key types it does not understand.This is becoming a live issue as post-quantum keys (ML-DSA,
kty:"AKP", RFC 9964) begin appearing in published JWKS next to RSA/EC keys: one unknown key otherwise stops the classical keys next to it from verifying. (Companion to the same fix in authlib, authlib/authlib#914, sinceauthlib.josepoints here as its successor.)Change
import_key_setskips only keys whosektyis explicitly present and not inregistry_cls.key_types; a recognised-but-malformed key still raises, and a set with no usable keys still raisesMissingKeyErroras before.test_import_key_set_ignores_unknown_kty.tests/jwk/test_jwk_set.pypasses (11 passed).