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

Side by Side Diff: chrome/test/data/extensions/api_test/platform_keys/basic.js

Issue 884073002: Implement chrome.platformKeys.getKeyPair(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_impl2
Patch Set: Rebased. Created 5 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1); 7 var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1);
8 8
9 var assertEq = chrome.test.assertEq; 9 var assertEq = chrome.test.assertEq;
10 var assertTrue = chrome.test.assertTrue; 10 var assertTrue = chrome.test.assertTrue;
11 var assertThrows = chrome.test.assertThrows; 11 var assertThrows = chrome.test.assertThrows;
12 var fail = chrome.test.fail; 12 var fail = chrome.test.fail;
13 var succeed = chrome.test.succeed; 13 var succeed = chrome.test.succeed;
14 var callbackPass = chrome.test.callbackPass; 14 var callbackPass = chrome.test.callbackPass;
15 var callbackFail= chrome.test.callbackFail; 15 var callbackFail= chrome.test.callbackFail;
16 16
17 // A X.509 client certificate in DER encoding. 17 // Each value is the path to a file in this extension's folder that will be
18 var clientCert1 = new Uint8Array([ 18 // loaded and replaced by a Uint8Array in the setUp() function below.
19 0x30, 0x82, 0x02, 0xd2, 0x30, 0x82, 0x01, 0xba, 0xa0, 0x03, 0x02, 0x01, 19 var data = {
20 0x02, 0x02, 0x02, 0x10, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 20 // X.509 client certificates in DER encoding.
21 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d, 21 // openssl x509 -in net/data/ssl/certificates/client_1.pem -outform DER -out
22 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x04, 0x42, 0x20, 0x43, 22 // client_1.der
23 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x38, 0x31, 0x34, 0x30, 23 client_1: 'client_1.der',
24 0x32, 0x34, 0x36, 0x33, 0x37, 0x5a, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x38,
25 0x31, 0x31, 0x30, 0x32, 0x34, 0x36, 0x33, 0x37, 0x5a, 0x30, 0x18, 0x31,
26 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0d, 0x43, 0x6c,
27 0x69, 0x65, 0x6e, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x41, 0x30,
28 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
29 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30,
30 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xd5, 0xdf, 0xba, 0x34,
31 0xcb, 0xc2, 0x03, 0xb5, 0x37, 0x7a, 0x61, 0x89, 0x1a, 0xb5, 0x1a, 0xb9,
32 0x27, 0x7f, 0xa9, 0x2c, 0xba, 0xa1, 0x36, 0xac, 0x83, 0x6d, 0xb8, 0x45,
33 0x9e, 0x35, 0x82, 0xa4, 0xde, 0xa3, 0x69, 0x38, 0x25, 0x84, 0x57, 0x00,
34 0x8c, 0x41, 0x84, 0x86, 0x6d, 0x78, 0x41, 0xd4, 0x10, 0x99, 0x1b, 0x15,
35 0x18, 0xa6, 0x04, 0x2f, 0x92, 0xa0, 0x1c, 0x29, 0xc3, 0xe0, 0x5d, 0xe2,
36 0x90, 0x11, 0x2c, 0xfa, 0xac, 0x18, 0x0d, 0xfe, 0x5e, 0x8d, 0x5c, 0x5a,
37 0x01, 0x4a, 0xf7, 0x2c, 0xc9, 0x6e, 0x39, 0x8e, 0x14, 0x30, 0xd9, 0xfc,
38 0xf6, 0x6a, 0xee, 0x9d, 0xa3, 0xba, 0x23, 0xfe, 0x5d, 0xaa, 0x2f, 0x96,
39 0x07, 0x65, 0x38, 0xca, 0xa4, 0x3c, 0xd2, 0x93, 0x21, 0xb0, 0xb6, 0xdb,
40 0xfb, 0x40, 0x12, 0x00, 0x01, 0x99, 0x30, 0x41, 0x67, 0xe2, 0x2f, 0x65,
41 0x63, 0x71, 0xaa, 0xa6, 0xef, 0x45, 0x23, 0x05, 0x8b, 0xb4, 0x28, 0x6c,
42 0x35, 0xbf, 0x41, 0x73, 0x61, 0xf1, 0x9e, 0x77, 0x8c, 0xa7, 0x51, 0xcf,
43 0xc7, 0x51, 0x63, 0xc7, 0x00, 0xab, 0x4e, 0xa3, 0xe5, 0x8f, 0xfe, 0x3c,
44 0x45, 0xfa, 0x9e, 0xd2, 0x29, 0xbc, 0x59, 0x94, 0x7d, 0x14, 0xc9, 0x36,
45 0xdf, 0xcd, 0x0a, 0xb5, 0x9f, 0xbf, 0xac, 0xfd, 0x1d, 0x2b, 0x6d, 0xe5,
46 0x13, 0x30, 0x14, 0x71, 0xde, 0x77, 0xdf, 0x83, 0xf3, 0x6d, 0x2c, 0xcd,
47 0x16, 0xc0, 0xa5, 0xdc, 0xf2, 0x1f, 0x65, 0x86, 0x37, 0x91, 0x2f, 0x31,
48 0x66, 0x7e, 0x1a, 0x4b, 0x42, 0xb7, 0x29, 0xe1, 0xcd, 0x1d, 0xc9, 0x72,
49 0x0e, 0x65, 0x8e, 0xa9, 0x4c, 0x74, 0x2e, 0x90, 0xb7, 0xe0, 0x91, 0x0c,
50 0xe8, 0xfe, 0x92, 0x26, 0xa7, 0x17, 0x9a, 0xb6, 0x25, 0x7f, 0x66, 0x89,
51 0x2f, 0xbf, 0x54, 0xa7, 0x51, 0x4c, 0xe6, 0x8f, 0x4d, 0x34, 0xa1, 0xc3,
52 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x2f, 0x30, 0x2d, 0x30, 0x0c, 0x06,
53 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30,
54 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08,
55 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06,
56 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
57 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01,
58 0x01, 0x00, 0x6d, 0x3e, 0xc3, 0xd4, 0xc8, 0xd1, 0xfc, 0xec, 0x0e, 0xd3,
59 0xca, 0xc8, 0x4c, 0x8d, 0xfe, 0xab, 0x51, 0xfb, 0x1c, 0xa4, 0xf6, 0x3c,
60 0x13, 0x07, 0x76, 0x58, 0x7f, 0x61, 0x34, 0x9c, 0xb6, 0xfd, 0x9a, 0xc5,
61 0x7e, 0xc7, 0xb7, 0xe0, 0x89, 0xfb, 0xc5, 0x67, 0x76, 0x75, 0xee, 0xab,
62 0xd9, 0xbf, 0xfb, 0xaa, 0x3e, 0xe9, 0x5a, 0x4a, 0xc1, 0x83, 0xc3, 0xc6,
63 0xa0, 0x01, 0x8e, 0xb1, 0xf8, 0x0d, 0x08, 0x9a, 0x26, 0xa7, 0xb7, 0x3c,
64 0x19, 0xb0, 0x76, 0x77, 0x57, 0x03, 0xc3, 0x61, 0xcf, 0x56, 0x7e, 0x59,
65 0x25, 0x10, 0x11, 0xbb, 0x4d, 0x20, 0xd5, 0x49, 0x51, 0x0d, 0xc9, 0x19,
66 0xbb, 0x50, 0x4e, 0xd1, 0xf7, 0x62, 0x21, 0x84, 0x02, 0x9b, 0x9b, 0xfa,
67 0xca, 0xef, 0xde, 0x7f, 0x6c, 0xa0, 0x1e, 0xf6, 0x50, 0x87, 0x26, 0xeb,
68 0x2a, 0xfd, 0xe3, 0x69, 0x4b, 0x12, 0x10, 0x9b, 0xe3, 0xf5, 0x96, 0x33,
69 0x23, 0xb5, 0x06, 0x31, 0x42, 0x26, 0x8c, 0x07, 0xcc, 0x0a, 0x19, 0x4a,
70 0xa5, 0x92, 0x44, 0xa3, 0x22, 0x5a, 0x69, 0xad, 0x4a, 0x96, 0x61, 0xb7,
71 0xa8, 0x6f, 0xbe, 0x31, 0x30, 0xb2, 0x1d, 0xee, 0x5a, 0x21, 0x87, 0xa7,
72 0x33, 0x51, 0x02, 0xe4, 0x24, 0x86, 0xab, 0x8e, 0xaa, 0x94, 0xf4, 0x25,
73 0x6e, 0x3f, 0x53, 0x42, 0xce, 0x12, 0x91, 0x99, 0x23, 0x52, 0x1d, 0xba,
74 0xdf, 0x59, 0x11, 0x0f, 0x34, 0x2e, 0x8e, 0x58, 0xac, 0xdf, 0x6b, 0x1a,
75 0x08, 0xa3, 0x03, 0x46, 0x0f, 0xc0, 0x11, 0x72, 0x66, 0xc4, 0xe8, 0x92,
76 0x5a, 0x20, 0x06, 0xfe, 0xe2, 0x2b, 0xe9, 0xb3, 0x9b, 0x70, 0x1a, 0xb9,
77 0x53, 0x21, 0xad, 0xd7, 0x5f, 0xa1, 0xab, 0x26, 0x97, 0x17, 0x0b, 0xba,
78 0xb0, 0x8b, 0x2d, 0xdb, 0x0c, 0x4e, 0xed, 0x75, 0x8b, 0x72, 0x46, 0xb0,
79 0x6b, 0x23, 0x11, 0xba, 0x1e, 0x03
80 ]);
81 24
82 // The distinguished name of the CA that issued clientCert1 in DER encoding. 25 // openssl x509 -in net/data/ssl/certificates/client_2.pem -outform DER -out
83 var ca1DistinguishedNameDER = new Uint8Array([ 26 // client_2.der
84 0x30, 0x0f, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 27 client_2: 'client_2.der',
85 0x04, 0x42, 0x20, 0x43, 0x41
86 ]);
87 28
88 // A X.509 client certificate in DER encoding. 29 // The public key of client_1 as Subject Public Key Info in DER encoding.
89 var clientCert2 = new Uint8Array([ 30 // openssl rsa -in net/data/ssl/certificates/client_1.key -inform PEM -out
90 0x30, 0x82, 0x02, 0xd2, 0x30, 0x82, 0x01, 0xba, 0xa0, 0x03, 0x02, 0x01, 31 // pubkey.der -pubout -outform DER
91 0x02, 0x02, 0x02, 0x10, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 32 client_1_spki: 'client_1_spki.der',
92 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d, 33
93 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x04, 0x45, 0x20, 0x43, 34 // The distinguished name of the CA that issued client_1 in DER encoding.
94 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x38, 0x31, 0x34, 0x30, 35 // openssl asn1parse -in client_1.der -inform DER -strparse 32 -out
95 0x32, 0x34, 0x36, 0x33, 0x37, 0x5a, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x38, 36 // client_1_issuer_dn.der
96 0x31, 0x31, 0x30, 0x32, 0x34, 0x36, 0x33, 0x37, 0x5a, 0x30, 0x18, 0x31, 37 client_1_issuer_dn: 'client_1_issuer_dn.der',
97 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0d, 0x43, 0x6c, 38
98 0x69, 0x65, 0x6e, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x44, 0x30, 39 // echo -n "hello world" > data
99 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 40 raw_data: 'data',
100 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 41
101 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe7, 0xb2, 0x44, 0x6e, 42 // openssl rsautl -inkey net/data/ssl/certificates/client_1.key -sign -in
102 0xf9, 0xef, 0x0a, 0x10, 0xd3, 0xeb, 0x66, 0x39, 0x09, 0x93, 0x96, 0x40, 43 // data -pkcs -out signature_nohash_pkcs
103 0x22, 0x3f, 0xe4, 0xbc, 0xfb, 0x89, 0xca, 0x55, 0x20, 0x71, 0x8e, 0x04, 44 signature_nohash_pkcs: 'signature_nohash_pkcs',
104 0x18, 0x82, 0xa4, 0x36, 0x18, 0x85, 0x26, 0x3f, 0x8b, 0x26, 0xc0, 0x44, 45
105 0x02, 0x8b, 0x8c, 0xaf, 0xf7, 0xab, 0x72, 0x0a, 0x8f, 0x33, 0x42, 0x9f, 46 // openssl dgst -sha1 -sign net/data/ssl/certificates/client_1.key
106 0xf1, 0x4d, 0x12, 0x14, 0x61, 0x68, 0xb3, 0x54, 0x57, 0x72, 0x4b, 0xfc, 47 // -out signature_sha1_pkcs data
107 0xc5, 0x61, 0xf6, 0xfc, 0x5a, 0x34, 0xce, 0x1f, 0x04, 0x1e, 0xf6, 0xe6, 48 signature_sha1_pkcs: 'signature_sha1_pkcs',
108 0x32, 0x94, 0xf7, 0x11, 0xe3, 0x80, 0xe4, 0x61, 0x06, 0xc2, 0x0c, 0x2c, 49 };
109 0xa8, 0x24, 0x02, 0x9d, 0x1c, 0xc1, 0xe6, 0xe8, 0x0b, 0xf5, 0x43, 0x17, 50
110 0x6c, 0x47, 0x59, 0x4a, 0x6f, 0x8d, 0x0f, 0x97, 0x4f, 0xac, 0x59, 0x13, 51 // Reads the binary file at |path| and passes it as a Uin8Array to |callback|.
111 0x02, 0xe9, 0x93, 0x02, 0xa2, 0x16, 0x15, 0x85, 0xda, 0x20, 0xb9, 0x87, 52 function readFile(path, callback) {
112 0x3f, 0x18, 0x78, 0xca, 0xd6, 0xe0, 0x15, 0x55, 0xe5, 0x5b, 0xd2, 0x60, 53 var oReq = new XMLHttpRequest();
113 0x4d, 0xd5, 0x60, 0x24, 0xc8, 0xfc, 0xba, 0x3c, 0x4e, 0x07, 0xca, 0xee, 54 oReq.responseType = "arraybuffer";
114 0xa3, 0x7c, 0x32, 0xbf, 0x9a, 0xe2, 0xe2, 0x02, 0xe7, 0x87, 0x65, 0x77, 55 oReq.open("GET", path, true /* asynchronous */);
115 0xfb, 0xca, 0x3d, 0xe0, 0x4e, 0x4a, 0x3f, 0xe3, 0xc6, 0x98, 0xa7, 0x56, 56 oReq.onload = function() {
116 0x3a, 0x17, 0x54, 0x42, 0xc5, 0xae, 0xaf, 0x05, 0xf4, 0x9b, 0xb8, 0x30, 57 var arrayBuffer = oReq.response;
117 0xe6, 0xee, 0x3a, 0x1c, 0x31, 0x35, 0x4b, 0x73, 0xd6, 0xd3, 0x7c, 0x4c, 58 if (arrayBuffer) {
118 0x52, 0x4d, 0x1f, 0xf8, 0x0f, 0x14, 0x97, 0xd9, 0xd5, 0xd7, 0x67, 0xd6, 59 callback(new Uint8Array(arrayBuffer));
119 0xd7, 0xbb, 0xa5, 0x52, 0xe9, 0xd2, 0xad, 0x68, 0x8c, 0x61, 0x02, 0x95, 60 } else {
120 0x8d, 0xb4, 0xe1, 0x37, 0x0c, 0x3f, 0x30, 0x64, 0x05, 0x4f, 0x76, 0x49, 61 callback(null);
121 0x9c, 0x50, 0xdb, 0x76, 0xa5, 0xad, 0xd2, 0x2d, 0xb4, 0xc3, 0xd2, 0xd2, 62 }
122 0xad, 0x0d, 0x64, 0x9a, 0xd6, 0xcf, 0x85, 0xba, 0x0c, 0x61, 0x00, 0xe3, 63 };
123 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x2f, 0x30, 0x2d, 0x30, 0x0c, 0x06, 64 oReq.send(null);
124 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 65 }
125 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 66
126 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 67 // For each key in dictionary, replaces the path dictionary[key] by the content
127 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 68 // of the resource located at that path stored in a Uint8Array.
128 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 69 function readData(dictionary, callback) {
129 0x01, 0x00, 0xce, 0x8a, 0x6b, 0xa8, 0x70, 0x1a, 0xa3, 0xbb, 0x54, 0x2b, 70 var keys = Object.keys(dictionary);
130 0x78, 0x29, 0x84, 0xb3, 0x08, 0xfa, 0x4f, 0x0a, 0x98, 0xcd, 0x10, 0x1e, 71 function recurse(index) {
131 0x04, 0x05, 0x2d, 0xe9, 0x0d, 0xd0, 0x84, 0xc1, 0x49, 0x21, 0x74, 0x30, 72 if (index >= keys.length) {
132 0x2d, 0x7e, 0xfe, 0xec, 0x69, 0xa6, 0x6c, 0x5a, 0xa1, 0x7e, 0x17, 0xd1, 73 callback();
133 0xb3, 0x84, 0x8c, 0xa0, 0xc1, 0x88, 0xc6, 0x45, 0xa6, 0x26, 0x82, 0xae, 74 return;
134 0xa6, 0x54, 0xed, 0xc2, 0x80, 0x49, 0xe2, 0xe1, 0x94, 0x06, 0x02, 0x42, 75 }
135 0xbf, 0x8d, 0x9a, 0xc2, 0xbc, 0x0c, 0x1e, 0x4a, 0x02, 0x74, 0xb0, 0x7e, 76 var key = keys[index];
136 0x90, 0x04, 0x23, 0xc2, 0x12, 0x52, 0x14, 0xe8, 0xc5, 0xb2, 0xb8, 0xef, 77 var path = dictionary[key];
137 0x77, 0x7e, 0x6b, 0xac, 0xa0, 0xcc, 0x68, 0xa8, 0x02, 0x2d, 0xa6, 0x6a, 78 readFile(path, function(array) {
138 0xd2, 0x17, 0x7f, 0xbd, 0x14, 0x21, 0x8b, 0xe3, 0x07, 0x02, 0xcd, 0x7f, 79 assertTrue(!!array);
139 0xe2, 0x01, 0x63, 0xfa, 0xe1, 0xfd, 0x9a, 0x43, 0xf9, 0x81, 0x52, 0x56, 80 dictionary[key] = array;
140 0x7f, 0xd2, 0x42, 0x71, 0xad, 0x90, 0xfe, 0xb4, 0xe3, 0xee, 0xf9, 0x76, 81 recurse(index + 1);
141 0x14, 0x86, 0x4e, 0x4b, 0x9b, 0x7f, 0x94, 0x51, 0xc8, 0x5c, 0xce, 0x56, 82 });
142 0x5d, 0xc5, 0xee, 0x2d, 0xb4, 0xe4, 0xd1, 0x15, 0xd8, 0x49, 0x59, 0x4f, 83 }
143 0x12, 0xd8, 0x5e, 0xad, 0x8f, 0x9e, 0x50, 0xab, 0x61, 0x18, 0x0d, 0xdf, 84
144 0xbc, 0x56, 0xf3, 0x75, 0x89, 0x1b, 0x0f, 0x19, 0xdf, 0x2d, 0x6e, 0x81, 85 recurse(0);
145 0x85, 0xdc, 0xc7, 0x28, 0x6a, 0x4b, 0x70, 0x6d, 0x85, 0x8c, 0x9d, 0x7d, 86 }
146 0xe1, 0x5d, 0x62, 0xbb, 0x47, 0x18, 0xdc, 0xe8, 0x83, 0xc3, 0x27, 0xaf, 87
147 0x5b, 0xec, 0x58, 0x07, 0x95, 0xe9, 0xe4, 0x9f, 0x94, 0xb4, 0x2a, 0x4a, 88 function setUp(callback) {
148 0x67, 0xaa, 0xd7, 0x57, 0x37, 0x1b, 0x21, 0x07, 0x11, 0xd5, 0x4e, 0xca, 89 readData(data, callback);
149 0x1e, 0x72, 0x8c, 0x43, 0xfe, 0xcf, 0xb9, 0xea, 0x68, 0xea, 0x5d, 0xd7, 90 }
150 0xd3, 0x32, 0xfb, 0x8a, 0x29, 0xf6
151 ]);
152 91
153 // Some array comparison. Note: not lexicographical! 92 // Some array comparison. Note: not lexicographical!
154 function compareArrays(array1, array2) { 93 function compareArrays(array1, array2) {
155 if (array1.length < array2.length) 94 if (array1.length < array2.length)
156 return -1; 95 return -1;
157 if (array1.length > array2.length) 96 if (array1.length > array2.length)
158 return 1; 97 return 1;
159 for (var i = 0; i < array1.length; i++) { 98 for (var i = 0; i < array1.length; i++) {
160 if (array1[i] < array2[i]) 99 if (array1[i] < array2[i])
161 return -1; 100 return -1;
(...skipping 26 matching lines...) Expand all
188 for (var i = 0; i < expectedCerts.length; i++) { 127 for (var i = 0; i < expectedCerts.length; i++) {
189 assertEq(expectedCerts[i], actualCerts[i], 128 assertEq(expectedCerts[i], actualCerts[i],
190 'Certs at index ' + i + ' differ'); 129 'Certs at index ' + i + ' differ');
191 } 130 }
192 } 131 }
193 if (callback) 132 if (callback)
194 callback(); 133 callback();
195 })); 134 }));
196 } 135 }
197 136
137 function checkAlgorithmIsCopiedOnRead(key) {
138 var algorithm = key.algorithm;
139 var originalAlgorithm = {
140 name: algorithm.name,
141 modulusLength: algorithm.modulusLength,
142 publicExponent: algorithm.publicExponent,
143 hash: {name: algorithm.hash.name}
144 };
145 var originalModulusLength = algorithm.modulusLength;
146 algorithm.hash.name = null;
147 algorithm.hash = null;
148 algorithm.name = null;
149 algorithm.modulusLength = null;
150 algorithm.publicExponent = null;
151 assertEq(originalAlgorithm, key.algorithm);
152 }
153
154 function checkPropertyIsReadOnly(object, key) {
155 var original = object[key];
156 try {
157 object[key] = {};
158 fail('Expected the property to be read-only and an exception to be thrown');
159 } catch (error) {
160 assertEq(original, object[key]);
161 }
162 }
163
164 function checkPrivateKeyFormat(privateKey) {
165 assertEq('private', privateKey.type);
166 assertEq(false, privateKey.extractable);
167 checkPropertyIsReadOnly(privateKey, 'algorithm');
168 checkAlgorithmIsCopiedOnRead(privateKey);
169 }
170
171 function checkPublicKeyFormat(publicKey) {
172 assertEq('public', publicKey.type);
173 assertEq(true, publicKey.extractable);
174 checkPropertyIsReadOnly(publicKey, 'algorithm');
175 checkAlgorithmIsCopiedOnRead(publicKey);
176 }
177
198 function testStaticMethods() { 178 function testStaticMethods() {
199 assertTrue(!!chrome.platformKeys, "No platformKeys namespace."); 179 assertTrue(!!chrome.platformKeys, "No platformKeys namespace.");
200 assertTrue(!!chrome.platformKeys.selectClientCertificates, 180 assertTrue(!!chrome.platformKeys.selectClientCertificates,
201 "No selectClientCertificates function."); 181 "No selectClientCertificates function.");
202 succeed(); 182 succeed();
203 } 183 }
204 184
185 function testHasSubtleCryptoMethods(token) {
186 assertTrue(!!token.subtleCrypto.generateKey,
187 "token has no generateKey method");
188 assertTrue(!!token.subtleCrypto.sign, "token has no sign method");
189 assertTrue(!!token.subtleCrypto.exportKey, "token has no exportKey method");
190 succeed();
191 }
192
205 function testSelectAllCerts() { 193 function testSelectAllCerts() {
206 var requestAll = { 194 var requestAll = {
207 certificateTypes: [], 195 certificateTypes: [],
208 certificateAuthorities: [] 196 certificateAuthorities: []
209 }; 197 };
210 var expectedCerts = [clientCert1]; 198 var expectedCerts = [data.client_1];
211 if (systemTokenEnabled) 199 if (systemTokenEnabled)
212 expectedCerts.push(clientCert2); 200 expectedCerts.push(data.client_2);
213 assertCertsSelected(requestAll, expectedCerts); 201 assertCertsSelected(requestAll, expectedCerts);
214 } 202 }
215 203
216 function testSelectCA1Certs() { 204 function testSelectCA1Certs() {
217 var requestCA1 = { 205 var requestCA1 = {
218 certificateTypes: [], 206 certificateTypes: [],
219 certificateAuthorities: [ca1DistinguishedNameDER.buffer] 207 certificateAuthorities: [data.client_1_issuer_dn.buffer]
220 }; 208 };
221 assertCertsSelected(requestCA1, [clientCert1]); 209 assertCertsSelected(requestCA1, [data.client_1]);
210 }
211
212 function testMatchResult() {
213 var requestCA1 = {
214 certificateTypes: [],
215 certificateAuthorities: [data.client_1_issuer_dn.buffer]
216 };
217 chrome.platformKeys.selectClientCertificates(
218 {interactive: false, request: requestCA1},
219 callbackPass(function(matches) {
220 var expectedAlgorithm = {
221 modulusLength: 2048,
222 name: "RSASSA-PKCS1-v1_5",
223 publicExponent: new Uint8Array([0x01, 0x00, 0x01])
224 };
225 var actualAlgorithm = matches[0].keyAlgorithm;
226 assertEq(
227 expectedAlgorithm, actualAlgorithm,
228 'Member algorithm of Match does not equal the expected algorithm');
229 }));
230 }
231
232 function testGetKeyPair() {
233 var keyParams = {
234 // Algorithm names are case-insensitive.
235 'hash': {'name': 'sha-1'}
236 };
237 chrome.platformKeys.getKeyPair(
238 data.client_1.buffer, keyParams,
239 callbackPass(function(publicKey, privateKey) {
240 var expectedAlgorithm = {
241 modulusLength: 2048,
242 name: "RSASSA-PKCS1-v1_5",
243 publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
244 hash: {name: 'SHA-1'}
245 };
246 assertEq(expectedAlgorithm, publicKey.algorithm);
247 assertEq(expectedAlgorithm, privateKey.algorithm);
248
249 checkPublicKeyFormat(publicKey);
250 checkPrivateKeyFormat(privateKey);
251
252 chrome.platformKeys.subtleCrypto()
253 .exportKey('spki', publicKey)
254 .then(callbackPass(function(actualPublicKeySpki) {
255 assertTrue(
256 compareArrays(data.client_1_spki, actualPublicKeySpki) == 0,
257 'Match did not contain correct public key');
258 }),
259 function(error) { fail("Export failed: " + error); });
260 }));
261 }
262
263 function testSignNoHash() {
264 var keyParams = {
265 // Algorithm names are case-insensitive.
266 hash: {name: 'NONE'}
267 };
268 var signParams = {
269 name: 'RSASSA-PKCS1-v1_5'
270 };
271 chrome.platformKeys.getKeyPair(
272 data.client_1.buffer, keyParams,
273 callbackPass(function(publicKey, privateKey) {
274 chrome.platformKeys.subtleCrypto()
275 .sign(signParams, privateKey, data.raw_data)
276 .then(callbackPass(function(signature) {
277 var actualSignature = new Uint8Array(signature);
278 assertTrue(compareArrays(data.signature_nohash_pkcs,
279 actualSignature) == 0,
280 'Incorrect signature');
281 }));
282 }));
283 }
284
285 function testSignSha1() {
286 var keyParams = {
287 // Algorithm names are case-insensitive.
288 hash: {name: 'Sha-1'}
289 };
290 var signParams = {
291 // Algorithm names are case-insensitive.
292 name: 'RSASSA-Pkcs1-v1_5'
293 };
294 chrome.platformKeys.getKeyPair(
295 data.client_1.buffer, keyParams,
296 callbackPass(function(publicKey, privateKey) {
297 chrome.platformKeys.subtleCrypto()
298 .sign(signParams, privateKey, data.raw_data)
299 .then(callbackPass(function(signature) {
300 var actualSignature = new Uint8Array(signature);
301 assertTrue(
302 compareArrays(data.signature_sha1_pkcs, actualSignature) == 0,
303 'Incorrect signature');
304 }));
305 }));
222 } 306 }
223 307
224 function runTests() { 308 function runTests() {
225 var tests = [ 309 var tests = [
226 testStaticMethods, 310 testStaticMethods,
227 testSelectAllCerts, 311 testSelectAllCerts,
228 testSelectCA1Certs 312 testSelectCA1Certs,
313 testMatchResult,
314 testGetKeyPair,
315 testSignNoHash,
316 testSignSha1
229 ]; 317 ];
230 318
231 chrome.test.runTests(tests); 319 chrome.test.runTests(tests);
232 } 320 }
233 321
234 runTests(); 322 setUp(runTests);
OLDNEW
« no previous file with comments | « chrome/renderer/resources/renderer_resources.grd ('k') | chrome/test/data/extensions/api_test/platform_keys/client_1.der » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698