crypto: fix public PKCS8 export error - #65609
Open
koreahghg wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
panva
self-requested a review
August 28, 2026 05:51
panva
reviewed
Aug 28, 2026
panva
left a comment
Member
There was a problem hiding this comment.
@koreahghg thank you, please change the first commit message line to
crypto: fix public PKCS8 export error
mirroring the other fix done in 3615979
exportKeySpki() already rejects exporting a private key as 'spki'
with an InvalidAccessError, per the Web Crypto export key algorithm
steps for each of RSA, EC, CFRG, ML-DSA, and ML-KEM. exportKeyPkcs8()
was missing the symmetric check: exporting a public key as 'pkcs8'
fell through to the generic "Unable to export ... key using pkcs8
format" NotSupportedError instead of the spec-mandated
InvalidAccessError.
Add the same key-type check to exportKeyPkcs8(), mirroring
exportKeySpki(), and drop the now-redundant type guard around its
call site in exportKeySync(). This also fixes wrapKey(), which
delegates to the same export path.
Add test coverage for both subtle.exportKey('pkcs8', publicKey) and
subtle.wrapKey('pkcs8', publicKey, ...).
Signed-off-by: koreahghg <koreahghg@gmail.com>
koreahghg
force-pushed
the
crypto-fix-pkcs8-export-invalidaccesserror
branch
from
August 28, 2026 06:24
298b584 to
1a4fc6f
Compare
Author
|
Updated the commit message per review, thanks! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65609 +/- ##
==========================================
- Coverage 90.07% 90.06% -0.01%
==========================================
Files 751 751
Lines 254916 254920 +4
Branches 48133 48125 -8
==========================================
- Hits 229605 229588 -17
Misses 16496 16496
- Partials 8815 8836 +21
🚀 New features to boost your workflow:
|
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.
Summary
exportKeySpki()already rejects exporting a private key as'spki'with an
InvalidAccessError, per the Web Crypto export key algorithmsteps for RSA, EC, CFRG, ML-DSA, and ML-KEM.
exportKeyPkcs8()wasmissing the symmetric check: exporting a public key as
'pkcs8'fell through to the generic
NotSupportedError("Unable to export... key using pkcs8 format") instead of the spec-mandated
InvalidAccessError.This adds the same key-type check to
exportKeyPkcs8(), mirroringexportKeySpki(), and drops the now-redundant type guard around itscall site in
exportKeySync(). This also fixeswrapKey(), whichdelegates to the same export path (
subtle.wrapKey('pkcs8', publicKey, ...)previously threw the wrong error type too).
Test plan
subtle.exportKey('pkcs8', publicKey)rejection coveragein
test/parallel/test-webcrypto-export-import-ec.jssubtle.wrapKey('pkcs8', publicKey, ...)rejection coveragein
test/parallel/test-webcrypto-wrap-unwrap.jsnode --checkon all changed filesmake test(please run in CI; no local build environment wasavailable when preparing this patch)