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 (!userToken) |
255 fail('no user token'); | 303 fail('no user token'); |
256 if (userToken.id != 'user') | 304 if (userToken.id != 'user') |
257 fail('token is not named "user".'); | 305 fail('user token is not named "user".'); |
258 | 306 |
259 callback(userToken); | 307 if (!systemToken) |
| 308 fail('no system token'); |
| 309 if (systemToken.id != 'system') |
| 310 fail('system token is not named "system".'); |
| 311 |
| 312 callback(userToken, systemToken); |
260 }); | 313 }); |
261 } | 314 } |
262 | 315 |
263 function checkAlgorithmIsCopiedOnRead(key) { | 316 function checkAlgorithmIsCopiedOnRead(key) { |
264 var algorithm = key.algorithm; | 317 var algorithm = key.algorithm; |
265 var originalAlgorithm = { | 318 var originalAlgorithm = { |
266 name: algorithm.name, | 319 name: algorithm.name, |
267 modulusLength: algorithm.modulusLength, | 320 modulusLength: algorithm.modulusLength, |
268 publicExponent: algorithm.publicExponent, | 321 publicExponent: algorithm.publicExponent, |
269 hash: {name: algorithm.hash.name} | 322 hash: {name: algorithm.hash.name} |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 return window.crypto.subtle.verify( | 424 return window.crypto.subtle.verify( |
372 algorithm, webCryptoPublicKey, cachedSignature, data); | 425 algorithm, webCryptoPublicKey, cachedSignature, data); |
373 }), | 426 }), |
374 function(error) { fail("Import failed: " + error); }) | 427 function(error) { fail("Import failed: " + error); }) |
375 .then(callbackPass(function(success) { | 428 .then(callbackPass(function(success) { |
376 assertEq(true, success, "Signature invalid."); | 429 assertEq(true, success, "Signature invalid."); |
377 callback(cachedKeyPair); | 430 callback(cachedKeyPair); |
378 }), function(error) { fail("Verification failed: " + error); }); | 431 }), function(error) { fail("Verification failed: " + error); }); |
379 } | 432 } |
380 | 433 |
381 function runTests(userToken) { | 434 function runTests(userToken, systemToken) { |
382 chrome.test.runTests([ | 435 chrome.test.runTests([ |
383 function hasSubtleCryptoMethods() { | 436 function hasSubtleCryptoMethods() { |
384 assertTrue(!!userToken.subtleCrypto.generateKey, | 437 assertTrue(!!userToken.subtleCrypto.generateKey, |
385 "user token has no generateKey method"); | 438 "user token has no generateKey method"); |
386 assertTrue(!!userToken.subtleCrypto.sign, | 439 assertTrue(!!userToken.subtleCrypto.sign, |
387 "user token has no sign method"); | 440 "user token has no sign method"); |
388 assertTrue(!!userToken.subtleCrypto.exportKey, | 441 assertTrue(!!userToken.subtleCrypto.exportKey, |
389 "user token has no exportKey method"); | 442 "user token has no exportKey method"); |
390 succeed(); | 443 succeed(); |
391 }, | 444 }, |
392 function initiallyNoCerts() { assertCertsStored(userToken, []); }, | 445 |
| 446 function initiallyNoCerts() { |
| 447 assertCertsStored(userToken, []); |
| 448 assertCertsStored(systemToken, []); |
| 449 }, |
393 | 450 |
394 // Generates a key and signs some data with it. Verifies the signature using | 451 // Generates a key and signs some data with it. Verifies the signature using |
395 // WebCrypto. Verifies also that a second sign operation fails. | 452 // WebCrypto. Verifies also that a second sign operation fails. |
396 function generateKeyAndSign() { | 453 function generateKeyAndSign() { |
397 var algorithm = { | 454 var algorithm = { |
398 name: "RSASSA-PKCS1-v1_5", | 455 name: "RSASSA-PKCS1-v1_5", |
399 // RsaHashedKeyGenParams | 456 // RsaHashedKeyGenParams |
400 modulusLength: 512, | 457 modulusLength: 512, |
401 // Equivalent to 65537 | 458 // Equivalent to 65537 |
402 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | 459 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 hash: { | 495 hash: { |
439 name: "SHA-512", | 496 name: "SHA-512", |
440 } | 497 } |
441 }; | 498 }; |
442 | 499 |
443 // Some random data to sign. | 500 // Some random data to sign. |
444 var data = new Uint8Array([5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 254]); | 501 var data = new Uint8Array([5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0, 0, 254]); |
445 generateKeyAndVerify(userToken, algorithm, data, callbackPass()); | 502 generateKeyAndVerify(userToken, algorithm, data, callbackPass()); |
446 }, | 503 }, |
447 | 504 |
448 // Imports and removes certificates for privateKeyPkcs8, which was imported | 505 // Importing a cert should fail, if the private key is stored in another |
449 // by on C++'s side. | 506 // token. |
450 // Note: After this test, privateKeyPkcs8 is not stored anymore! | 507 // This uses the cert that refers to the privateKeyPkcs8, which was imported |
451 function importAndRemoveCerts() { | 508 // on C++'s side. |
| 509 function importCertWithKeyInOtherToken() { |
| 510 chrome.enterprise.platformKeys.importCertificate( |
| 511 systemToken.id, cert1a.buffer, callbackFail('Key not found.')); |
| 512 }, |
| 513 |
| 514 // Imports and removes certificates for privateKeyPkcs8User, which was |
| 515 // imported on C++'s side. |
| 516 // Note: After this test, privateKeyPkcs8User is not stored anymore! |
| 517 function importAndRemoveCertsToUserToken() { |
452 runAsyncSequence([ | 518 runAsyncSequence([ |
453 chrome.enterprise.platformKeys.importCertificate.bind( | 519 chrome.enterprise.platformKeys.importCertificate.bind( |
454 null, userToken.id, cert1a.buffer), | 520 null, userToken.id, cert1a.buffer), |
455 assertCertsStored.bind(null, userToken, [cert1a]), | 521 assertCertsStored.bind(null, userToken, [cert1a]), |
456 // Importing the same cert again shouldn't change anything. | 522 // Importing the same cert again shouldn't change anything. |
457 chrome.enterprise.platformKeys.importCertificate.bind( | 523 chrome.enterprise.platformKeys.importCertificate.bind( |
458 null, userToken.id, cert1a.buffer), | 524 null, userToken.id, cert1a.buffer), |
459 assertCertsStored.bind(null, userToken, [cert1a]), | 525 assertCertsStored.bind(null, userToken, [cert1a]), |
460 // Importing another certificate should succeed. | 526 // Importing another certificate should succeed. |
461 chrome.enterprise.platformKeys.importCertificate.bind( | 527 chrome.enterprise.platformKeys.importCertificate.bind( |
462 null, userToken.id, cert1b.buffer), | 528 null, userToken.id, cert1b.buffer), |
463 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | 529 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), |
| 530 // Shouldn't affect the system token. |
| 531 assertCertsStored.bind(null, systemToken, []), |
464 chrome.enterprise.platformKeys.removeCertificate.bind( | 532 chrome.enterprise.platformKeys.removeCertificate.bind( |
465 null, userToken.id, cert1a.buffer), | 533 null, userToken.id, cert1a.buffer), |
466 assertCertsStored.bind(null, userToken, [cert1b]), | 534 assertCertsStored.bind(null, userToken, [cert1b]), |
467 chrome.enterprise.platformKeys.removeCertificate.bind( | 535 chrome.enterprise.platformKeys.removeCertificate.bind( |
468 null, userToken.id, cert1b.buffer), | 536 null, userToken.id, cert1b.buffer), |
469 assertCertsStored.bind(null, userToken, []) | 537 assertCertsStored.bind(null, userToken, []) |
470 ]); | 538 ]); |
471 }, | 539 }, |
472 | 540 |
| 541 // Imports and removes certificates for privateKeyPkcs8System, which was |
| 542 // imported on C++'s side. |
| 543 // Note: After this test, privateKeyPkcs8System is not stored anymore! |
| 544 function importAndRemoveCertsToSystemToken() { |
| 545 runAsyncSequence([ |
| 546 chrome.enterprise.platformKeys.importCertificate.bind( |
| 547 null, systemToken.id, certSystem.buffer), |
| 548 assertCertsStored.bind(null, systemToken, [certSystem]), |
| 549 // Importing the same cert again shouldn't change anything. |
| 550 chrome.enterprise.platformKeys.importCertificate.bind( |
| 551 null, systemToken.id, certSystem.buffer), |
| 552 assertCertsStored.bind(null, systemToken, [certSystem]), |
| 553 // Shouldn't affect the user token. |
| 554 assertCertsStored.bind(null, userToken, []), |
| 555 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 556 null, systemToken.id, certSystem.buffer), |
| 557 assertCertsStored.bind(null, systemToken, []), |
| 558 ]); |
| 559 }, |
| 560 |
473 // Call generate key with invalid algorithm parameter, missing | 561 // Call generate key with invalid algorithm parameter, missing |
474 // modulusLength. | 562 // modulusLength. |
475 function algorithmParameterMissingModulusLength() { | 563 function algorithmParameterMissingModulusLength() { |
476 var algorithm = { | 564 var algorithm = { |
477 name: "RSASSA-PKCS1-v1_5", | 565 name: "RSASSA-PKCS1-v1_5", |
478 // Equivalent to 65537 | 566 // Equivalent to 65537 |
479 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | 567 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
480 hash: { | 568 hash: { |
481 name: "SHA-1", | 569 name: "SHA-1", |
482 } | 570 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 }; | 606 }; |
519 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | 607 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
520 function(keyPair) { fail('generateKey was expected to fail'); }, | 608 function(keyPair) { fail('generateKey was expected to fail'); }, |
521 callbackPass(function(error) { | 609 callbackPass(function(error) { |
522 assertTrue(error instanceof Error); | 610 assertTrue(error instanceof Error); |
523 assertEq('A required parameter was missing or out-of-range', | 611 assertEq('A required parameter was missing or out-of-range', |
524 error.message); | 612 error.message); |
525 })); | 613 })); |
526 }, | 614 }, |
527 | 615 |
528 // Imports a certificate for which now private key was imported/generated | 616 // Imports a certificate for which no private key was imported/generated |
529 // before. | 617 // before. |
530 function missingPrivateKey() { | 618 function missingPrivateKey() { |
531 chrome.enterprise.platformKeys.importCertificate( | 619 chrome.enterprise.platformKeys.importCertificate( |
532 userToken.id, cert2.buffer, callbackFail('Key not found.')); | 620 userToken.id, cert2.buffer, callbackFail('Key not found.')); |
533 }, | 621 }, |
| 622 |
534 function importInvalidCert() { | 623 function importInvalidCert() { |
535 var invalidCert = new ArrayBuffer(16); | 624 var invalidCert = new ArrayBuffer(16); |
536 chrome.enterprise.platformKeys.importCertificate( | 625 chrome.enterprise.platformKeys.importCertificate( |
537 userToken.id, | 626 userToken.id, |
538 invalidCert, | 627 invalidCert, |
539 callbackFail('Certificate is not a valid X.509 certificate.')); | 628 callbackFail('Certificate is not a valid X.509 certificate.')); |
540 }, | 629 }, |
| 630 |
541 function removeUnknownCert() { | 631 function removeUnknownCert() { |
542 chrome.enterprise.platformKeys.removeCertificate( | 632 chrome.enterprise.platformKeys.removeCertificate( |
543 userToken.id, | 633 userToken.id, |
544 cert2.buffer, | 634 cert2.buffer, |
545 callbackFail('Certificate could not be found.')); | 635 callbackFail('Certificate could not be found.')); |
546 }, | 636 }, |
| 637 |
547 function removeInvalidCert() { | 638 function removeInvalidCert() { |
548 var invalidCert = new ArrayBuffer(16); | 639 var invalidCert = new ArrayBuffer(16); |
549 chrome.enterprise.platformKeys.removeCertificate( | 640 chrome.enterprise.platformKeys.removeCertificate( |
550 userToken.id, | 641 userToken.id, |
551 invalidCert, | 642 invalidCert, |
552 callbackFail('Certificate is not a valid X.509 certificate.')); | 643 callbackFail('Certificate is not a valid X.509 certificate.')); |
553 }, | 644 }, |
| 645 |
554 function getCertsInvalidToken() { | 646 function getCertsInvalidToken() { |
555 chrome.enterprise.platformKeys.getCertificates( | 647 chrome.enterprise.platformKeys.getCertificates( |
556 'invalid token id', callbackFail('The token is not valid.')); | 648 'invalid token id', callbackFail('The token is not valid.')); |
557 } | 649 } |
558 ]); | 650 ]); |
559 } | 651 } |
560 | 652 |
561 beforeTests(runTests); | 653 beforeTests(runTests); |
OLD | NEW |