Bug 1368859 - Test that the Web Crypto API rejects 0-length AES-GCM IVs r=keeler
authorTim Taubert <ttaubert@mozilla.com>
Wed, 21 Jun 2017 12:48:04 +0200
changeset 598334 94365aa1f1284a82274126ba575e35aefd5fe211
parent 598333 1d7e008d7d70c5aa07f2ffc57514d08e0a8033e0
child 598335 5860160aa25501de7374a05bc892cf879110e218
push id65172
push usergpascutto@mozilla.com
push dateWed, 21 Jun 2017 16:21:54 +0000
reviewerskeeler
bugs1368859
milestone56.0a1
Bug 1368859 - Test that the Web Crypto API rejects 0-length AES-GCM IVs r=keeler
dom/crypto/test/test_WebCrypto.html
--- a/dom/crypto/test/test_WebCrypto.html
+++ b/dom/crypto/test/test_WebCrypto.html
@@ -719,16 +719,104 @@ TestArray.addTest(
         error(that),
         complete(that)
       );
   }
 );
 
 // -----------------------------------------------------------------------------
 TestArray.addTest(
+  "AES-GCM encryption, fail with a zero-length IV",
+  function () {
+    var that = this;
+    var alg = {
+      name: "AES-GCM",
+      iv: new Uint8Array(),
+      additionalData: tv.aes_gcm_enc.adata,
+      tagLength: 128
+    };
+
+    function doEncrypt(x) {
+      return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
+    }
+
+    crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
+      .then(doEncrypt)
+      .then(error(that), complete(that));
+  }
+);
+
+// -----------------------------------------------------------------------------
+TestArray.addTest(
+  "AES-GCM encryption, accept an all-zero IV (1 byte)",
+  function () {
+    var that = this;
+    var alg = {
+      name: "AES-GCM",
+      iv: new Uint8Array(1),
+      additionalData: tv.aes_gcm_enc.adata,
+      tagLength: 128
+    };
+
+    function doEncrypt(x) {
+      return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
+    }
+
+    crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
+      .then(doEncrypt)
+      .then(complete(that), error(that));
+  }
+);
+
+// -----------------------------------------------------------------------------
+TestArray.addTest(
+  "AES-GCM encryption, accept an all-zero IV (12 bytes)",
+  function () {
+    var that = this;
+    var alg = {
+      name: "AES-GCM",
+      iv: new Uint8Array(12),
+      additionalData: tv.aes_gcm_enc.adata,
+      tagLength: 128
+    };
+
+    function doEncrypt(x) {
+      return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
+    }
+
+    crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
+      .then(doEncrypt)
+      .then(complete(that), error(that));
+  }
+);
+
+// -----------------------------------------------------------------------------
+TestArray.addTest(
+  "AES-GCM encryption, accept an all-zero IV (16 bytes)",
+  function () {
+    var that = this;
+    var alg = {
+      name: "AES-GCM",
+      iv: new Uint8Array(16),
+      additionalData: tv.aes_gcm_enc.adata,
+      tagLength: 128
+    };
+
+    function doEncrypt(x) {
+      return crypto.subtle.encrypt(alg, x, tv.aes_gcm_enc.data);
+    }
+
+    crypto.subtle.importKey("raw", tv.aes_gcm_enc.key, "AES-GCM", false, ['encrypt'])
+      .then(doEncrypt)
+      .then(complete(that), error(that));
+  }
+);
+
+// -----------------------------------------------------------------------------
+TestArray.addTest(
   "HMAC SHA-256 sign",
   function() {
     var that = this;
     var alg = {
       name: "HMAC",
       hash: "SHA-256"
     }