Skip to content

fix(ffi): reject private JWKs in RSA public imports - #333

Merged
HamdaanAliQuatil merged 2 commits into
google:masterfrom
harrshita123:fix/rsa-public-jwk-import
Jul 24, 2026
Merged

fix(ffi): reject private JWKs in RSA public imports#333
HamdaanAliQuatil merged 2 commits into
google:masterfrom
harrshita123:fix/rsa-public-jwk-import

Conversation

@harrshita123

Copy link
Copy Markdown
Contributor

Summary

  • Reject RSA JWKs containing the private exponent when importing a public key through the native FFI backend.
  • Add regression coverage for RSA-OAEP, RSA-PSS, and RSASSA-PKCS1-v1_5 public-key imports.

Root cause

The shared native RSA JWK importer required d for private-key imports but did not require it to be absent for public-key imports. Public-key import methods therefore accepted private JWKs and silently discarded their private parameters.

The new validation rejects the JWK before allocating or parsing the native RSA key.

Validation

  • dart analyze
  • dart test test/rsa_jwk_validation_test.dart -p vm
  • dart test test/rsa_jwk_validation_test.dart -p chrome
  • dart test -p vm

Fixes #332

@harrshita123
harrshita123 marked this pull request as ready for review July 20, 2026 14:45
@harrshita123
harrshita123 force-pushed the fix/rsa-public-jwk-import branch from b25583b to 9707d6e Compare July 20, 2026 14:47

@HamdaanAliQuatil HamdaanAliQuatil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct. An RSA JWK with d is a private key, so the public import APIs should reject it instead of silently using only n and e. Keeping the check in the shared RSA importer covers OAEP, PSS, and PKCS#1 and brings the native backend in line with Web Crypto.

I ran the focused test on VM and Chromium, the full VM suite, and dart analyze locally; all passed. Could you also add a short entry under 0.6.2-wip in the changelog?

@harrshita123

Copy link
Copy Markdown
Contributor Author

This looks correct. An RSA JWK with d is a private key, so the public import APIs should reject it instead of silently using only n and e. Keeping the check in the shared RSA importer covers OAEP, PSS, and PKCS#1 and brings the native backend in line with Web Crypto.

I ran the focused test on VM and Chromium, the full VM suite, and dart analyze locally; all passed. Could you also add a short entry under 0.6.2-wip in the changelog?

I have added a short entry under 0.6.2-wip in the changelog to document the RSA public JWK import fix.

@HamdaanAliQuatil HamdaanAliQuatil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :)

@HamdaanAliQuatil
HamdaanAliQuatil merged commit 383bfc7 into google:master Jul 24, 2026
15 checks passed
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.

bug: native RSA public JWK imports accept private keys

2 participants