Bug 1158296 - Allow ECDSA key export in WebCrypto, r=rbarnes
authorMartin Thomson <martin.thomson@gmail.com>
Fri, 24 Apr 2015 12:56:46 -0700
changeset 241025 1835de92a1bd0e0c652fbd92b5deaebd7b769162
parent 241024 d1269f811e059a9648c993a97edf63976fbc3559
child 241026 ee381f0c4b9351d1b4c84aaf9b5331bb44293fa1
push id58996
push usermartin.thomson@gmail.com
push dateFri, 24 Apr 2015 22:22:30 +0000
treeherdermozilla-inbound@1835de92a1bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarnes
bugs1158296
milestone40.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 1158296 - Allow ECDSA key export in WebCrypto, r=rbarnes
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>