0
$\begingroup$

The generateKey() docs states:

extractable A boolean value indicating whether it will be possible to export the key using SubtleCrypto.exportKey() or SubtleCrypto.wrapKey().

It isn't entirely clear whether this applies to the public key in keypairs. I would not consider a public key to be a secret. But (sadly) specs don't always agree with me, and a public key is at least a 'key' by name.

The webcrypto spec includes items like:

such deserialization may expose the contents of the key material, which in some cases (such as when the [[extractable]] internal slot is false) should not be exposed to applications.

But again, it's unclear whether a public key is considered key material. I would not consider a public key to be key material. Others may disagree.

Create a file runme.js and run it with node runme.js

const keyPair = await crypto.subtle.generateKey( "Ed25519", false, // note the false for exportable ["sign", "verify"], ); const rawPublicKeyBytes = await crypto.subtle.exportKey("raw", keyPair.publicKey); console.log(`Extractable was false and we were able to export the public key:`, rawPublicKeyBytes); 

We can see the public key is extracted even though the CryptoKeyPair was created with exportable: false.

Is allowing a public key to be exported when the CryptoKeyPair was created with exportable: false the correct behavior?

$\endgroup$

1 Answer 1

2
$\begingroup$

I've found the answer since posting this, answering here to help others:

Yes this is spec compliant. publicKey is statically set to true for RSA and Ed25519 keypairs (and probably other types too).

For RSA keypairs

See https://w3c.github.io/webcrypto/#rsassa-pkcs1-operations (scroll down to 'Generate Key')

...

Set the [[extractable]] internal slot of publicKey to true.

...

Set the [[extractable]] internal slot of privateKey to extractable.

For Ed25519 keypairs

For Ed25519 - see https://wicg.github.io/webcrypto-secure-curves/#ed25519-operations (scroll down to 'Generate Key')

Set the [[extractable]] internal slot of publicKey to true.

...

Set the [[extractable]] internal slot of privateKey to extractable.

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.