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

Side by Side Diff: LayoutTests/crypto/importKey.html

Issue 179353002: [webcrypto] Add the KeyAlgorithm interface. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase yet again (another conflict) 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 | « LayoutTests/crypto/generateKey-expected.txt ('k') | LayoutTests/crypto/importKey-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 </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 cypto.subtle.importKey."); 12 description("Tests cypto.subtle.importKey.");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 aesCbc = {name: 'aes-cbc'}; 16 aesCbc = {name: 'aes-cbc'};
17 17
18 Promise.resolve(null).then(function() { 18 Promise.resolve(null).then(function() {
19 keyFormat = "raw"; 19 keyFormat = "raw";
20 data = asciiToUint8Array("raw bytes for key"); 20 data = asciiToUint8Array("raw bytes for key");
21 algorithm = { name: 'hmac', hash: { name: 'sha-256' } }; 21 algorithm = { name: 'hmac', hash: { name: 'sha-256' } };
22 extractable = true; 22 extractable = true;
23 // Note there are duplicates 23 // Note there are duplicates
24 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign']; 24 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign'];
25 25
26 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 26 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
27 }).then(function(result) { 27 }).then(function(result) {
28 key = result; 28 key = result;
29 shouldBe("key.type", "'secret'") 29 shouldBe("key.type", "'secret'");
30 shouldBe("key.extractable", "true") 30 shouldBe("key.extractable", "true");
31 shouldBe("key.algorithm.name", "'HMAC'") 31 shouldBe("key.algorithm.name", "'HMAC'");
32 shouldBe("key.usages.join(',')", "'encrypt,sign'") 32 shouldBe("key.algorithm.hash.name", "'SHA-256'");
33 shouldBe("key.usages.join(',')", "'encrypt,sign'");
33 34
34 // Same test as above, but with an keyUsages, and AES-CBC. 35 // Same test as above, but with an keyUsages, and AES-CBC.
35 keyFormat = "raw"; 36 keyFormat = "raw";
36 data = asciiToUint8Array("16 bytes of key!"); 37 data = asciiToUint8Array("16 bytes of key!");
37 algorithm = aesCbc; 38 algorithm = aesCbc;
38 extractable = true; 39 extractable = true;
39 keyUsages = []; 40 keyUsages = [];
40 41
41 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 42 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
42 }).then(function(result) { 43 }).then(function(result) {
43 key = result; 44 key = result;
44 shouldBe("key.type", "'secret'") 45 shouldBe("key.type", "'secret'");
45 shouldBe("key.extractable", "true") 46 shouldBe("key.extractable", "true");
46 shouldBe("key.algorithm.name", "'AES-CBC'") 47 shouldBe("key.algorithm.name", "'AES-CBC'");
47 shouldBe("key.usages.join(',')", "''") 48 shouldBe("key.algorithm.length", "128");
49 shouldBe("key.usages.join(',')", "''");
48 50
49 // Same test as above, but with extractable = false. 51 // Same test as above, but with extractable = false.
50 keyFormat = "raw"; 52 keyFormat = "raw";
51 data = asciiToUint8Array("16 bytes of key!"); 53 data = asciiToUint8Array("16 bytes of key!");
52 algorithm = aesCbc; 54 algorithm = aesCbc;
53 extractable = false; 55 extractable = false;
54 keyUsages = []; 56 keyUsages = [];
55 57
56 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 58 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
57 }).then(function(result) { 59 }).then(function(result) {
58 key = result; 60 key = result;
59 shouldBe("key.type", "'secret'") 61 shouldBe("key.type", "'secret'");
60 shouldBe("key.extractable", "false") 62 shouldBe("key.extractable", "false");
61 shouldBe("key.algorithm.name", "'AES-CBC'") 63 shouldBe("key.algorithm.name", "'AES-CBC'");
62 shouldBe("key.usages.join(',')", "''") 64 shouldBe("key.algorithm.length", "128");
65 shouldBe("key.usages.join(',')", "''");
63 66
64 // Same test as above, but with keyFormat = spki 67 // Same test as above, but with keyFormat = spki
65 keyFormat = "spki"; 68 keyFormat = "spki";
66 data = asciiToUint8Array("16 bytes of key!"); 69 data = asciiToUint8Array("16 bytes of key!");
67 algorithm = aesCbc; 70 algorithm = aesCbc;
68 extractable = false; 71 extractable = false;
69 keyUsages = []; 72 keyUsages = [];
70 73
71 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 74 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
72 }).then(undefined, function(result) { 75 }).then(undefined, function(result) {
73 // TODO(eroman): Only "raw" key format is supported at the moment.
74 debug("rejected with " + result); 76 debug("rejected with " + result);
75 77
78 // Import an spki formatted public key
79 keyFormat = "spki";
80 data = hexStringToUint8Array(kPublicKeySpkiDerHex);
81 algorithm = {name: 'RsasSA-pKCS1-v1_5', hash: {name: 'sha-1'}};
82 extractable = false;
83 keyUsages = [];
84
85 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
86 }).then(function(result) {
87 key = result;
88 shouldBe("key.type", "'public'");
89 // FIXME: Enable this once updated.
90 //shouldBe("key.extractable", "true");
91 shouldBe("key.algorithm.name", "'RSASSA-PKCS1-v1_5'");
92 shouldBe("key.algorithm.hash.name", '"SHA-1"');
93 shouldBe("key.algorithm.modulusLength", '1024');
94 bytesShouldMatchHexString("key.algorithm.publicExponent", "010001", key.algo rithm.publicExponent);
95 shouldBe("key.usages.join(',')", "''");
96
97 // Import a pkcs8 formatted private key
98 keyFormat = "pkcs8";
99 data = hexStringToUint8Array(kPrivateKeyPkcs8DerHex);
100 algorithm = {name: 'RsasSA-pKCS1-v1_5', hash: {name: 'sha-1'}};
101 extractable = false;
102 keyUsages = [];
103
104 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
105 }).then(function(result) {
106 key = result;
107 shouldBe("key.type", "'private'");
108 shouldBe("key.extractable", "false");
109 shouldBe("key.algorithm.name", "'RSASSA-PKCS1-v1_5'");
110 shouldBe("key.algorithm.hash.name", '"SHA-1"');
111 shouldBe("key.algorithm.modulusLength", '1024');
112 bytesShouldMatchHexString("key.algorithm.publicExponent", "010001", key.algo rithm.publicExponent);
113 shouldBe("key.usages.join(',')", "''")
114
76 // Import a "raw" key without specifying the algorithm. 115 // Import a "raw" key without specifying the algorithm.
77 keyFormat = "raw"; 116 keyFormat = "raw";
78 data = asciiToUint8Array("16 bytes of key!"); 117 data = asciiToUint8Array("16 bytes of key!");
79 algorithm = null; 118 algorithm = null;
80 extractable = false; 119 extractable = false;
81 keyUsages = []; 120 keyUsages = [];
82 121
83 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 122 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
84 }).then(undefined, function(result) { 123 }).then(undefined, function(result) {
85 debug("rejected with " + result); 124 debug("rejected with " + result);
(...skipping 26 matching lines...) Expand all
112 shouldRejectPromiseWithNull("crypto.subtle.importKey(keyFormat, data, {name: 'hmac'}, extractable, keyUsages)"); 151 shouldRejectPromiseWithNull("crypto.subtle.importKey(keyFormat, data, {name: 'hmac'}, extractable, keyUsages)");
113 152
114 // SHA-1 doesn't support the importKey operation. 153 // SHA-1 doesn't support the importKey operation.
115 shouldRejectPromiseWithNull("crypto.subtle.importKey(keyFormat, data, {name: 'sha-1'}, extractable, keyUsages)"); 154 shouldRejectPromiseWithNull("crypto.subtle.importKey(keyFormat, data, {name: 'sha-1'}, extractable, keyUsages)");
116 }).then(finishJSTest, failAndFinishJSTest); 155 }).then(finishJSTest, failAndFinishJSTest);
117 156
118 </script> 157 </script>
119 158
120 </body> 159 </body>
121 </html> 160 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/generateKey-expected.txt ('k') | LayoutTests/crypto/importKey-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698