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

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

Issue 210693002: [webcrypto] Add structured clone tests for RSA private keys. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months 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
« no previous file with comments | « no previous file | LayoutTests/crypto/clone-rsaHashedKey-private-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 6 <script src="resources/keys.js"></script>
7 </head> 7 </head>
8 <body> 8 <body>
9 <p id="description"></p> 9 <p id="description"></p>
10 <div id="console"></div> 10 <div id="console"></div>
11 11
12 <script> 12 <script>
13 description("Tests structured cloning of RSA keys (with a hash)"); 13 description("Tests structured cloning of RSA private keys (with a hash)");
14 14
15 jsTestIsAsync = true; 15 jsTestIsAsync = true;
16 16
17 // Tests the 48 permutations of keys generated by: 17 // Tests the 48 permutations of keys generated by:
18 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData x kPossibleHashAlgorithms 18 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData x kPossibleHashAlgorithms
19 // 19 //
20 // For practical reasons these tests are not exhaustive. 20 // For practical reasons these tests are not exhaustive.
21 21
22 var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5']; 22 var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5'];
23 var kPossibleExtractable = [true, false]; 23 var kPossibleExtractable = [true, false];
24 var kPossibleKeyUsages = [[], ['sign'], ['verify'], ['sign', 'verify']]; 24 var kPossibleKeyUsages = [[], ['sign'], ['verify'], ['sign', 'verify']];
25 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; 25 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
26 26
27 var kPossibleKeyData = [ 27 var kPossibleKeyData = [
28 kKeyData.rsa2, 28 kKeyData.rsa1,
29 kKeyData.rsa3 29 kKeyData.rsa4
30 ]; 30 ];
31 31
32 function runTest(algorithmName, hashName, extractable, keyUsages, keyData) 32 function runTest(algorithmName, hashName, extractable, keyUsages, keyData)
33 { 33 {
34 var importData = hexStringToUint8Array(keyData.spki); 34 var importData = hexStringToUint8Array(keyData.pkcs8);
35 var importAlgorithm = { name: algorithmName, hash: {name: hashName} }; 35 var importAlgorithm = { name: algorithmName, hash: {name: hashName} };
36 36
37 var results = {}; 37 var results = {};
38 38
39 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) { 39 return crypto.subtle.importKey('pkcs8', importData, importAlgorithm, extract able, keyUsages).then(function(importedKey) {
40 results.importedKey = importedKey; 40 results.importedKey = importedKey;
41 importedKey.extraProperty = 'hi'; 41 importedKey.extraProperty = 'hi';
42 return cloneKey(importedKey); 42 return cloneKey(importedKey);
43 }).then(function(clonedKey) { 43 }).then(function(clonedKey) {
44 results.clonedKey = clonedKey; 44 results.clonedKey = clonedKey;
45 if (extractable) 45 if (extractable)
46 return crypto.subtle.exportKey('spki', clonedKey); 46 return crypto.subtle.exportKey('pkcs8', clonedKey);
47 return null; 47 return null;
48 }).then(function(clonedKeyData) { 48 }).then(function(clonedKeyData) {
49 importedKey = results.importedKey; 49 importedKey = results.importedKey;
50 clonedKey = results.clonedKey; 50 clonedKey = results.clonedKey;
51 51
52 shouldEvaluateAs("importedKey.extraProperty", "hi"); 52 shouldEvaluateAs("importedKey.extraProperty", "hi");
53 shouldEvaluateAs("importedKey.type", "public"); 53 shouldEvaluateAs("importedKey.type", "private");
54 shouldEvaluateAs("importedKey.extractable", extractable); 54 shouldEvaluateAs("importedKey.extractable", extractable);
55 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); 55 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
56 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL engthBits); 56 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL engthBits);
57 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat a.publicExponent, importedKey.algorithm.publicExponent); 57 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat a.publicExponent, importedKey.algorithm.publicExponent);
58 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName); 58 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); 59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
60 60
61 shouldBeTrue("importedKey != clonedKey"); 61 shouldBeTrue("importedKey != clonedKey");
62 62
63 shouldBeUndefined("clonedKey.extraProperty"); 63 shouldBeUndefined("clonedKey.extraProperty");
64 shouldEvaluateAs("clonedKey.type", "public"); 64 shouldEvaluateAs("clonedKey.type", "private");
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.modulusLength", keyData.modulusLen gthBits);
68 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData. publicExponent, clonedKey.algorithm.publicExponent); 68 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData. publicExponent, clonedKey.algorithm.publicExponent);
69 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName); 69 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
70 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); 70 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
71 71
72 logSerializedKey(importedKey); 72 logSerializedKey(importedKey);
73 73
74 if (extractable) 74 if (extractable)
75 bytesShouldMatchHexString("Cloned key exported data", keyData.spki, clonedKeyData); 75 bytesShouldMatchHexString("Cloned key exported data", keyData.pkcs8, clonedKeyData);
76 76
77 debug(""); 77 debug("");
78 }); 78 });
79 } 79 }
80 80
81 var lastPromise = Promise.resolve(null); 81 var lastPromise = Promise.resolve(null);
82 82
83 kPossibleAlgorithms.forEach(function(algorithmName) { 83 kPossibleAlgorithms.forEach(function(algorithmName) {
84 kPossibleExtractable.forEach(function(extractable) { 84 kPossibleExtractable.forEach(function(extractable) {
85 kPossibleKeyUsages.forEach(function(keyUsages) { 85 kPossibleKeyUsages.forEach(function(keyUsages) {
86 kPossibleKeyData.forEach(function(keyData) { 86 kPossibleKeyData.forEach(function(keyData) {
87 kPossibleHashAlgorithms.forEach(function(hashName) { 87 kPossibleHashAlgorithms.forEach(function(hashName) {
88 lastPromise = lastPromise.then(runTest.bind(null, algorithmN ame, hashName, extractable, keyUsages, keyData)); 88 lastPromise = lastPromise.then(runTest.bind(null, algorithmN ame, hashName, extractable, keyUsages, keyData));
89 }); 89 });
90 }); 90 });
91 }); 91 });
92 }); 92 });
93 }); 93 });
94 94
95 lastPromise.then(finishJSTest, failAndFinishJSTest); 95 lastPromise.then(finishJSTest, failAndFinishJSTest);
96 96
97 </script> 97 </script>
98 98
99 </body> 99 </body>
100 </html> 100 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/crypto/clone-rsaHashedKey-private-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698