Skip to content

Reject JWK keys with conflicting use and key_ops#291

Open
Syed-Moiz-Ali wants to merge 1 commit into
google:masterfrom
Syed-Moiz-Ali:feat/jwk-key-ops
Open

Reject JWK keys with conflicting use and key_ops#291
Syed-Moiz-Ali wants to merge 1 commit into
google:masterfrom
Syed-Moiz-Ali:feat/jwk-key-ops

Conversation

@Syed-Moiz-Ali

Copy link
Copy Markdown

Fixes #58

Validates JWK \use/\key_ops\ consistency during key import across both FFI and JS backends, matching Chromium's \VerifyUsages\ behavior.

FFI backend changes:


  • sa_common.dart, \ec_common.dart, \�es_common.dart, \hmac.dart: validate \key_ops\ entries are consistent with the algorithm's expected \use\ value
    • \sig\ algorithms allow only [sign, verify]\
    • \enc\ algorithms allow only [encrypt, decrypt, wrapKey, unwrapKey, deriveKey, deriveBits]\
  • Removes TODO comments about missing \key_ops\ validation

JS backend changes:

  • Adds _checkJwkUseAndKeyOps()\ that cross-validates \use\ vs \key_ops\ when both are present
  • Now strips \use\ (alongside existing \key_ops\ and \ext) before forwarding to \crypto.subtle.importKey\
  • Removes the ECDH Chrome workaround (\crbug.com/641499) since \use\ is now always stripped for all algorithms
  • Removes TODO about missing \use\ validation

Tests:

  • \ est/jwk_key_ops_validation_test.dart: verifies rejection of conflicting \use/\key_ops\ across HMAC, AES, ECDSA, and RSA imports

Adds validation of JWK use/key_ops consistency across all backends:

FFI backend:
  - rsa_common: validate key_ops entries match expectedUse
  - ec_common: validate key_ops entries match expectedUse
  - aes_common: validate key_ops entries are enc-consistent
  - hmac: validate key_ops entries are sig-consistent
  - Removes TODO comments about missing key_ops validation

JS backend:
  - Adds _checkJwkUseAndKeyOps cross-validation of use vs key_ops
  - Strips use along with key_ops and ext before forwarding to browser
  - Removes ECDH Chrome workaround (crbug.com/641499) since use is now
    always stripped for all algorithms
  - Removes TODO about missing use validation

Tests added for conflicting use/key_ops across HMAC, AES, ECDSA, RSA.

Fixes google#58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject JWK keys that have conflicting "use" and "key_ops"

1 participant