Bug 1917228 - WebCrypto: X25519 public key should be copied so it can be exported as jwk r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D221308
This commit is contained in:
Anna Weine 2024-09-17 11:11:39 +00:00
parent c9e9c193c8
commit b6bf25a4ba
2 changed files with 10 additions and 4 deletions

View File

@ -302,9 +302,10 @@ void CryptoKey::SetExtractable(bool aExtractable) {
nsresult CryptoKey::AddPublicKeyData(SECKEYPublicKey* aPublicKey) {
// This should be a private key.
MOZ_ASSERT(GetKeyType() == PRIVATE);
// There should be a private NSS key with type 'EC' and 'ED'.
// There should be a private NSS key with type 'EC', 'EC Montgomery' or 'ED'.
MOZ_ASSERT(mPrivateKey &&
(mPrivateKey->keyType == ecKey || mPrivateKey->keyType == edKey));
(mPrivateKey->keyType == ecKey || mPrivateKey->keyType == edKey ||
mPrivateKey->keyType == ecMontKey));
// The given public key should have the same key type.
MOZ_ASSERT(aPublicKey->keyType == mPrivateKey->keyType);
@ -328,13 +329,17 @@ nsresult CryptoKey::AddPublicKeyData(SECKEYPublicKey* aPublicKey) {
CK_OBJECT_CLASS privateKeyValue = CKO_PRIVATE_KEY;
CK_BBOOL falseValue = CK_FALSE;
/* ecKey corresponds to CKK_EC; edKey corresponds to CKK_EC_EDWARDS key.
The other key types are not allowed. */
// ecKey corresponds to CKK_EC;
// edKey corresponds to CKK_EC_EDWARDS key,
// ecMontKey corresponds to CKK_EC_MONTGOMERY.
// The other key types are not allowed.
CK_KEY_TYPE ecValue;
if (mPrivateKey->keyType == ecKey) {
ecValue = CKK_EC;
} else if (mPrivateKey->keyType == edKey) {
ecValue = CKK_EC_EDWARDS;
} else if (mPrivateKey->keyType == ecMontKey) {
ecValue = CKK_EC_MONTGOMERY;
} else {
return NS_ERROR_DOM_OPERATION_ERR;
}

View File

@ -2768,6 +2768,7 @@ nsresult GenerateAsymmetricKeyTask::DoCrypto() {
// PK11_GenerateKeyPair() does not set a CKA_EC_POINT attribute on the
// private key, we need this later when exporting to PKCS8 and JWK though.
if (mMechanism == CKM_EC_KEY_PAIR_GEN ||
mMechanism == CKM_EC_MONTGOMERY_KEY_PAIR_GEN ||
mMechanism == CKM_EC_EDWARDS_KEY_PAIR_GEN) {
rv = mKeyPair->mPrivateKey->AddPublicKeyData(mPublicKey.get());
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_OPERATION_ERR);