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

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

Issue 707753002: WebCrypto: Add LayoutTests for ECDSA. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase onto master Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 <script src="resources/keys.js"></script>
7 </head> 6 </head>
8 <body> 7 <body>
9 <p id="description"></p> 8 <p id="description"></p>
10 <div id="console"></div> 9 <div id="console"></div>
11 10
12 <script> 11 <script>
13 description("Tests structured cloning of RSA public keys (with a hash)"); 12 description("Tests structured cloning of EC public keys");
14 13
15 jsTestIsAsync = true; 14 jsTestIsAsync = true;
16 15
17 // Tests the 12 permutations of keys generated by: 16 // Tests the 12 permutations of keys generated by:
18 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData x kPossibleHashAlgorithms 17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible Curves
19 // 18 //
20 // For practical reasons these tests are not exhaustive. 19 // For practical reasons these tests are not exhaustive.
21 20
22 var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5']; 21 var kPossibleAlgorithms = ['ECDSA'];
23 var kPossibleExtractable = [true, false]; 22 var kPossibleExtractable = [true, false];
24 var kPossibleKeyUsages = [[], ['verify']]; 23 var kPossibleKeyUsages = [[], ['verify']];
25 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; 24 var kPossibleNamedCurves = ['P-256', 'P-384', 'P-521'];
26 25
27 var kPossibleKeyData = [ 26 // A mapping from curve name, to SPKI data (hex-encoded) for a valid public key.
28 kKeyData.rsa2, 27 var kKeyDataForCurve = {
29 kKeyData.rsa3 28 "P-256": "3059301306072A8648CE3D020106082A8648CE3D030107034200049CB0CF69303D AFC761D4E4687B4ECF039E6D34AB964AF80810D8D558A4A8D6F72D51233A1788920A86EE08A1962C 79EFA317FB7879E297DAD2146DB995FA1C78",
30 ]; 29 "P-384": "3076301006072A8648CE3D020106052B81040022036200040874A2E0B8FF448F0E 54321E27F4F1E64D064CDEB7D26F458C32E930120F4E57DC85C2693F977EED4A8ECC8DB981B4D91F 69446DF4F4C6F5DE19003F45F891D0EBCD2FFFDB5C81C040E8D6994C43C7FEEDB98A4A31EDFB35E8 9A30013C3B9267",
30 "P-521": "30819B301006072A8648CE3D020106052B81040023038186000400F50A08703250 C15F043C8C46E99783435245CF98F4F2694B0E2F8D029A514DD6F0B086D4ED892000CD5590107AAE 69C4C0A7A95F7CF74E5770A07D5DB55BCE4AB400F2C770BAB8B9BE4CDB6ECD3DC26C698DA0D2599C EBF3D904F7F9CA3A55E64731810D73CD317264E50BABA4BC2860857E16D6CBB79501BC9E3A32BD17 2EA8A71DEE"
31 };
31 32
32 function runTest(algorithmName, hashName, extractable, keyUsages, keyData) 33 function runTest(algorithmName, namedCurve, extractable, keyUsages)
33 { 34 {
34 var importData = hexStringToUint8Array(keyData.spki); 35 var keyDataHex = kKeyDataForCurve[namedCurve];
35 var importAlgorithm = { name: algorithmName, hash: {name: hashName} }; 36 var importData = hexStringToUint8Array(keyDataHex);
37 var importAlgorithm = { name: algorithmName, namedCurve: namedCurve };
36 38
37 var results = {}; 39 var results = {};
38 40
39 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) { 41 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) {
40 results.importedKey = importedKey; 42 results.importedKey = importedKey;
41 importedKey.extraProperty = 'hi'; 43 importedKey.extraProperty = 'hi';
42 return cloneKey(importedKey); 44 return cloneKey(importedKey);
43 }).then(function(clonedKey) { 45 }).then(function(clonedKey) {
44 results.clonedKey = clonedKey; 46 results.clonedKey = clonedKey;
45 if (extractable) 47 if (extractable)
46 return crypto.subtle.exportKey('spki', clonedKey); 48 return crypto.subtle.exportKey('spki', clonedKey);
47 return null; 49 return null;
48 }).then(function(clonedKeyData) { 50 }).then(function(clonedKeyData) {
49 importedKey = results.importedKey; 51 importedKey = results.importedKey;
50 clonedKey = results.clonedKey; 52 clonedKey = results.clonedKey;
51 53
52 shouldEvaluateAs("importedKey.extraProperty", "hi"); 54 shouldEvaluateAs("importedKey.extraProperty", "hi");
53 shouldEvaluateAs("importedKey.type", "public"); 55 shouldEvaluateAs("importedKey.type", "public");
54 shouldEvaluateAs("importedKey.extractable", extractable); 56 shouldEvaluateAs("importedKey.extractable", extractable);
55 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); 57 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
56 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL engthBits); 58 shouldEvaluateAs("importedKey.algorithm.namedCurve", namedCurve);
57 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat a.publicExponent, importedKey.algorithm.publicExponent);
58 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); 59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
60 60
61 shouldNotBe("importedKey", "clonedKey"); 61 shouldNotBe("importedKey", "clonedKey");
62 62
63 shouldBeUndefined("clonedKey.extraProperty"); 63 shouldBeUndefined("clonedKey.extraProperty");
64 shouldEvaluateAs("clonedKey.type", "public"); 64 shouldEvaluateAs("clonedKey.type", "public");
65 shouldEvaluateAs("clonedKey.extractable", extractable); 65 shouldEvaluateAs("clonedKey.extractable", extractable);
66 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); 66 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
67 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLen gthBits); 67 shouldEvaluateAs("clonedKey.algorithm.namedCurve", namedCurve);
68 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData. publicExponent, clonedKey.algorithm.publicExponent);
69 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
70 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); 68 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
71 69
72 logSerializedKey(importedKey); 70 logSerializedKey(importedKey);
73 71
74 if (extractable) 72 if (extractable)
75 bytesShouldMatchHexString("Cloned key exported data", keyData.spki, clonedKeyData); 73 bytesShouldMatchHexString("Cloned key exported data", keyDataHex, cl onedKeyData);
76 74
77 debug(""); 75 debug("");
78 }); 76 });
79 } 77 }
80 78
81 var lastPromise = Promise.resolve(null); 79 var lastPromise = Promise.resolve(null);
82 80
83 kPossibleAlgorithms.forEach(function(algorithmName) { 81 kPossibleAlgorithms.forEach(function(algorithmName) {
84 kPossibleExtractable.forEach(function(extractable) { 82 kPossibleExtractable.forEach(function(extractable) {
85 kPossibleKeyUsages.forEach(function(keyUsages) { 83 kPossibleKeyUsages.forEach(function(keyUsages) {
86 kPossibleKeyData.forEach(function(keyData) { 84 kPossibleNamedCurves.forEach(function(namedCurve) {
87 kPossibleHashAlgorithms.forEach(function(hashName) { 85 lastPromise = lastPromise.then(runTest.bind(null, algorithmNam e, namedCurve, extractable, keyUsages));
88 lastPromise = lastPromise.then(runTest.bind(null, algorithmN ame, hashName, extractable, keyUsages, keyData)); 86 });
89 });
90 });
91 }); 87 });
92 }); 88 });
93 }); 89 });
94 90
95 lastPromise.then(finishJSTest, failAndFinishJSTest); 91 lastPromise.then(finishJSTest, failAndFinishJSTest);
96 92
97 </script> 93 </script>
98 94
99 </body> 95 </body>
100 </html> 96 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698