OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Must be packed to ../enterprise_platform_keys.crx using the private key | 5 // Must be packed to ../enterprise_platform_keys.crx using the private key |
6 // ../enterprise_platform_keys.pem . | 6 // ../enterprise_platform_keys.pem . |
7 | 7 |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 var assertEq = chrome.test.assertEq; | 10 var assertEq = chrome.test.assertEq; |
11 var assertTrue = chrome.test.assertTrue; | 11 var assertTrue = chrome.test.assertTrue; |
12 var assertThrows = chrome.test.assertThrows; | 12 var assertThrows = chrome.test.assertThrows; |
13 var fail = chrome.test.fail; | 13 var fail = chrome.test.fail; |
14 var succeed = chrome.test.succeed; | 14 var succeed = chrome.test.succeed; |
15 var callbackPass = chrome.test.callbackPass; | 15 var callbackPass = chrome.test.callbackPass; |
16 var callbackFail= chrome.test.callbackFail; | 16 var callbackFail= chrome.test.callbackFail; |
17 | 17 |
18 // openssl req -new -x509 -key privkey.pem \ | 18 // openssl req -new -x509 -key privkey.pem \ |
19 // -outform der -out cert.der -days 36500 | 19 // -outform der -out cert.der -days 36500 |
20 // xxd -i cert.der | 20 // xxd -i cert.der |
21 // based on privateKeyPkcs8 | 21 // Based on privateKeyPkcs8User, which is stored in the user's token. |
22 var cert1a = new Uint8Array([ | 22 var cert1a = new Uint8Array([ |
23 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, | 23 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
24 0x02, 0x02, 0x09, 0x00, 0xd2, 0xcc, 0x76, 0xeb, 0x19, 0xb9, 0x3a, 0x33, | 24 0x02, 0x02, 0x09, 0x00, 0xd2, 0xcc, 0x76, 0xeb, 0x19, 0xb9, 0x3a, 0x33, |
25 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, | 25 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
26 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, | 26 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
27 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, | 27 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
28 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, | 28 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
29 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, | 29 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
30 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, | 30 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
31 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, | 31 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
(...skipping 23 matching lines...) Expand all Loading... | |
55 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 55 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
56 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, | 56 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
57 0x00, 0x37, 0x23, 0x2f, 0x81, 0x24, 0xfc, 0xec, 0x2d, 0x0b, 0xd1, 0xa0, | 57 0x00, 0x37, 0x23, 0x2f, 0x81, 0x24, 0xfc, 0xec, 0x2d, 0x0b, 0xd1, 0xa0, |
58 0x74, 0xdf, 0x2e, 0x34, 0x9a, 0x92, 0x33, 0xae, 0x75, 0xd6, 0x60, 0xfc, | 58 0x74, 0xdf, 0x2e, 0x34, 0x9a, 0x92, 0x33, 0xae, 0x75, 0xd6, 0x60, 0xfc, |
59 0x44, 0x1d, 0x65, 0x8c, 0xb7, 0xd9, 0x60, 0x3b, 0xc7, 0x20, 0x30, 0xdf, | 59 0x44, 0x1d, 0x65, 0x8c, 0xb7, 0xd9, 0x60, 0x3b, 0xc7, 0x20, 0x30, 0xdf, |
60 0x17, 0x07, 0xd1, 0x87, 0xda, 0x2b, 0x7f, 0x84, 0xf3, 0xfc, 0xb0, 0x31, | 60 0x17, 0x07, 0xd1, 0x87, 0xda, 0x2b, 0x7f, 0x84, 0xf3, 0xfc, 0xb0, 0x31, |
61 0x42, 0x08, 0x17, 0x96, 0xd2, 0x1b, 0xdc, 0x28, 0xae, 0xf8, 0xbd, 0xf9, | 61 0x42, 0x08, 0x17, 0x96, 0xd2, 0x1b, 0xdc, 0x28, 0xae, 0xf8, 0xbd, 0xf9, |
62 0x4e, 0x78, 0xc3, 0xe8, 0x80 | 62 0x4e, 0x78, 0xc3, 0xe8, 0x80 |
63 ]); | 63 ]); |
64 | 64 |
65 // based on privateKeyPkcs8, different from cert1a | 65 // Based on privateKeyPkcs8User, different from cert1a. |
66 var cert1b = new Uint8Array([ | 66 var cert1b = new Uint8Array([ |
67 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, | 67 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
68 0x02, 0x02, 0x09, 0x00, 0xe7, 0x1e, 0x6e, 0xb0, 0x12, 0x87, 0xf5, 0x09, | 68 0x02, 0x02, 0x09, 0x00, 0xe7, 0x1e, 0x6e, 0xb0, 0x12, 0x87, 0xf5, 0x09, |
69 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, | 69 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
70 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, | 70 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
71 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, | 71 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
72 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, | 72 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
73 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, | 73 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
74 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, | 74 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
75 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, | 75 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
(...skipping 23 matching lines...) Expand all Loading... | |
99 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 99 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
100 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, | 100 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
101 0x00, 0x82, 0x95, 0xa7, 0x08, 0x6c, 0xbd, 0x49, 0xe6, 0x1e, 0xc1, 0xd9, | 101 0x00, 0x82, 0x95, 0xa7, 0x08, 0x6c, 0xbd, 0x49, 0xe6, 0x1e, 0xc1, 0xd9, |
102 0x58, 0x54, 0x11, 0x11, 0x84, 0x77, 0x1e, 0xad, 0xe9, 0x73, 0x69, 0x1c, | 102 0x58, 0x54, 0x11, 0x11, 0x84, 0x77, 0x1e, 0xad, 0xe9, 0x73, 0x69, 0x1c, |
103 0x5c, 0xaa, 0x26, 0x3e, 0x5f, 0x1d, 0x89, 0x20, 0xc3, 0x90, 0xa4, 0x67, | 103 0x5c, 0xaa, 0x26, 0x3e, 0x5f, 0x1d, 0x89, 0x20, 0xc3, 0x90, 0xa4, 0x67, |
104 0xfa, 0x26, 0x20, 0xd7, 0x1f, 0xae, 0x42, 0x89, 0x30, 0x61, 0x43, 0x8a, | 104 0xfa, 0x26, 0x20, 0xd7, 0x1f, 0xae, 0x42, 0x89, 0x30, 0x61, 0x43, 0x8a, |
105 0x8c, 0xbe, 0xd4, 0x32, 0xf7, 0x96, 0x71, 0x2a, 0xcd, 0xeb, 0x26, 0xf6, | 105 0x8c, 0xbe, 0xd4, 0x32, 0xf7, 0x96, 0x71, 0x2a, 0xcd, 0xeb, 0x26, 0xf6, |
106 0xdb, 0x54, 0x95, 0xca, 0x5a | 106 0xdb, 0x54, 0x95, 0xca, 0x5a |
107 ]); | 107 ]); |
108 | 108 |
109 // based on a private key different than privateKeyPkcs8 | 109 // Based on a private key different than privateKeyPkcs8User or |
110 // privateKeyPkcs8System. | |
110 var cert2 = new Uint8Array([ | 111 var cert2 = new Uint8Array([ |
111 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, | 112 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
112 0x02, 0x02, 0x09, 0x00, 0x9e, 0x11, 0x7e, 0xff, 0x43, 0x84, 0xd4, 0xe6, | 113 0x02, 0x02, 0x09, 0x00, 0x9e, 0x11, 0x7e, 0xff, 0x43, 0x84, 0xd4, 0xe6, |
113 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, | 114 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
114 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, | 115 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
115 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, | 116 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
116 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, | 117 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
117 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, | 118 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
118 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, | 119 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
119 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, | 120 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
(...skipping 23 matching lines...) Expand all Loading... | |
143 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 144 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
144 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, | 145 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
145 0x00, 0xa5, 0xe8, 0x9d, 0x3d, 0xc4, 0x1a, 0x6e, 0xd2, 0x92, 0x42, 0x37, | 146 0x00, 0xa5, 0xe8, 0x9d, 0x3d, 0xc4, 0x1a, 0x6e, 0xd2, 0x92, 0x42, 0x37, |
146 0xb9, 0x3a, 0xb3, 0x8e, 0x2f, 0x55, 0xb5, 0xf2, 0xe4, 0x6e, 0x39, 0x0d, | 147 0xb9, 0x3a, 0xb3, 0x8e, 0x2f, 0x55, 0xb5, 0xf2, 0xe4, 0x6e, 0x39, 0x0d, |
147 0xa8, 0xba, 0x10, 0x43, 0x57, 0xdd, 0x4e, 0x4e, 0x52, 0xc6, 0xbe, 0x07, | 148 0xa8, 0xba, 0x10, 0x43, 0x57, 0xdd, 0x4e, 0x4e, 0x52, 0xc6, 0xbe, 0x07, |
148 0xdb, 0x83, 0x05, 0x97, 0x97, 0xc1, 0x7b, 0xd5, 0x5c, 0x50, 0x64, 0x0f, | 149 0xdb, 0x83, 0x05, 0x97, 0x97, 0xc1, 0x7b, 0xd5, 0x5c, 0x50, 0x64, 0x0f, |
149 0x96, 0xff, 0x3d, 0x83, 0x37, 0x8f, 0x3a, 0x85, 0x08, 0x62, 0x5c, 0xb1, | 150 0x96, 0xff, 0x3d, 0x83, 0x37, 0x8f, 0x3a, 0x85, 0x08, 0x62, 0x5c, 0xb1, |
150 0x2f, 0x68, 0xb2, 0x4a, 0x4a | 151 0x2f, 0x68, 0xb2, 0x4a, 0x4a |
151 ]); | 152 ]); |
152 | 153 |
154 // Based on privateKeyPkcs8System, which is stored in the system token. | |
155 var certSystem = new Uint8Array([ | |
156 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, | |
157 0x02, 0x02, 0x09, 0x00, 0xf4, 0x3d, 0x9f, 0xd2, 0x1e, 0xa4, 0xf5, 0x82, | |
158 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, | |
159 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, | |
160 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, | |
161 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, | |
162 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, | |
163 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, | |
164 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, | |
165 0x74, 0x64, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x37, 0x32, 0x38, | |
166 0x31, 0x33, 0x31, 0x36, 0x34, 0x35, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x31, | |
167 0x34, 0x30, 0x37, 0x30, 0x34, 0x31, 0x33, 0x31, 0x36, 0x34, 0x35, 0x5a, | |
168 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, | |
169 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, | |
170 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, | |
171 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, | |
172 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, | |
173 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, | |
174 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, | |
175 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, | |
176 0xe8, 0xb3, 0x04, 0xb1, 0xad, 0xef, 0x6b, 0xe5, 0xbe, 0xc9, 0x05, 0x75, | |
177 0x07, 0x41, 0xf5, 0x70, 0x50, 0xc2, 0xe8, 0xee, 0xeb, 0x09, 0x9d, 0x49, | |
178 0x64, 0x4c, 0x60, 0x61, 0x80, 0xbe, 0xc5, 0x41, 0xf3, 0x8c, 0x57, 0x90, | |
179 0x3a, 0x44, 0x62, 0x6d, 0x51, 0xb8, 0xbb, 0xc6, 0x9a, 0x16, 0xdf, 0xf9, | |
180 0xce, 0xe3, 0xb8, 0x8c, 0x2e, 0xa2, 0x16, 0xc8, 0xed, 0xc7, 0xf8, 0x4f, | |
181 0xbd, 0xd3, 0x6e, 0x63, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, | |
182 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, | |
183 0xcd, 0x97, 0x2d, 0xb2, 0xe2, 0xb8, 0x11, 0xea, 0xcf, 0x0b, 0xca, 0xad, | |
184 0x61, 0xf4, 0x2e, 0x49, 0x3e, 0xa0, 0x7e, 0xa7, 0x30, 0x1f, 0x06, 0x03, | |
185 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xcd, 0x97, 0x2d, | |
186 0xb2, 0xe2, 0xb8, 0x11, 0xea, 0xcf, 0x0b, 0xca, 0xad, 0x61, 0xf4, 0x2e, | |
187 0x49, 0x3e, 0xa0, 0x7e, 0xa7, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, | |
188 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, | |
189 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, | |
190 0x00, 0x8c, 0x05, 0x7e, 0xb1, 0xef, 0x5f, 0x7d, 0x80, 0x0c, 0x70, 0x9c, | |
191 0x99, 0x70, 0x97, 0x5f, 0x83, 0x89, 0xe3, 0x4e, 0x3c, 0x77, 0xed, 0xf3, | |
192 0x66, 0x2d, 0xd6, 0xa9, 0x46, 0x7d, 0xeb, 0x58, 0xbc, 0x50, 0xa7, 0xe6, | |
193 0xd7, 0x7d, 0xfc, 0xdd, 0x18, 0x20, 0x53, 0xfb, 0x11, 0x3d, 0xfc, 0x2f, | |
194 0xf3, 0x30, 0x60, 0x47, 0x2d, 0x8e, 0xd7, 0xbf, 0x0f, 0x0d, 0x47, 0x99, | |
195 0xcc, 0x6d, 0xab, 0xb6, 0xd6 | |
196 ]); | |
197 | |
153 /** | 198 /** |
154 * Runs an array of asynchronous functions [f1, f2, ...] of the form | 199 * Runs an array of asynchronous functions [f1, f2, ...] of the form |
155 * function(callback) {} | 200 * function(callback) {} |
156 * by chaining, i.e. f1(f2(...)). Additionally, each callback is wrapped with | 201 * by chaining, i.e. f1(f2(...)). Additionally, each callback is wrapped with |
157 * callbackPass. | 202 * callbackPass. |
158 */ | 203 */ |
159 function runAsyncSequence(funcs) { | 204 function runAsyncSequence(funcs) { |
160 if (funcs.length == 0) | 205 if (funcs.length == 0) |
161 return; | 206 return; |
162 function go(i) { | 207 function go(i) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 'Certs at index ' + i + ' differ'); | 261 'Certs at index ' + i + ' differ'); |
217 } | 262 } |
218 } | 263 } |
219 if (callback) | 264 if (callback) |
220 callback(); | 265 callback(); |
221 })); | 266 })); |
222 } | 267 } |
223 | 268 |
224 /** | 269 /** |
225 * Fetches all available tokens using platformKeys.getTokens and calls | 270 * Fetches all available tokens using platformKeys.getTokens and calls |
226 * |callback| with the user token if available or with undefined otherwise. | 271 * |callback| with the user and system token if available or with undefined |
272 * otherwise. | |
227 */ | 273 */ |
228 function getUserToken(callback) { | 274 function getTokens(callback) { |
229 chrome.enterprise.platformKeys.getTokens(function(tokens) { | 275 chrome.enterprise.platformKeys.getTokens(function(tokens) { |
276 var userToken = null; | |
277 var systemToken = null; | |
230 for (var i = 0; i < tokens.length; i++) { | 278 for (var i = 0; i < tokens.length; i++) { |
231 if (tokens[i].id == 'user') { | 279 if (tokens[i].id == 'user') |
232 callback(tokens[i]); | 280 userToken = tokens[i]; |
233 return; | 281 else if (tokens[i].id == 'system') |
234 } | 282 systemToken = tokens[i]; |
235 } | 283 } |
236 callback(undefined); | 284 callback(userToken, systemToken); |
237 }); | 285 }); |
238 } | 286 } |
239 | 287 |
240 /** | 288 /** |
241 * Runs preparations before the actual tests. Calls |callback| with |userToken|. | 289 * Runs preparations before the actual tests. Calls |callback| with |userToken|. |
242 */ | 290 */ |
243 function beforeTests(callback) { | 291 function beforeTests(callback) { |
244 assertTrue(!!chrome.enterprise, "No enterprise namespace."); | 292 assertTrue(!!chrome.enterprise, "No enterprise namespace."); |
245 assertTrue(!!chrome.enterprise.platformKeys, "No platformKeys namespace."); | 293 assertTrue(!!chrome.enterprise.platformKeys, "No platformKeys namespace."); |
246 assertTrue(!!chrome.enterprise.platformKeys.getTokens, | 294 assertTrue(!!chrome.enterprise.platformKeys.getTokens, |
247 "No getTokens function."); | 295 "No getTokens function."); |
248 assertTrue(!!chrome.enterprise.platformKeys.importCertificate, | 296 assertTrue(!!chrome.enterprise.platformKeys.importCertificate, |
249 "No importCertificate function."); | 297 "No importCertificate function."); |
250 assertTrue(!!chrome.enterprise.platformKeys.removeCertificate, | 298 assertTrue(!!chrome.enterprise.platformKeys.removeCertificate, |
251 "No removeCertificate function."); | 299 "No removeCertificate function."); |
252 | 300 |
253 getUserToken(function(userToken) { | 301 getTokens(function(userToken, systemToken) { |
254 if (!userToken) | 302 if (!systemToken) |
255 fail('no user token'); | 303 fail('no system token'); |
256 if (userToken.id != 'user') | 304 if (systemToken.id != 'system') |
257 fail('token is not named "user".'); | 305 fail('token is not named "system".'); |
Joao da Silva
2014/07/30 08:46:39
Shouldnt these checks be done for the userToken to
pneubeck (no reviews)
2014/07/30 13:53:45
Uuuhh. Yeah, something went wrong here.
| |
258 | 306 |
259 callback(userToken); | 307 callback(userToken, systemToken); |
260 }); | 308 }); |
261 } | 309 } |
262 | 310 |
263 function checkAlgorithmIsCopiedOnRead(key) { | 311 function checkAlgorithmIsCopiedOnRead(key) { |
264 var algorithm = key.algorithm; | 312 var algorithm = key.algorithm; |
265 var originalAlgorithm = { | 313 var originalAlgorithm = { |
266 name: algorithm.name, | 314 name: algorithm.name, |
267 modulusLength: algorithm.modulusLength, | 315 modulusLength: algorithm.modulusLength, |
268 publicExponent: algorithm.publicExponent, | 316 publicExponent: algorithm.publicExponent, |
269 hash: {name: algorithm.hash.name} | 317 hash: {name: algorithm.hash.name} |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 return window.crypto.subtle.verify( | 419 return window.crypto.subtle.verify( |
372 algorithm, webCryptoPublicKey, cachedSignature, data); | 420 algorithm, webCryptoPublicKey, cachedSignature, data); |
373 }), | 421 }), |
374 function(error) { fail("Import failed: " + error); }) | 422 function(error) { fail("Import failed: " + error); }) |
375 .then(callbackPass(function(success) { | 423 .then(callbackPass(function(success) { |
376 assertEq(true, success, "Signature invalid."); | 424 assertEq(true, success, "Signature invalid."); |
377 callback(cachedKeyPair); | 425 callback(cachedKeyPair); |
378 }), function(error) { fail("Verification failed: " + error); }); | 426 }), function(error) { fail("Verification failed: " + error); }); |
379 } | 427 } |
380 | 428 |
381 function runTests(userToken) { | 429 function runTests(userToken, systemToken) { |
382 chrome.test.runTests([ | 430 chrome.test.runTests([ |
383 function hasSubtleCryptoMethods() { | 431 function hasSubtleCryptoMethods() { |
384 assertTrue(!!userToken.subtleCrypto.generateKey, | 432 assertTrue(!!userToken.subtleCrypto.generateKey, |
385 "user token has no generateKey method"); | 433 "user token has no generateKey method"); |
386 assertTrue(!!userToken.subtleCrypto.sign, | 434 assertTrue(!!userToken.subtleCrypto.sign, |
387 "user token has no sign method"); | 435 "user token has no sign method"); |
388 assertTrue(!!userToken.subtleCrypto.exportKey, | 436 assertTrue(!!userToken.subtleCrypto.exportKey, |
389 "user token has no exportKey method"); | 437 "user token has no exportKey method"); |
390 succeed(); | 438 succeed(); |
391 }, | 439 }, |
392 function initiallyNoCerts() { assertCertsStored(userToken, []); }, | 440 function initiallyNoCerts() { |
441 assertCertsStored(userToken, []); | |
442 assertCertsStored(systemToken, []); | |
443 }, | |
393 | 444 |
394 // Generates a key and signs some data with it. Verifies the signature using | 445 // Generates a key and signs some data with it. Verifies the signature using |
395 // WebCrypto. Verifies also that a second sign operation fails. | 446 // WebCrypto. Verifies also that a second sign operation fails. |
396 function generateKeyAndSign() { | 447 function generateKeyAndSign() { |
397 var algorithm = { | 448 var algorithm = { |
398 name: "RSASSA-PKCS1-v1_5", | 449 name: "RSASSA-PKCS1-v1_5", |
399 // RsaHashedKeyGenParams | 450 // RsaHashedKeyGenParams |
400 modulusLength: 512, | 451 modulusLength: 512, |
401 // Equivalent to 65537 | 452 // Equivalent to 65537 |
402 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | 453 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 hash: { | 489 hash: { |
439 name: "SHA-512", | 490 name: "SHA-512", |
440 } | 491 } |
441 }; | 492 }; |
442 | 493 |
443 // Some random data to sign. | 494 // Some random data to sign. |
444 var data = new Uint8Array([5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 254]); | 495 var data = new Uint8Array([5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 254]); |
445 generateKeyAndVerify(userToken, algorithm, data, callbackPass()); | 496 generateKeyAndVerify(userToken, algorithm, data, callbackPass()); |
446 }, | 497 }, |
447 | 498 |
448 // Imports and removes certificates for privateKeyPkcs8, which was imported | 499 // Importing a cert should fail, if the private key is stored in another |
449 // by on C++'s side. | 500 // token. |
450 // Note: After this test, privateKeyPkcs8 is not stored anymore! | 501 // This uses the cert that refers to the privateKeyPkcs8, which was imported |
451 function importAndRemoveCerts() { | 502 // on C++'s side. |
503 function importCertWithKeyInOtherToken() { | |
504 chrome.enterprise.platformKeys.importCertificate( | |
505 systemToken.id, cert1a.buffer, callbackFail('Key not found.')); | |
506 }, | |
507 | |
508 // Imports and removes certificates for privateKeyPkcs8User, which was | |
509 // imported on C++'s side. | |
510 // Note: After this test, privateKeyPkcs8User is not stored anymore! | |
511 function importAndRemoveCertsToUserToken() { | |
452 runAsyncSequence([ | 512 runAsyncSequence([ |
453 chrome.enterprise.platformKeys.importCertificate.bind( | 513 chrome.enterprise.platformKeys.importCertificate.bind( |
454 null, userToken.id, cert1a.buffer), | 514 null, userToken.id, cert1a.buffer), |
455 assertCertsStored.bind(null, userToken, [cert1a]), | 515 assertCertsStored.bind(null, userToken, [cert1a]), |
456 // Importing the same cert again shouldn't change anything. | 516 // Importing the same cert again shouldn't change anything. |
457 chrome.enterprise.platformKeys.importCertificate.bind( | 517 chrome.enterprise.platformKeys.importCertificate.bind( |
458 null, userToken.id, cert1a.buffer), | 518 null, userToken.id, cert1a.buffer), |
459 assertCertsStored.bind(null, userToken, [cert1a]), | 519 assertCertsStored.bind(null, userToken, [cert1a]), |
460 // Importing another certificate should succeed. | 520 // Importing another certificate should succeed. |
461 chrome.enterprise.platformKeys.importCertificate.bind( | 521 chrome.enterprise.platformKeys.importCertificate.bind( |
462 null, userToken.id, cert1b.buffer), | 522 null, userToken.id, cert1b.buffer), |
463 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | 523 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), |
524 // Shouldn't affect the system token. | |
525 assertCertsStored.bind(null, systemToken, []), | |
464 chrome.enterprise.platformKeys.removeCertificate.bind( | 526 chrome.enterprise.platformKeys.removeCertificate.bind( |
465 null, userToken.id, cert1a.buffer), | 527 null, userToken.id, cert1a.buffer), |
466 assertCertsStored.bind(null, userToken, [cert1b]), | 528 assertCertsStored.bind(null, userToken, [cert1b]), |
467 chrome.enterprise.platformKeys.removeCertificate.bind( | 529 chrome.enterprise.platformKeys.removeCertificate.bind( |
468 null, userToken.id, cert1b.buffer), | 530 null, userToken.id, cert1b.buffer), |
469 assertCertsStored.bind(null, userToken, []) | 531 assertCertsStored.bind(null, userToken, []) |
470 ]); | 532 ]); |
471 }, | 533 }, |
472 | 534 |
535 // Imports and removes certificates for privateKeyPkcs8System, which was | |
536 // imported on C++'s side. | |
537 // Note: After this test, privateKeyPkcs8System is not stored anymore! | |
538 function importAndRemoveCertsToSystemToken() { | |
539 runAsyncSequence([ | |
540 chrome.enterprise.platformKeys.importCertificate.bind( | |
541 null, systemToken.id, certSystem.buffer), | |
542 assertCertsStored.bind(null, systemToken, [certSystem]), | |
543 // Importing the same cert again shouldn't change anything. | |
544 chrome.enterprise.platformKeys.importCertificate.bind( | |
545 null, systemToken.id, certSystem.buffer), | |
546 assertCertsStored.bind(null, systemToken, [certSystem]), | |
547 // Shouldn't affect the user token. | |
548 assertCertsStored.bind(null, userToken, []), | |
549 chrome.enterprise.platformKeys.removeCertificate.bind( | |
550 null, systemToken.id, certSystem.buffer), | |
551 assertCertsStored.bind(null, systemToken, []), | |
552 ]); | |
553 }, | |
554 | |
473 // Call generate key with invalid algorithm parameter, missing | 555 // Call generate key with invalid algorithm parameter, missing |
474 // modulusLength. | 556 // modulusLength. |
475 function algorithmParameterMissingModulusLength() { | 557 function algorithmParameterMissingModulusLength() { |
476 var algorithm = { | 558 var algorithm = { |
477 name: "RSASSA-PKCS1-v1_5", | 559 name: "RSASSA-PKCS1-v1_5", |
478 // Equivalent to 65537 | 560 // Equivalent to 65537 |
479 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | 561 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
480 hash: { | 562 hash: { |
481 name: "SHA-1", | 563 name: "SHA-1", |
482 } | 564 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 }; | 600 }; |
519 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | 601 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
520 function(keyPair) { fail('generateKey was expected to fail'); }, | 602 function(keyPair) { fail('generateKey was expected to fail'); }, |
521 callbackPass(function(error) { | 603 callbackPass(function(error) { |
522 assertTrue(error instanceof Error); | 604 assertTrue(error instanceof Error); |
523 assertEq('A required parameter was missing or out-of-range', | 605 assertEq('A required parameter was missing or out-of-range', |
524 error.message); | 606 error.message); |
525 })); | 607 })); |
526 }, | 608 }, |
527 | 609 |
528 // Imports a certificate for which now private key was imported/generated | 610 // Imports a certificate for which no private key was imported/generated |
529 // before. | 611 // before. |
530 function missingPrivateKey() { | 612 function missingPrivateKey() { |
531 chrome.enterprise.platformKeys.importCertificate( | 613 chrome.enterprise.platformKeys.importCertificate( |
532 userToken.id, cert2.buffer, callbackFail('Key not found.')); | 614 userToken.id, cert2.buffer, callbackFail('Key not found.')); |
533 }, | 615 }, |
616 | |
Joao da Silva
2014/07/30 08:46:39
Add newlines after the functions below too
pneubeck (no reviews)
2014/07/30 13:53:45
Done.
| |
534 function importInvalidCert() { | 617 function importInvalidCert() { |
535 var invalidCert = new ArrayBuffer(16); | 618 var invalidCert = new ArrayBuffer(16); |
536 chrome.enterprise.platformKeys.importCertificate( | 619 chrome.enterprise.platformKeys.importCertificate( |
537 userToken.id, | 620 userToken.id, |
538 invalidCert, | 621 invalidCert, |
539 callbackFail('Certificate is not a valid X.509 certificate.')); | 622 callbackFail('Certificate is not a valid X.509 certificate.')); |
540 }, | 623 }, |
541 function removeUnknownCert() { | 624 function removeUnknownCert() { |
542 chrome.enterprise.platformKeys.removeCertificate( | 625 chrome.enterprise.platformKeys.removeCertificate( |
543 userToken.id, | 626 userToken.id, |
544 cert2.buffer, | 627 cert2.buffer, |
545 callbackFail('Certificate could not be found.')); | 628 callbackFail('Certificate could not be found.')); |
546 }, | 629 }, |
547 function removeInvalidCert() { | 630 function removeInvalidCert() { |
548 var invalidCert = new ArrayBuffer(16); | 631 var invalidCert = new ArrayBuffer(16); |
549 chrome.enterprise.platformKeys.removeCertificate( | 632 chrome.enterprise.platformKeys.removeCertificate( |
550 userToken.id, | 633 userToken.id, |
551 invalidCert, | 634 invalidCert, |
552 callbackFail('Certificate is not a valid X.509 certificate.')); | 635 callbackFail('Certificate is not a valid X.509 certificate.')); |
553 }, | 636 }, |
554 function getCertsInvalidToken() { | 637 function getCertsInvalidToken() { |
555 chrome.enterprise.platformKeys.getCertificates( | 638 chrome.enterprise.platformKeys.getCertificates( |
556 'invalid token id', callbackFail('The token is not valid.')); | 639 'invalid token id', callbackFail('The token is not valid.')); |
557 } | 640 } |
558 ]); | 641 ]); |
559 } | 642 } |
560 | 643 |
561 beforeTests(runTests); | 644 beforeTests(runTests); |
OLD | NEW |