WebCrypto API: `deriveBits` fails with X25519 keys imported in 'jwk' format
Categories
(Core :: DOM: Web Crypto, defect)
Tracking
()
People
(Reporter: larabr+github, Unassigned)
Details
Steps to reproduce:
- Import the X25519 test vectors from RFC7748 (https://datatracker.ietf.org/doc/html/rfc7748#section-6.1) using JWK format;
- Run
deriveBits
:
alicePrivateJWK = { kty: 'OKP', crv: 'X25519', x: 'hSDwCYkwp1R0i33ctD73Wg2_Og0mOBr066SpjqqbTmo', ext: true, d: 'dwdtCnMYpX08FsFyUbJmRd9ML4frwJkqsXf7pR25LCo' };
bobPublicJWK = { kty: 'OKP', crv: 'X25519', x: '3p7bfXt9wbTTW2HC7OQ1Nz-DQ8hbeGdNrfx-FG-IK08', ext: true };
alicePrivateKey = await crypto.subtle.importKey('jwk', alicePrivateJWK, 'X25519', true, ['deriveKey', 'deriveBits']);
bobPublicKey = await crypto.subtle.importKey('jwk', bobPublicJWK, 'X25519', true, [])
sharedSecret = new Uint8Array(await crypto.subtle.deriveBits(
{ name: 'X25519', public: bobPublicKey },
alicePrivateKey,
256
)); // this throws
Exporting and re-importing the same keys in PKCS#8/SPKI format results in a successful operation:
bobPublicSKPI = await crypto.subtle.exportKey('spki', bobPublicKey) ;
alicePrivatePKCS8 = await crypto.subtle.exportKey('pkcs8', alicePrivateKey);
alicePrivateKey2 = await crypto.subtle.importKey('pkcs8', alicePrivatePKCS8, 'X25519', true, ['deriveKey', 'deriveBits']);
bobPublicKey2 = await crypto.subtle.importKey('spki', bobPublicSKPI, 'X25519', true, []);
sharedSecret2 = new Uint8Array(await crypto.subtle.deriveBits(
{ name: 'X25519', public: bobPublicKey2 },
alicePrivateKey2,
256
)); // this succeeds
Actual results:
deriveBits
over the JWK imported keys throws: "DOMException: The operation failed for an operation-specific reason".
deriveBits
over the PKCS8/SPKI re-imported keys is successful.
Expected results:
deriveBits
is successful with the JWK imported keys.
Comment 1•10 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Web Crypto' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Updated•10 months ago
|
Comment 3•10 months ago
|
||
I still get DOMException: The operation failed for an operation-specific reason
for the first code example. Is this really a duplicate?
Comment 4•9 months ago
|
||
(In reply to Tom S [:evilpie] from comment #3)
I still get
DOMException: The operation failed for an operation-specific reason
for the first code example. Is this really a duplicate?
Curious, it works for me.
It might be also connected to the bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1920705) than was closed at the same time :)
I can confirm it's still not working for me either on v131.0b9 (macOS)
Updated•9 months ago
|
Comment 6•9 months ago
|
||
(In reply to larabr from comment #5)
I can confirm it's still not working for me either on v131.0b9 (macOS)
Are you using Firefox Release or Nightly?
Updated•9 months ago
|
Comment 7•9 months ago
•
|
||
Actually, sorry for the confusion. I just checked again, and the first code sample does work on Nightly 2024-09-30 for me. Running moz-regression --find-fix
points to https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=b254963175f3d173232c962d039876f49f3bc7c4&tochange=dcf993cb9bd97cb5484ec144bee75d39ec4f1f04, which includes Bug 1920705.
Comment 8•9 months ago
|
||
Great! Let's wait for the reporter answer :)
(In reply to Anna Weine from comment #6)
(In reply to larabr from comment #5)
I can confirm it's still not working for me either on v131.0b9 (macOS)
Are you using Firefox Release or Nightly?
I've downloaded the Beta from https://www.mozilla.org/en-US/firefox/channel/desktop/ .
Comment 10•9 months ago
|
||
Usually the cycle is the following: the bug is solved; it goes to Nightly, then, in one cycle to Beta (that's what you've downloaded), then to Release.
Do you specifically need to use Beta? If no - the problem is fixed in Nightly, you can download it here (https://www.mozilla.org/en-US/firefox/channel/desktop/). If yes, I could think what I can do...
Reporter | ||
Comment 11•9 months ago
|
||
No I don't need it, it just important for us to know which Firefox versions are affected :)
Comment 12•9 months ago
|
||
So, I think it's solved for 132 version (https://bugzilla.mozilla.org/show_bug.cgi?id=1920705#c12)
Tom, correct me if I am wrong :)
Updated•9 months ago
|
Description
•