Skip to content

Commit

Permalink
crypto: fix subtle.importKey JWK OKP public key import
Browse files Browse the repository at this point in the history
PR-URL: #37255
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
panva authored and danielleadams committed Feb 16, 2021
1 parent 85bed2e commit e28ea89
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/crypto/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ async function ecImportKey(
keyObject = createECRawKey(
namedCurve,
Buffer.from(
isPublic ? keyData.k : keyData.d,
isPublic ? keyData.x : keyData.d,
'base64'),
isPublic);
break;
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-webcrypto-x25519-x448.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,36 @@ assert.rejects(
{
message: /Unsupported named curves for ECDH/
});

{
// Private JWK import
subtle.importKey(
'jwk',
{
crv: 'X25519',
d: '8CE-XY7cvbR-Pu7mILHq8YZ4hLGAA2-RD01he5q2wUA',
x: '42IbTo34ZYANub5o42547vB6OxdEd44ztwZewoRch0Q',
kty: 'OKP'
},
{
name: 'ECDH',
namedCurve: 'NODE-X25519'
},
true,
['deriveBits']).then(common.mustCall());

// Public JWK import
subtle.importKey(
'jwk',
{
crv: 'X25519',
x: '42IbTo34ZYANub5o42547vB6OxdEd44ztwZewoRch0Q',
kty: 'OKP'
},
{
name: 'ECDH',
namedCurve: 'NODE-X25519'
},
true,
[]).then(common.mustCall());
}

0 comments on commit e28ea89

Please sign in to comment.