-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Report: Error while calling importJsonWebKey #66
Comments
cc @jonasfj 🙏 |
What happens if you do this in a various browsers? window.crypto.subtle.importKey(
'jwk', {
"kty": "EC",
"crv": "P-256",
"x": "h0rbX_vxGVgx-u-ITxnydyy7W9VNGFITcqltL7hDa5A=",
"y": "iQdcRQ8aghMIKnnE1RZEzrfag4c2PHBq8kVea6tK6w==",
"d": "A-zAYOf8KYYxZvP6akkL6SNjBPygstC7VALP2cuh0QA="
}, {
"name": "ECDH",
"namedCurve": "P-256"
}, true, ['deriveKey']
).then(
k => console.log(k)
).catch(
err => console.log(err)
); Fails for me on both Chrome and Firefox. This indicates to me that the JWK might be malformed or incorrectly formatted. |
From: https://datatracker.ietf.org/doc/html/rfc7517#section-1.1
|
Is there any reason to think this is a valid JWK? What other libraries that understand JWKs will accept this JWK? |
I also fail on Chrome with error Here is my example project: https://github.com/leanhdaoit/chat-e2e-example
maybe the old libraries don't check the format of the x and y points, but it can still do deriveKey and encrypt/decrypt (AES-GCM) 🤔🤔 |
I don't find it hard to believe that there are other libraries out there that'll accept JWKs that are somewhat malformed. I'm guessing that you could simply remove the padding and possibly prepend the In any case, unless we can somehow reasonably say that the input is a valid JWK and would be accepted by most other webcrypto implementations, then I suggest we close this issue. |
I can confirm that after padLeft zero with length 32 of
|
Description
When calling the function EcdhPrivateKey.importJsonWebKey with a specific private key JWK object, the following error occurs:
FormatException: JWK property "y" should hold 32 bytes
Steps to Reproduce
EcdhPrivateKey.importJsonWebKey(privateKeyJWK, EllipticCurve.p256);
Expected Behavior
The function EcdhPrivateKey.importJsonWebKey should import the private key JWK object without errors.
Actual Behavior
The function EcdhPrivateKey.importJsonWebKey throws a FormatException with the message "JWK property "y" should hold 32 bytes".
Additional Context
y
is only 31 bytes butparamSize
is 32 bytes (line 169 inimpl_ffi.ec_common.dart
)impl_ffi.ec_common.dart
it works normallyEnvironment
webcrypto: ^0.5.3
flutter doctor -v
The text was updated successfully, but these errors were encountered: