| OLD | NEW | 
 | (Empty) | 
|   1 <!DOCTYPE html> |  | 
|   2 <html> |  | 
|   3 <head> |  | 
|   4 <script src="../resources/js-test.js"></script> |  | 
|   5 <script src="resources/common.js"></script> |  | 
|   6 <script src="resources/keys.js"></script> |  | 
|   7 </head> |  | 
|   8 <body> |  | 
|   9 <p id="description"></p> |  | 
|  10 <div id="console"></div> |  | 
|  11  |  | 
|  12 <script> |  | 
|  13 description("Tests structured cloning of RSA private keys (without a hash)"); |  | 
|  14  |  | 
|  15 jsTestIsAsync = true; |  | 
|  16  |  | 
|  17 // Tests the 16 permutations of keys generated by: |  | 
|  18 //   kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
    KeyData |  | 
|  19 // |  | 
|  20 // For practical reasons these tests are not exhaustive. |  | 
|  21  |  | 
|  22 var kPossibleAlgorithms = ['RSAES-PKCS1-v1_5']; |  | 
|  23 var kPossibleExtractable = [true, false]; |  | 
|  24 var kPossibleKeyUsages = [[], ['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', '
    wrapKey', 'unwrapKey']]; |  | 
|  25  |  | 
|  26 var kPossibleKeyData = [ |  | 
|  27     kKeyData.rsa1, |  | 
|  28     kKeyData.rsa4 |  | 
|  29 ]; |  | 
|  30  |  | 
|  31 function runTest(algorithmName, extractable, keyUsages, keyData) |  | 
|  32 { |  | 
|  33     var importData = hexStringToUint8Array(keyData.pkcs8); |  | 
|  34     var importAlgorithm = { name: algorithmName }; |  | 
|  35  |  | 
|  36     var results = {}; |  | 
|  37  |  | 
|  38     return crypto.subtle.importKey('pkcs8', importData, importAlgorithm, extract
    able, keyUsages).then(function(importedKey) { |  | 
|  39         results.importedKey = importedKey; |  | 
|  40         importedKey.extraProperty = 'hi'; |  | 
|  41         return cloneKey(importedKey); |  | 
|  42     }).then(function(clonedKey) { |  | 
|  43         results.clonedKey = clonedKey; |  | 
|  44         if (extractable) |  | 
|  45             return crypto.subtle.exportKey('pkcs8', clonedKey); |  | 
|  46         return null; |  | 
|  47     }).then(function(clonedKeyData) { |  | 
|  48         importedKey = results.importedKey; |  | 
|  49         clonedKey = results.clonedKey; |  | 
|  50  |  | 
|  51         shouldEvaluateAs("importedKey.extraProperty", "hi"); |  | 
|  52         shouldEvaluateAs("importedKey.type", "private"); |  | 
|  53         shouldEvaluateAs("importedKey.extractable", extractable); |  | 
|  54         shouldEvaluateAs("importedKey.algorithm.name", algorithmName); |  | 
|  55         shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL
    engthBits); |  | 
|  56         bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat
    a.publicExponent, importedKey.algorithm.publicExponent); |  | 
|  57         shouldBeUndefined("importedKey.algorithm.hash"); |  | 
|  58         shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); |  | 
|  59  |  | 
|  60         shouldNotBe("importedKey", "clonedKey"); |  | 
|  61  |  | 
|  62         shouldBeUndefined("clonedKey.extraProperty"); |  | 
|  63         shouldEvaluateAs("clonedKey.type", "private"); |  | 
|  64         shouldEvaluateAs("clonedKey.extractable", extractable); |  | 
|  65         shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); |  | 
|  66         shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLen
    gthBits); |  | 
|  67         bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData.
    publicExponent, clonedKey.algorithm.publicExponent); |  | 
|  68         shouldBeUndefined("clonedKey.algorithm.hash"); |  | 
|  69         shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); |  | 
|  70  |  | 
|  71         logSerializedKey(importedKey); |  | 
|  72  |  | 
|  73         if (extractable) |  | 
|  74             bytesShouldMatchHexString("Cloned key exported data", keyData.pkcs8,
     clonedKeyData); |  | 
|  75  |  | 
|  76         debug(""); |  | 
|  77     }); |  | 
|  78 } |  | 
|  79  |  | 
|  80 var lastPromise = Promise.resolve(null); |  | 
|  81  |  | 
|  82 kPossibleAlgorithms.forEach(function(algorithmName) { |  | 
|  83     kPossibleExtractable.forEach(function(extractable) { |  | 
|  84         kPossibleKeyUsages.forEach(function(keyUsages) { |  | 
|  85             kPossibleKeyData.forEach(function(keyData) { |  | 
|  86                   lastPromise = lastPromise.then(runTest.bind(null, algorithmNam
    e, extractable, keyUsages, keyData)); |  | 
|  87             }); |  | 
|  88         }); |  | 
|  89     }); |  | 
|  90 }); |  | 
|  91  |  | 
|  92 lastPromise.then(finishJSTest, failAndFinishJSTest); |  | 
|  93  |  | 
|  94 </script> |  | 
|  95  |  | 
|  96 </body> |  | 
|  97 </html> |  | 
| OLD | NEW |