1

I'm trying to export an ECDSA (this probably applies to ECDH as well) private key I've generated with SubtleCrypto in JavaScript. According to MDN (yes, this is for importKey, but this is where you are linked from the page for exportKey), I can use PKCS#8 for this purpose, and so I put together the following code snippet that seeks to implement a such export:

crypto.subtle.generateKey(
    {
        "name": "ECDSA",
        "namedCurve": "P-256"
    },
    true,
    ["sign", "verify"]
).then(keys => {
    crypto.subtle.exportKey("pkcs8", keys.privateKey)
        .then(exported_key => {
            console.log(exported_key)
        })
})

This works in Chromium and GNOME Web (WebKit). In Firefox, I get the following error logged to the console:

Uncaught (in promise) DOMException: Operation is not supported

This seems to come from the latter expression, i.e. the call to exportKey. Firefox support is important to me and what I'm working on, so I'd like to figure this out, and I imagine it is rather that I'm doing something wrong than a bug in Firefox, so I'm thinking this is better to figure out than just to say Firefox isn't supported regardless.

One might think this is due to Firefox not supporting exporting EC keys with PKSC#8, but looking at the compatibility table on MDN this seems to not be the case since it is marked as being supported from version 34 and onwards and there are no implementation notes. I digress.

What might I be doing wrong here, and how can I make it work?

Newbyte
  • 2,421
  • 5
  • 22
  • 45
  • 2
    Seems to be an open Firefox bug, [Bug 1133698](https://bugzilla.mozilla.org/show_bug.cgi?id=1133698) and [D97857](https://phabricator.services.mozilla.com/D97857). – Topaco Jan 01 '21 at 10:35
  • 1
    both bugs are now marked closed and the code in the question just worked for me (firefox version 94.0.1, chrome version 96.0.4664.45) – cubesareneat Nov 23 '21 at 23:16
  • Definitely an awkward situation. How do you think this should be handled? – Newbyte Nov 24 '21 at 16:59

0 Answers0