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 structured cloning of EC private keys"); | 12 description("Tests structured cloning of EC private keys"); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 // Tests the 12 permutations of keys generated by: | 16 // ECDSA and ECDH support different key usages. Pick either sign or deriveBits d
epending on the algorithm. |
| 17 function signOrDeriveBits(algorithmName) { |
| 18 if (algorithmName == "ECDSA") |
| 19 return ['sign']; |
| 20 if (algorithmName == "ECDH") |
| 21 return ['deriveBits']; |
| 22 } |
| 23 |
| 24 // Tests the 24 permutations of keys generated by: |
17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
Curves | 25 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible
Curves |
18 // | 26 // |
19 // For practical reasons these tests are not exhaustive. | 27 // For practical reasons these tests are not exhaustive. |
20 | 28 |
21 var kPossibleAlgorithms = ['ECDSA']; | 29 var kPossibleAlgorithms = ['ECDSA', 'ECDH']; |
22 var kPossibleExtractable = [true, false]; | 30 var kPossibleExtractable = [true, false]; |
23 var kPossibleKeyUsages = [[], ['sign']]; | 31 var kPossibleKeyUsages = [[], signOrDeriveBits]; |
24 var kPossibleNamedCurves = ['P-256', 'P-384', 'P-521']; | 32 var kPossibleNamedCurves = ['P-256', 'P-384', 'P-521']; |
25 | 33 |
26 // A mapping from curve name, to PKCS8 data (hex-encoded) for a valid private ke
y. | 34 // A mapping from curve name, to PKCS8 data (hex-encoded) for a valid private ke
y. |
27 var kKeyDataForCurve = { | 35 var kKeyDataForCurve = { |
28 "P-256": "308187020100301306072A8648CE3D020106082A8648CE3D030107046D306B0201
0104201FE33950C5F461124AE992C2BDFDF1C73B1615F571BD567E60D19AA1F48CDF42A144034200
047C110C66DCFDA807F6E69E45DDB3C74F69A1484D203E8DC5ADA8E9A9DD7CB3C70DF448986E51BD
E5D1576F99901F9C2C6A806A47FD907643A72B835597EFC8C6", | 36 "P-256": "308187020100301306072A8648CE3D020106082A8648CE3D030107046D306B0201
0104201FE33950C5F461124AE992C2BDFDF1C73B1615F571BD567E60D19AA1F48CDF42A144034200
047C110C66DCFDA807F6E69E45DDB3C74F69A1484D203E8DC5ADA8E9A9DD7CB3C70DF448986E51BD
E5D1576F99901F9C2C6A806A47FD907643A72B835597EFC8C6", |
29 "P-384": "3081B6020100301006072A8648CE3D020106052B8104002204819E30819B020101
0430A492CE8FA90084C227E1A32F7974D39E9FF67A7E8705EC3419B35FB607582BEBD461E0B1520A
C76EC2DD4E9B63EBAE71A16403620004E55FEE6C49D8D523F5CE7BF9C0425CE4FF650708B7DE5CFB
095901523979A7F042602DB30854735369813B5C3F5EF86828F59CC5DC509892A988D38A8E2519DE
3D0C4FD0FBDB0993E38F18506C17606C5E24249246F1CE94983A5361C5BE983E", | 37 "P-384": "3081B6020100301006072A8648CE3D020106052B8104002204819E30819B020101
0430A492CE8FA90084C227E1A32F7974D39E9FF67A7E8705EC3419B35FB607582BEBD461E0B1520A
C76EC2DD4E9B63EBAE71A16403620004E55FEE6C49D8D523F5CE7BF9C0425CE4FF650708B7DE5CFB
095901523979A7F042602DB30854735369813B5C3F5EF86828F59CC5DC509892A988D38A8E2519DE
3D0C4FD0FBDB0993E38F18506C17606C5E24249246F1CE94983A5361C5BE983E", |
30 "P-521": "3081EE020100301006072A8648CE3D020106052B810400230481D63081D3020101
044201BD56BD106118EDA246155BD43B42B8E13F0A6E25DD3BB376026FAB4DC92B6157BC6DFEC2D1
5DD3D0CF2A39AA68494042AF48BA9601118DA82C6F2108A3A203AD74A181890381860004012FBCAE
FFA6A51F3EE4D3D2B51C5DEC6D7C726CA353FC014EA2BF7CFBB9B910D32CBFA6A00FE39B6CDB8946
F22775398B2E233C0CF144D78C8A7742B5C7A3BB5D23009CDEF823DD7BF9A79E8CCEACD2E4527C23
1D0AE5967AF0958E931D7DDCCF2805A3E618DC3039FEC9FEBBD33052FE4C0FEE98F033106064982D
88F4E03549D4A64D" | 38 "P-521": "3081EE020100301006072A8648CE3D020106052B810400230481D63081D3020101
044201BD56BD106118EDA246155BD43B42B8E13F0A6E25DD3BB376026FAB4DC92B6157BC6DFEC2D1
5DD3D0CF2A39AA68494042AF48BA9601118DA82C6F2108A3A203AD74A181890381860004012FBCAE
FFA6A51F3EE4D3D2B51C5DEC6D7C726CA353FC014EA2BF7CFBB9B910D32CBFA6A00FE39B6CDB8946
F22775398B2E233C0CF144D78C8A7742B5C7A3BB5D23009CDEF823DD7BF9A79E8CCEACD2E4527C23
1D0AE5967AF0958E931D7DDCCF2805A3E618DC3039FEC9FEBBD33052FE4C0FEE98F033106064982D
88F4E03549D4A64D" |
31 }; | 39 }; |
32 | 40 |
33 function runTest(algorithmName, namedCurve, extractable, keyUsages) | 41 function runTest(algorithmName, namedCurve, extractable, keyUsages) |
34 { | 42 { |
35 var keyDataHex = kKeyDataForCurve[namedCurve]; | 43 var keyDataHex = kKeyDataForCurve[namedCurve]; |
36 var importData = hexStringToUint8Array(keyDataHex); | 44 var importData = hexStringToUint8Array(keyDataHex); |
37 var importAlgorithm = { name: algorithmName, namedCurve: namedCurve }; | 45 var importAlgorithm = { name: algorithmName, namedCurve: namedCurve }; |
38 | 46 |
39 var results = {}; | 47 var results = {}; |
40 | 48 |
| 49 if (typeof keyUsages == "function") |
| 50 keyUsages = keyUsages(algorithmName); |
| 51 |
41 return crypto.subtle.importKey('pkcs8', importData, importAlgorithm, extract
able, keyUsages).then(function(importedKey) { | 52 return crypto.subtle.importKey('pkcs8', importData, importAlgorithm, extract
able, keyUsages).then(function(importedKey) { |
42 results.importedKey = importedKey; | 53 results.importedKey = importedKey; |
43 importedKey.extraProperty = 'hi'; | 54 importedKey.extraProperty = 'hi'; |
44 return cloneKey(importedKey); | 55 return cloneKey(importedKey); |
45 }).then(function(clonedKey) { | 56 }).then(function(clonedKey) { |
46 results.clonedKey = clonedKey; | 57 results.clonedKey = clonedKey; |
47 if (extractable) | 58 if (extractable) |
48 return crypto.subtle.exportKey('pkcs8', clonedKey); | 59 return crypto.subtle.exportKey('pkcs8', clonedKey); |
49 return null; | 60 return null; |
50 }).then(function(clonedKeyData) { | 61 }).then(function(clonedKeyData) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 }); | 98 }); |
88 }); | 99 }); |
89 }); | 100 }); |
90 | 101 |
91 lastPromise.then(finishJSTest, failAndFinishJSTest); | 102 lastPromise.then(finishJSTest, failAndFinishJSTest); |
92 | 103 |
93 </script> | 104 </script> |
94 | 105 |
95 </body> | 106 </body> |
96 </html> | 107 </html> |
OLD | NEW |