Bug 233705
| Summary: | PKCS8 EC private keys without the public key component cannot be imported with SubtleCrypto.importKey | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Filip Skokan <panva.ip> |
| Component: | WebKit Misc. | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | ahmad.saleem792, bfulgham, davertay, karlcow, katherine_cheney, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Other | ||
| Hardware: | All | ||
| OS: | All | ||
Filip Skokan
Steps to reproduce:
// PKCS8 representation of a private P-384 EC key with the public key omitted
const pkcs8 = new Uint8Array([48, 78, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 4, 55, 48, 53, 2, 1, 1, 4, 48, 32, 52, 118, 9, 96, 116, 119, 172, 168, 251, 251, 197, 230, 33, 132, 85, 243, 25, 150, 105, 121, 46, 248, 180, 102, 250, 168, 123, 220, 103, 121, 129, 68, 200, 72, 221, 3, 102, 30, 237, 90, 198, 36, 97, 52, 12, 234, 150])
crypto.subtle.importKey('pkcs8', pkcs8, { name: 'ECDSA', namedCurve: 'P-384' }, false, ['sign'])
Actual result:
importKey is rejected with DataError: Data provided to an operation does not meet requirements
Expected result:
EC private key PKCS8 without the public key component should import as in other browsers and Web Cryptography API implementations (we expect interoperability in this regard)
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/86211792>
Ahmad Saleem
Using this in console for all browsers, I get similar error;
const pkcs8 = new Uint8Array([48, 78, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 4, 55, 48, 53, 2, 1, 1, 4, 48, 32, 52, 118, 9, 96, 116, 119, 172, 168, 251, 251, 197, 230, 33, 132, 85, 243, 25, 150, 105, 121, 46, 248, 180, 102, 250, 168, 123, 220, 103, 121, 129, 68, 200, 72, 221, 3, 102, 30, 237, 90, 198, 36, 97, 52, 12, 234, 150])
crypto.subtle.importKey('pkcs8', pkcs8, { name: 'ECDSA', namedCurve: 'P-384' }, false, ['sign'])
___
Safari 17.4, Chrome Canary 124 and Firefox Nightly 125.
Ahmad Saleem
Actually I might have copied code wrong in Chrome:
const pkcs8 = new Uint8Array([48, 78, 2, 1, 0, 48, 16, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 5, 43, 129, 4, 0, 34, 4, 55, 48, 53, 2, 1, 1, 4, 48, 32, 52, 118, 9, 96, 116, 119, 172, 168, 251, 251, 197, 230, 33, 132, 85, 243, 25, 150, 105, 121, 46, 248, 180, 102, 250, 168, 123, 220, 103, 121, 129, 68, 200, 72, 221, 3, 102, 30, 237, 90, 198, 36, 97, 52, 12, 234, 150])
crypto.subtle.importKey('pkcs8', pkcs8, { name: 'ECDSA', namedCurve: 'P-384' }, false, ['sign'])
__
It shows `Promise <pending>`.
davertay
Confirming that an EC private key PKCS8 without the public key fails to import in this manner.
And I have further found that if the a private key payload (RFC5915) does contain the public key, but also contains a `parameters` field then this too will fail to import. For things to work, the inner EC Private Key needs to both include the public key and omit the parameters.