| OLD | NEW | 
|   1 <!DOCTYPE html> |   1 <!DOCTYPE html> | 
|   2 <html> |   2 <html> | 
|   3 <head> |   3 <head> | 
|   4 <script src="../resources/js-test.js"></script> |   4 <script src="../resources/js-test.js"></script> | 
|   5 <script src="resources/common.js"></script> |   5 <script src="resources/common.js"></script> | 
|   6 </head> |   6 </head> | 
|   7 <body> |   7 <body> | 
|   8 <p id="description"></p> |   8 <p id="description"></p> | 
|   9 <div id="console"></div> |   9 <div id="console"></div> | 
|  10  |  10  | 
|  11 <script> |  11 <script> | 
|  12 description("Tests bad algorithm inputs for AES-GCM"); |  12 description("Tests generateKey() with bad HMAC parameters."); | 
|  13  |  | 
|  14 jsTestIsAsync = true; |  13 jsTestIsAsync = true; | 
|  15  |  14  | 
|  16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); |  15 extractable = true; | 
|  17 var data = asciiToUint8Array("hello"); |  16 keyUsages = ['sign', 'verify']; | 
|  18 var key = null; |  | 
|  19  |  17  | 
|  20 Promise.resolve(null).then(function(result) { |  18 Promise.resolve(null).then(function() { | 
|  21     var usages = ['encrypt', 'decrypt']; |  19     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: -3}, extractable , keyUsages); | 
|  22     var extractable = false; |  | 
|  23     var algorithm = {name: 'aes-gcm'}; |  | 
|  24  |  | 
|  25     return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
    s); |  | 
|  26 }).then(function(result) { |  | 
|  27     key = result; |  | 
|  28  |  | 
|  29     return crypto.subtle.encrypt({name: 'AES-gcm'}, key, data); |  | 
|  30 }).then(failAndFinishJSTest, function(result) { |  20 }).then(failAndFinishJSTest, function(result) { | 
|  31     error = result; |  21     error = result; | 
|  32     shouldBeNull("error"); |  22     shouldBeNull("error"); | 
|  33  |  23  | 
|  34     return crypto.subtle.encrypt({name: 'AES-gcm', iv: 3}, key, data); |  24     return crypto.subtle.generateKey({name: 'hmac', hash: {name: ''}, length: 48
    }, extractable , keyUsages); | 
|  35 }).then(failAndFinishJSTest, function(result) { |  25 }).then(failAndFinishJSTest, function(result) { | 
|  36     error = result; |  26     error = result; | 
|  37     shouldBeNull("error"); |  27     shouldBeNull("error"); | 
|  38  |  28  | 
|  39     return crypto.subtle.encrypt({name: 'AES-gcm', iv: 'foo'}, key, data); |  29     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: 5000000000}, extractable , keyUsages); | 
|  40 }).then(failAndFinishJSTest, function(result) { |  30 }).then(failAndFinishJSTest, function(result) { | 
|  41     error = result; |  31     error = result; | 
|  42     shouldBeNull("error"); |  32     shouldBeNull("error"); | 
|  43  |  33  | 
|  44     return crypto.subtle.encrypt({name: 'AeS-gcm', iv: new Uint8Array(16), addit
    ionalData: '5'}, key, data); |  34     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: NaN}, extractable , keyUsages); | 
|  45 }).then(failAndFinishJSTest, function(result) { |  35 }).then(failAndFinishJSTest, function(result) { | 
|  46     error = result; |  36     error = result; | 
|  47     shouldBeNull("error"); |  37     shouldBeNull("error"); | 
|  48  |  38  | 
|  49     return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), addit
    ionalData: new Uint8Array(1), tagLength: 'foo'}, key, data); |  39     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: Infinity}, extractable , keyUsages); | 
|  50 }).then(failAndFinishJSTest, function(result) { |  40 }).then(failAndFinishJSTest, function(result) { | 
|  51     error = result; |  41     error = result; | 
|  52     shouldBeNull("error"); |  42     shouldBeNull("error"); | 
|  53  |  43  | 
|  54     return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), addit
    ionalData: new Uint8Array(1), tagLength: -1}, key, data); |  44     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: -Infinity}, extractable , keyUsages); | 
|  55 }).then(failAndFinishJSTest, function(result) { |  45 }).then(failAndFinishJSTest, function(result) { | 
|  56     error = result; |  46     error = result; | 
|  57     shouldBeNull("error"); |  47     shouldBeNull("error"); | 
|  58  |  48  | 
|  59     return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), addit
    ionalData: new Uint8Array(1), tagLength: 8000}, key, data); |  49     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: crypto}, extractable , keyUsages); | 
|  60 }).then(failAndFinishJSTest, function(result) { |  50 }).then(failAndFinishJSTest, function(result) { | 
|  61     error = result; |  51     error = result; | 
|  62     shouldBeNull("error"); |  52     shouldBeNull("error"); | 
 |  53  | 
 |  54     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: undefined}, extractable , keyUsages); | 
 |  55 }).then(failAndFinishJSTest, function(result) { | 
 |  56     error = result; | 
 |  57     shouldBeNull("error"); | 
 |  58  | 
 |  59     return crypto.subtle.generateKey({name: 'hmac', hash: {name: 'sha-256'}, len
    gth: true}, extractable , keyUsages); | 
 |  60 }).then(failAndFinishJSTest, function(result) { | 
 |  61     error = result; | 
 |  62     shouldBeNull("error"); | 
|  63 }).then(finishJSTest, failAndFinishJSTest); |  63 }).then(finishJSTest, failAndFinishJSTest); | 
|  64  |  64  | 
|  65 </script> |  65 </script> | 
|  66  |  66  | 
|  67 </body> |  67 </body> | 
|  68 </html> |  68 </html> | 
| OLD | NEW |