Bug 1410403 - Use id-ecPublicKey for ECDH key export from WebCrypto r=keeler
authorJ.C. Jones <jjones@mozilla.com>
Mon, 11 Nov 2019 21:25:40 +0000
changeset 501756 35f2efaaeff6d8c617498ba1958a2409efe1c92c
parent 501755 5d93cdf79d2796c10ea902470cab90b9f903b159
child 501757 2c748c06bd9b294017bd5b5d6b0967b86b580d7c
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1410403, 10045
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1410403 - Use id-ecPublicKey for ECDH key export from WebCrypto r=keeler id-ecPublicKey is defined as the OID {iso(1) member-body(2) us(840) ansi-x962(10045) keyType(2) ecPublicKey(1)}, and is the NSS default, so remove the override code from CryptoKey.cpp that forced it to the legacy id-ecDH code. Differential Revision: https://phabricator.services.mozilla.com/D52570
dom/crypto/CryptoKey.cpp
dom/crypto/test/test_WebCrypto_ECDH.html
--- a/dom/crypto/CryptoKey.cpp
+++ b/dom/crypto/CryptoKey.cpp
@@ -445,17 +445,17 @@ UniqueSECKEYPublicKey CryptoKey::PublicK
       SECKEY_DecodeDERSubjectPublicKeyInfo(&spkiItem));
   if (!spki) {
     return nullptr;
   }
 
   bool isECDHAlgorithm =
       SECITEM_ItemsAreEqual(&SEC_OID_DATA_EC_DH, &spki->algorithm.algorithm);
 
-  // Check for |id-ecDH|. Per the WebCrypto spec we must
+  // Check for |id-ecDH|. Per old versions of the WebCrypto spec we must
   // support this OID but NSS does unfortunately not know it. Let's
   // change the algorithm to |id-ecPublicKey| to make NSS happy.
   if (isECDHAlgorithm) {
     SECOidTag oid = SEC_OID_ANSIX962_EC_PUBLIC_KEY;
 
     SECOidData* oidData = SECOID_FindOIDByTag(oid);
     if (!oidData) {
       return nullptr;
@@ -492,27 +492,16 @@ nsresult CryptoKey::PublicKeyToSpki(SECK
                                     CryptoBuffer& aRetVal) {
   UniqueCERTSubjectPublicKeyInfo spki;
 
   spki.reset(SECKEY_CreateSubjectPublicKeyInfo(aPubKey));
   if (!spki) {
     return NS_ERROR_DOM_OPERATION_ERR;
   }
 
-  // Per WebCrypto spec we must export ECDH SPKIs with the algorithm OID
-  // id-ecDH (1.3.132.112). NSS doesn't know about this OID and there is
-  // no way to specify the algorithm to use when exporting a public key.
-  if (aPubKey->keyType == ecKey) {
-    SECStatus rv = SECITEM_CopyItem(spki->arena, &spki->algorithm.algorithm,
-                                    &SEC_OID_DATA_EC_DH);
-    if (rv != SECSuccess) {
-      return NS_ERROR_DOM_OPERATION_ERR;
-    }
-  }
-
   const SEC_ASN1Template* tpl = SEC_ASN1_GET(CERT_SubjectPublicKeyInfoTemplate);
   UniqueSECItem spkiItem(SEC_ASN1EncodeItem(nullptr, nullptr, spki.get(), tpl));
 
   if (!aRetVal.Assign(spkiItem.get())) {
     return NS_ERROR_DOM_OPERATION_ERR;
   }
   return NS_OK;
 }
--- a/dom/crypto/test/test_WebCrypto_ECDH.html
+++ b/dom/crypto/test/test_WebCrypto_ECDH.html
@@ -389,17 +389,17 @@ TestArray.addTest(
     }
 
     function nextKey() {
       var key = keys.shift();
       var imported = doImport(key);
       var derived = imported.then(doExport);
 
       return derived.then(function(x) {
-        if (!util.memcmp(x, tv.ecdh_p256.spki)) {
+        if (!util.memcmp(x, tv.ecdh_p256.spki_id_ecpk)) {
           throw new Error("exported key is invalid");
         }
 
         if (keys.length) {
           return nextKey();
         }
         return Promise.resolve();
       });