Bug 1158296 - Allow ECDSA key export in WebCrypto. r=rbarnes, a=sledru
authorMartin Thomson <martin.thomson@gmail.com>
Fri, 24 Apr 2015 12:56:46 -0700
changeset 260511 1a8cd9f5bdad
parent 260510 82e59df1da4e
child 260512 825e8ac4ab29
push id805
push userryanvm@gmail.com
push date2015-05-18 17:06 +0000
treeherdermozilla-release@4bfd19d00ed4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarnes, sledru
bugs1158296
milestone38.0.5
Bug 1158296 - Allow ECDSA key export in WebCrypto. r=rbarnes, a=sledru
dom/crypto/WebCryptoTask.cpp
dom/crypto/test/mochitest.ini
dom/crypto/test/test_WebCrypto_ECDSA.html
--- a/dom/crypto/WebCryptoTask.cpp
+++ b/dom/crypto/WebCryptoTask.cpp
@@ -2987,16 +2987,17 @@ WebCryptoTask::CreateExportKeyTask(const
   if (algName.EqualsLiteral(WEBCRYPTO_ALG_AES_CBC) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_AES_CTR) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_AES_GCM) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_AES_KW) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_PBKDF2) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_HMAC) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_RSASSA_PKCS1) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_RSA_OAEP) ||
+      algName.EqualsLiteral(WEBCRYPTO_ALG_ECDSA) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_ECDH) ||
       algName.EqualsLiteral(WEBCRYPTO_ALG_DH)) {
     return new ExportKeyTask(aFormat, aKey);
   }
 
   return new FailureTask(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
 }
 
--- a/dom/crypto/test/mochitest.ini
+++ b/dom/crypto/test/mochitest.ini
@@ -5,14 +5,15 @@ support-files =
   test-array.js
   test-vectors.js
   test_WebCrypto.css
   util.js
 
 [test_WebCrypto.html]
 [test_WebCrypto_DH.html]
 [test_WebCrypto_ECDH.html]
+[test_WebCrypto_ECDSA.html]
 [test_WebCrypto_JWK.html]
 [test_WebCrypto_Normalize.html]
 [test_WebCrypto_PBKDF2.html]
 [test_WebCrypto_Reject_Generating_Keys_Without_Usages.html]
 [test_WebCrypto_RSA_OAEP.html]
 [test_WebCrypto_Wrap_Unwrap.html]
--- a/dom/crypto/test/test_WebCrypto_ECDSA.html
+++ b/dom/crypto/test/test_WebCrypto_ECDSA.html
@@ -64,16 +64,35 @@ TestArray.addTest(
     crypto.subtle.importKey("jwk", tv.ecdsa_verify.pub_jwk, alg, true, ["verify"])
       .then(doVerify)
       .then(complete(that), error(that))
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
+  "ECDSA key generation with public key export",
+  function() {
+    var that = this;
+    var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
+    var msg = Uint8Array.from([1]);
+
+    crypto.subtle.generateKey(alg, false, ["sign", "verify"])
+      .then(pair => Promise.all([
+          crypto.subtle.sign(alg, pair.privateKey, msg),
+          crypto.subtle.exportKey("spki", pair.publicKey)
+            .then(spki => crypto.subtle.importKey("spki", spki, alg, false, ["verify"]))
+      ]))
+      .then(sigAndKey => crypto.subtle.verify(alg, sigAndKey[1], sigAndKey[0], msg))
+      .then(complete(that), error(that))
+  }
+);
+
+// -----------------------------------------------------------------------------
+TestArray.addTest(
   "ECDSA JWK import and reject a known-bad signature",
   function() {
     var that = this;
     var alg = { name: "ECDSA", namedCurve: "P-256", hash: "SHA-256" };
 
     function doVerify(x) {
       return crypto.subtle.verify(alg, x, tv.ecdsa_verify.sig_tampered,
                                           tv.ecdsa_verify.data);
@@ -126,19 +145,19 @@ TestArray.addTest(
 );
 
 /*]]>*/</script>
 </head>
 
 <body>
 
 <div id="content">
-	<div id="head">
-		<b>Web</b>Crypto<br>
-	</div>
+        <div id="head">
+                <b>Web</b>Crypto<br>
+        </div>
 
     <div id="start" onclick="start();">RUN ALL</div>
 
     <div id="resultDiv" class="content">
     Summary:
     <span class="pass"><span id="passN">0</span> passed, </span>
     <span class="fail"><span id="failN">0</span> failed, </span>
     <span class="pending"><span id="pendingN">0</span> pending.</span>