Skip to content

fix: EC named-curve match, on-curve check, uncompressed SPKI export#1027

Merged
boorad merged 2 commits intomainfrom
fix/ec-curve-validation-uncompressed-spki
May 6, 2026
Merged

fix: EC named-curve match, on-curve check, uncompressed SPKI export#1027
boorad merged 2 commits intomainfrom
fix/ec-curve-validation-uncompressed-spki

Conversation

@boorad
Copy link
Copy Markdown
Collaborator

@boorad boorad commented May 6, 2026

Summary

Closes the three EC-specific WebCrypto gaps tracked in #1005:

  • D.1 — SPKI/PKCS#8 import now validates the parsed curve OID against algorithm.namedCurve and rejects mismatches with DataError('Named curve mismatch'), matching Node's ecImportKey.
  • D.2 — New KeyObjectHandle.checkEcKeyData() Nitro method delegates to ncrypto's EVPKeyCtxPointer::publicCheck()/privateCheck() (backed by EVP_PKEY_public_check_quick/EVP_PKEY_check) to verify the point lies on the named curve post-import.
  • D.3subtle.ecExportKey detects compressed-form SPKI by byte length (91/120/158 for P-256/P-384/P-521) and re-exports uncompressed by reconstructing 0x04 || x || y from the JWK coordinates and round-tripping through initECRaw. Falls back to OperationError if the rebuild can't be performed.

Changes

  • packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.{cpp,hpp}checkEcKeyData() implementation.
  • packages/react-native-quick-crypto/nitrogen/generated/... — regenerated Nitro bindings for the new method.
  • packages/react-native-quick-crypto/src/specs/keyObjectHandle.nitro.ts — TS spec for the new native method.
  • packages/react-native-quick-crypto/src/ec.ts — curve-OID match check after SPKI/PKCS#8 import; on-curve check after all non-JWK imports.
  • packages/react-native-quick-crypto/src/subtle.ts — uncompressed-SPKI re-export path with OperationError on rebuild failure.
  • example/src/tests/subtle/import_export.ts — three new tests:
    • EC SPKI import rejects named-curve mismatch (#1005) — P-256 SPKI imported as P-384 → DataError.
    • EC PKCS#8 import rejects named-curve mismatch (#1005) — P-256 PKCS#8 imported as P-384 → DataError.
    • EC SPKI export forces uncompressed point (#1005) — hand-rolled compressed P-256 SPKI round-trips to a 91-byte uncompressed SPKI.

Test plan

  • Run example app on iOS — full subtle/import_export suite passes, including the three new #1005 tests.
  • Run example app on Android — same suite passes.
  • Spot-check existing EC import/export round-trip tests still pass.
  • Confirm bun tsc is clean across packages.

Fixes #1005

🤖 Generated with Claude Code

boorad added 2 commits May 5, 2026 22:41
…1005)

D.1 — After SPKI/PKCS#8 import, validate the parsed curve OID matches
  algorithm.namedCurve; reject with DataError('Named curve mismatch'),
  matching Node's behavior.

D.2 — Add KeyObjectHandle.checkEcKeyData() backed by ncrypto's
  EVPKeyCtxPointer::publicCheck/privateCheck (EVP_PKEY_public_check_quick /
  EVP_PKEY_check). Called post-import so points are verified to lie on the
  named curve.

D.3 — In subtle.ecExportKey, detect compressed-form SPKI by length and
  re-export uncompressed: rebuild 0x04||x||y from JWK coordinates and
  round-trip via initECRaw, so spki output is always WebCrypto-compliant.
…atch test

Address review feedback on the #1005 EC export fix:

- Replace the silent fallback in ecExportKey when the JWK lacks x/y or
  initECRaw fails — emit OperationError instead so callers never receive
  a non-WebCrypto-compliant compressed SPKI.
- Drop redundant ArrayBuffer slice on a fresh Uint8Array.
- Drop misleading comment on kUncompressedSpkiLength.
- Add a PKCS#8 named-curve mismatch test alongside the existing SPKI one.
@boorad boorad self-assigned this May 6, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-native-quick-crypto Ready Ready Preview, Comment May 6, 2026 3:21am

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 25414664165

📸 Final Test Screenshot

Maestro Test Results - android

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 25414664167

📸 Final Test Screenshot

Maestro Test Results - ios

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@boorad boorad merged commit 9155523 into main May 6, 2026
10 checks passed
@boorad boorad deleted the fix/ec-curve-validation-uncompressed-spki branch May 6, 2026 13:12
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.

EC: validate named-curve match, on-curve point, and uncompressed-SPKI export

1 participant