Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: LayoutTests/crypto/clone-ecKey-private.html

Issue 806913006: [WebCrypto] Move LayoutTests from crypto to crypto/subtle (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update path for deserialize legacy tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10
11 <script>
12 description("Tests structured cloning of EC private keys");
13
14 jsTestIsAsync = true;
15
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 12 permutations of keys generated by:
25 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible Curves
26 //
27 // For practical reasons these tests are not exhaustive.
28
29 var kPossibleAlgorithms = ['ECDSA', 'ECDH'];
30 var kPossibleExtractable = [true, false];
31 var kPossibleKeyUsages = [signOrDeriveBits];
32 var kPossibleNamedCurves = ['P-256', 'P-384', 'P-521'];
33
34 // A mapping from curve name, to PKCS8 data (hex-encoded) for a valid private ke y.
35 var kKeyDataForCurve = {
36 "P-256": "308187020100301306072A8648CE3D020106082A8648CE3D030107046D306B0201 0104201FE33950C5F461124AE992C2BDFDF1C73B1615F571BD567E60D19AA1F48CDF42A144034200 047C110C66DCFDA807F6E69E45DDB3C74F69A1484D203E8DC5ADA8E9A9DD7CB3C70DF448986E51BD E5D1576F99901F9C2C6A806A47FD907643A72B835597EFC8C6",
37 "P-384": "3081B6020100301006072A8648CE3D020106052B8104002204819E30819B020101 0430A492CE8FA90084C227E1A32F7974D39E9FF67A7E8705EC3419B35FB607582BEBD461E0B1520A C76EC2DD4E9B63EBAE71A16403620004E55FEE6C49D8D523F5CE7BF9C0425CE4FF650708B7DE5CFB 095901523979A7F042602DB30854735369813B5C3F5EF86828F59CC5DC509892A988D38A8E2519DE 3D0C4FD0FBDB0993E38F18506C17606C5E24249246F1CE94983A5361C5BE983E",
38 "P-521": "3081EE020100301006072A8648CE3D020106052B810400230481D63081D3020101 044201BD56BD106118EDA246155BD43B42B8E13F0A6E25DD3BB376026FAB4DC92B6157BC6DFEC2D1 5DD3D0CF2A39AA68494042AF48BA9601118DA82C6F2108A3A203AD74A181890381860004012FBCAE FFA6A51F3EE4D3D2B51C5DEC6D7C726CA353FC014EA2BF7CFBB9B910D32CBFA6A00FE39B6CDB8946 F22775398B2E233C0CF144D78C8A7742B5C7A3BB5D23009CDEF823DD7BF9A79E8CCEACD2E4527C23 1D0AE5967AF0958E931D7DDCCF2805A3E618DC3039FEC9FEBBD33052FE4C0FEE98F033106064982D 88F4E03549D4A64D"
39 };
40
41 function runTest(algorithmName, namedCurve, extractable, keyUsages)
42 {
43 var keyDataHex = kKeyDataForCurve[namedCurve];
44 var importData = hexStringToUint8Array(keyDataHex);
45 var importAlgorithm = { name: algorithmName, namedCurve: namedCurve };
46
47 var results = {};
48
49 if (typeof keyUsages == "function")
50 keyUsages = keyUsages(algorithmName);
51
52 return crypto.subtle.importKey('pkcs8', importData, importAlgorithm, extract able, keyUsages).then(function(importedKey) {
53 results.importedKey = importedKey;
54 importedKey.extraProperty = 'hi';
55 return cloneKey(importedKey);
56 }).then(function(clonedKey) {
57 results.clonedKey = clonedKey;
58 if (extractable)
59 return crypto.subtle.exportKey('pkcs8', clonedKey);
60 return null;
61 }).then(function(clonedKeyData) {
62 importedKey = results.importedKey;
63 clonedKey = results.clonedKey;
64
65 shouldEvaluateAs("importedKey.extraProperty", "hi");
66 shouldEvaluateAs("importedKey.type", "private");
67 shouldEvaluateAs("importedKey.extractable", extractable);
68 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
69 shouldEvaluateAs("importedKey.algorithm.namedCurve", namedCurve);
70 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
71
72 shouldNotBe("importedKey", "clonedKey");
73
74 shouldBeUndefined("clonedKey.extraProperty");
75 shouldEvaluateAs("clonedKey.type", "private");
76 shouldEvaluateAs("clonedKey.extractable", extractable);
77 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
78 shouldEvaluateAs("clonedKey.algorithm.namedCurve", namedCurve);
79 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
80
81 logSerializedKey(importedKey);
82
83 if (extractable)
84 bytesShouldMatchHexString("Cloned key exported data", keyDataHex, cl onedKeyData);
85
86 debug("");
87 });
88 }
89
90 var lastPromise = Promise.resolve(null);
91
92 kPossibleAlgorithms.forEach(function(algorithmName) {
93 kPossibleExtractable.forEach(function(extractable) {
94 kPossibleKeyUsages.forEach(function(keyUsages) {
95 kPossibleNamedCurves.forEach(function(namedCurve) {
96 lastPromise = lastPromise.then(runTest.bind(null, algorithmNam e, namedCurve, extractable, keyUsages));
97 });
98 });
99 });
100 });
101
102 lastPromise.then(finishJSTest, failAndFinishJSTest);
103
104 </script>
105
106 </body>
107 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/clone-aesKey-expected.txt ('k') | LayoutTests/crypto/clone-ecKey-private-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698