OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 console.log('The sign-in screen test app loaded'); | 5 // The background script of the test app. The app exposes a certificate to |
6 // Chrome via chrome.certificateProvider API. This allows to test that the app | |
7 // and the API work by initiating an SSL connection that requests the client | |
8 // certificate. The app also tests displaying of the PIN dialog. Note that the | |
9 // app does NOT implement the real signing operation, therefore it's expected | |
10 // that the SSL connections will fail to establish in the end. | |
11 | |
12 | |
pmarko
2017/05/11 18:24:43
Consider adding a short comment here that debug ou
emaxx
2017/05/11 20:12:30
Done.
| |
13 // Raw contents of the DER-encoded X.509 certificate. | |
14 // Generated using the following command (assuming that the certificate was | |
15 // bundled in the PKCS #12 archive <path_to_pkcs12_file>): | |
16 // openssl pkcs12 -in <path_to_pkcs12_file> -nodes | \ | |
17 // openssl x509 -outform der | xxd -i | |
18 // Current certificate expires on Dec 15, 2017. | |
19 var TEST_CERTIFICATE = | |
20 (new Uint8Array([ | |
21 0x30, 0x82, 0x06, 0x78, 0x30, 0x82, 0x05, 0x60, 0xa0, 0x03, 0x02, 0x01, | |
22 0x02, 0x02, 0x0a, 0x17, 0xa5, 0x51, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, | |
23 0x8a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, | |
24 0x01, 0x0a, 0x30, 0x00, 0x30, 0x64, 0x31, 0x13, 0x30, 0x11, 0x06, 0x0a, | |
25 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x03, | |
26 0x6e, 0x65, 0x74, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x0a, 0x09, 0x92, 0x26, | |
27 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0b, 0x74, 0x6f, 0x74, | |
28 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x31, 0x12, 0x30, 0x10, | |
29 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, | |
30 0x16, 0x02, 0x61, 0x64, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, | |
31 0x03, 0x13, 0x13, 0x54, 0x6f, 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, | |
32 0x64, 0x73, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, | |
33 0x17, 0x0d, 0x31, 0x36, 0x31, 0x32, 0x31, 0x35, 0x31, 0x34, 0x34, 0x34, | |
34 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x31, 0x37, 0x31, 0x32, 0x31, 0x35, 0x31, | |
35 0x34, 0x34, 0x34, 0x31, 0x39, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x13, 0x30, | |
36 0x11, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, | |
37 0x19, 0x16, 0x03, 0x6e, 0x65, 0x74, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x0a, | |
38 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0b, | |
39 0x74, 0x6f, 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x31, | |
40 0x12, 0x30, 0x10, 0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, | |
41 0x64, 0x01, 0x19, 0x16, 0x02, 0x61, 0x64, 0x31, 0x0e, 0x30, 0x0c, 0x06, | |
42 0x03, 0x55, 0x04, 0x03, 0x13, 0x05, 0x55, 0x73, 0x65, 0x72, 0x73, 0x31, | |
43 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x0a, 0x61, 0x64, | |
44 0x66, 0x73, 0x20, 0x74, 0x65, 0x73, 0x74, 0x31, 0x31, 0x31, 0x30, 0x2f, | |
45 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, | |
46 0x22, 0x61, 0x64, 0x66, 0x73, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x31, 0x40, | |
47 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x6e, 0x6f, 0x6d, 0x61, | |
48 0x64, 0x69, 0x63, 0x66, 0x65, 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x30, | |
49 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, | |
50 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, | |
51 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xdf, 0xf4, 0x9a, 0x94, | |
52 0xad, 0x0f, 0xf4, 0xaf, 0xd6, 0x0e, 0xc5, 0x15, 0xf9, 0x20, 0x73, 0xa3, | |
53 0x73, 0x04, 0xb7, 0x6a, 0x32, 0xec, 0xa6, 0x1a, 0x91, 0x1f, 0x80, 0x1f, | |
54 0xc6, 0xfa, 0x33, 0x17, 0x1d, 0x9b, 0xb3, 0xd5, 0xe1, 0x2f, 0xcf, 0x1e, | |
55 0xfb, 0xd7, 0x43, 0xe9, 0xe8, 0x5f, 0x8e, 0x9d, 0x9e, 0x83, 0x9b, 0x95, | |
56 0x98, 0x5d, 0x21, 0xd2, 0xc9, 0x8a, 0x45, 0x5f, 0x0f, 0x98, 0x84, 0xfa, | |
57 0xe8, 0x0a, 0x7d, 0x9c, 0xab, 0xe6, 0xbe, 0x03, 0x18, 0x05, 0x2a, 0x46, | |
58 0xf0, 0x03, 0x2b, 0xf1, 0x36, 0xf6, 0x1f, 0x0a, 0xac, 0x04, 0xd6, 0x22, | |
59 0x0a, 0xce, 0x2c, 0x3f, 0x2f, 0x25, 0xd5, 0xad, 0x84, 0xf4, 0x6b, 0xd9, | |
60 0xbe, 0x77, 0x78, 0xcb, 0xa3, 0xe4, 0x8c, 0x2c, 0x8d, 0xdc, 0x83, 0x61, | |
61 0x18, 0x00, 0x0f, 0x2e, 0x2c, 0x57, 0x6b, 0xfa, 0xfb, 0x1d, 0x19, 0xf7, | |
62 0x8b, 0x2f, 0xdc, 0x3c, 0xb5, 0x69, 0x44, 0xfa, 0x81, 0x7d, 0x3d, 0x26, | |
63 0x84, 0xad, 0xe5, 0xe6, 0xce, 0x0f, 0x1b, 0x13, 0xf6, 0x60, 0xd4, 0x5d, | |
64 0x3f, 0xce, 0x09, 0x2d, 0x2f, 0x71, 0xda, 0x3f, 0x88, 0x51, 0xe1, 0x75, | |
65 0xcd, 0xf0, 0xbf, 0x84, 0xa8, 0xc5, 0xb5, 0x4e, 0x26, 0x59, 0x92, 0x0a, | |
66 0x3f, 0x5f, 0x5f, 0xcd, 0xa8, 0x67, 0x4b, 0xed, 0x22, 0xa0, 0x0d, 0x41, | |
67 0x31, 0x0a, 0x73, 0x10, 0x42, 0xa0, 0x08, 0xe1, 0x94, 0x1b, 0xd5, 0x3e, | |
68 0x97, 0x2b, 0x53, 0x9c, 0x65, 0xd3, 0xc8, 0x1d, 0x56, 0x0e, 0x0b, 0x4d, | |
69 0x32, 0x6d, 0x54, 0xfc, 0x5a, 0xa8, 0x3b, 0x61, 0xc1, 0xe2, 0xf7, 0x79, | |
70 0x16, 0xec, 0x9e, 0x81, 0x58, 0xf6, 0x9b, 0x13, 0xd9, 0x2f, 0x9b, 0x3c, | |
71 0x5c, 0x47, 0x87, 0xff, 0x5b, 0x8d, 0xc0, 0xbe, 0x34, 0xaf, 0xd3, 0x23, | |
72 0xeb, 0x67, 0x5a, 0xa1, 0xff, 0x9a, 0xb2, 0xf3, 0xea, 0x74, 0xbc, 0x89, | |
73 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x02, 0xef, 0x30, 0x82, 0x02, | |
74 0xeb, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, | |
75 0xbe, 0x17, 0x87, 0x1f, 0xa6, 0x79, 0xe3, 0xa6, 0x50, 0x93, 0x97, 0xa8, | |
76 0x11, 0x60, 0x09, 0x45, 0x85, 0xd4, 0x87, 0xad, 0x30, 0x1f, 0x06, 0x03, | |
77 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xd0, 0xd1, 0x3f, | |
78 0x7c, 0xcd, 0xc8, 0xe5, 0xff, 0x3f, 0x17, 0xb2, 0xfb, 0xc7, 0x51, 0xf1, | |
79 0xbd, 0x99, 0x5d, 0x27, 0xc0, 0x30, 0x82, 0x01, 0x72, 0x06, 0x03, 0x55, | |
80 0x1d, 0x1f, 0x04, 0x82, 0x01, 0x69, 0x30, 0x82, 0x01, 0x65, 0x30, 0x82, | |
81 0x01, 0x61, 0xa0, 0x82, 0x01, 0x5d, 0xa0, 0x82, 0x01, 0x59, 0x86, 0x81, | |
82 0xd1, 0x6c, 0x64, 0x61, 0x70, 0x3a, 0x2f, 0x2f, 0x2f, 0x43, 0x4e, 0x3d, | |
83 0x54, 0x6f, 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x25, | |
84 0x32, 0x30, 0x52, 0x6f, 0x6f, 0x74, 0x25, 0x32, 0x30, 0x43, 0x41, 0x2c, | |
85 0x43, 0x4e, 0x3d, 0x77, 0x69, 0x6e, 0x2d, 0x70, 0x6b, 0x69, 0x2d, 0x73, | |
86 0x65, 0x72, 0x76, 0x65, 0x72, 0x30, 0x31, 0x2c, 0x43, 0x4e, 0x3d, 0x43, | |
87 0x44, 0x50, 0x2c, 0x43, 0x4e, 0x3d, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, | |
88 0x25, 0x32, 0x30, 0x4b, 0x65, 0x79, 0x25, 0x32, 0x30, 0x53, 0x65, 0x72, | |
89 0x76, 0x69, 0x63, 0x65, 0x73, 0x2c, 0x43, 0x4e, 0x3d, 0x53, 0x65, 0x72, | |
90 0x76, 0x69, 0x63, 0x65, 0x73, 0x2c, 0x43, 0x4e, 0x3d, 0x43, 0x6f, 0x6e, | |
91 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x44, | |
92 0x43, 0x3d, 0x61, 0x64, 0x2c, 0x44, 0x43, 0x3d, 0x74, 0x6f, 0x74, 0x68, | |
93 0x65, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x2c, 0x44, 0x43, 0x3d, 0x6e, | |
94 0x65, 0x74, 0x3f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, | |
95 0x74, 0x65, 0x52, 0x65, 0x76, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, | |
96 0x4c, 0x69, 0x73, 0x74, 0x3f, 0x62, 0x61, 0x73, 0x65, 0x3f, 0x6f, 0x62, | |
97 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x63, 0x52, | |
98 0x4c, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, | |
99 0x6e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x86, 0x41, 0x68, 0x74, 0x74, 0x70, | |
100 0x3a, 0x2f, 0x2f, 0x70, 0x6b, 0x69, 0x2e, 0x74, 0x6f, 0x74, 0x68, 0x65, | |
101 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x2f, 0x43, | |
102 0x65, 0x72, 0x74, 0x45, 0x6e, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x54, 0x6f, | |
103 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x25, 0x32, 0x30, | |
104 0x52, 0x6f, 0x6f, 0x74, 0x25, 0x32, 0x30, 0x43, 0x41, 0x2e, 0x63, 0x72, | |
105 0x6c, 0x86, 0x40, 0x66, 0x69, 0x6c, 0x65, 0x3a, 0x2f, 0x2f, 0x5c, 0x5c, | |
106 0x77, 0x69, 0x6e, 0x2d, 0x70, 0x6b, 0x69, 0x2d, 0x73, 0x65, 0x72, 0x76, | |
107 0x65, 0x72, 0x30, 0x31, 0x5c, 0x43, 0x65, 0x72, 0x74, 0x45, 0x6e, 0x72, | |
108 0x6f, 0x6c, 0x6c, 0x5c, 0x54, 0x6f, 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, | |
109 0x75, 0x64, 0x73, 0x25, 0x32, 0x30, 0x52, 0x6f, 0x6f, 0x74, 0x25, 0x32, | |
110 0x30, 0x43, 0x41, 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x3b, 0x06, 0x08, 0x2b, | |
111 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x2f, 0x30, 0x2d, 0x30, | |
112 0x2b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, | |
113 0x1f, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x6b, 0x69, 0x2e, | |
114 0x74, 0x6f, 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x73, 0x2e, | |
115 0x6e, 0x65, 0x74, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x30, 0x17, 0x06, 0x09, | |
116 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x14, 0x02, 0x04, 0x0a, 0x1e, | |
117 0x08, 0x00, 0x55, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x30, 0x0e, 0x06, | |
118 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x05, | |
119 0xa0, 0x30, 0x29, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x22, 0x30, 0x20, | |
120 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x0a, 0x03, 0x04, | |
121 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x04, 0x06, 0x08, | |
122 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x5c, 0x06, 0x03, | |
123 0x55, 0x1d, 0x11, 0x04, 0x55, 0x30, 0x53, 0xa0, 0x2d, 0x06, 0x0a, 0x2b, | |
124 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x14, 0x02, 0x03, 0xa0, 0x1f, 0x0c, | |
125 0x1d, 0x61, 0x64, 0x66, 0x73, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x31, 0x40, | |
126 0x61, 0x64, 0x2e, 0x74, 0x6f, 0x74, 0x68, 0x65, 0x63, 0x6c, 0x6f, 0x75, | |
127 0x64, 0x73, 0x2e, 0x6e, 0x65, 0x74, 0x81, 0x22, 0x61, 0x64, 0x66, 0x73, | |
128 0x2d, 0x74, 0x65, 0x73, 0x74, 0x31, 0x40, 0x64, 0x65, 0x76, 0x69, 0x63, | |
129 0x65, 0x73, 0x2e, 0x6e, 0x6f, 0x6d, 0x61, 0x64, 0x69, 0x63, 0x66, 0x65, | |
130 0x65, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x44, 0x06, 0x09, 0x2a, 0x86, | |
131 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x0f, 0x04, 0x37, 0x30, 0x35, 0x30, | |
132 0x0e, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x03, 0x02, 0x02, | |
133 0x02, 0x00, 0x80, 0x30, 0x0e, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, | |
134 0x0d, 0x03, 0x04, 0x02, 0x02, 0x00, 0x80, 0x30, 0x07, 0x06, 0x05, 0x2b, | |
135 0x0e, 0x03, 0x02, 0x07, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, | |
136 0xf7, 0x0d, 0x03, 0x07, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | |
137 0xf7, 0x0d, 0x01, 0x01, 0x0a, 0x30, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, | |
138 0x2d, 0xb1, 0x92, 0xad, 0xc5, 0x3d, 0x4d, 0x41, 0x51, 0x7d, 0x38, 0xa0, | |
139 0x7a, 0x9b, 0x67, 0x51, 0x7e, 0x5b, 0x8f, 0xd6, 0x2a, 0x6f, 0xb5, 0x67, | |
140 0x58, 0xeb, 0x86, 0x1f, 0xf6, 0x9e, 0xfa, 0x06, 0x12, 0x5d, 0x3d, 0xce, | |
141 0x61, 0xba, 0x8f, 0x23, 0x89, 0xba, 0xd4, 0x2a, 0x50, 0xee, 0x1d, 0xda, | |
142 0x23, 0x7f, 0x19, 0x30, 0x10, 0xf6, 0xa4, 0xea, 0xbf, 0x0d, 0xbb, 0x4d, | |
143 0x3d, 0x4b, 0x1c, 0x03, 0xd5, 0x85, 0xbc, 0x42, 0x69, 0x59, 0xed, 0xb2, | |
144 0x0c, 0x68, 0x39, 0x7e, 0x8a, 0x00, 0xd0, 0x46, 0xe3, 0x59, 0xa4, 0xf5, | |
145 0x99, 0x43, 0xb1, 0xdf, 0x36, 0xfa, 0x18, 0x3c, 0xef, 0xc2, 0x51, 0x96, | |
146 0x55, 0x35, 0x79, 0xb6, 0x01, 0x1f, 0x54, 0xd1, 0xf0, 0xc5, 0x36, 0xe7, | |
147 0x11, 0x6f, 0xe7, 0x33, 0x5c, 0x87, 0xb5, 0x23, 0x9b, 0xcd, 0x5c, 0x97, | |
148 0x3e, 0x8c, 0x64, 0x43, 0xb3, 0xe0, 0x73, 0x1c, 0x89, 0xd5, 0x83, 0x60, | |
149 0x8c, 0xa7, 0xc7, 0x57, 0x8f, 0xc1, 0x62, 0x0a, 0x65, 0x5e, 0x80, 0x66, | |
150 0x76, 0xb8, 0x69, 0x71, 0x6a, 0x00, 0x3a, 0xda, 0x26, 0x07, 0x9e, 0x9e, | |
151 0x9f, 0x39, 0x62, 0x98, 0x6f, 0x76, 0x84, 0xbc, 0x8b, 0xd0, 0x12, 0x41, | |
152 0x2e, 0x1e, 0xca, 0x58, 0xae, 0x36, 0x9a, 0x1f, 0x10, 0x6b, 0x95, 0xda, | |
153 0x93, 0x34, 0x41, 0xba, 0xc8, 0x02, 0x37, 0x91, 0xb7, 0x28, 0x2a, 0xc5, | |
154 0x61, 0xc6, 0x2d, 0xd0, 0x27, 0xa2, 0xeb, 0xbc, 0x51, 0xe4, 0xf2, 0x79, | |
155 0x14, 0x2f, 0x13, 0x0a, 0xb1, 0x77, 0x0f, 0x01, 0x9a, 0xf9, 0x92, 0x2a, | |
156 0x98, 0xb7, 0x64, 0xf2, 0xef, 0x7d, 0xb8, 0x11, 0x25, 0x2d, 0xb9, 0xce, | |
157 0x9b, 0xb2, 0x4c, 0xde, 0x5b, 0x1e, 0x33, 0x6e, 0xa9, 0x1b, 0xbf, 0x8b, | |
158 0x1c, 0x9a, 0x00, 0x3b, 0x28, 0x13, 0x00, 0x5c, 0x3c, 0x3b, 0x69, 0x50, | |
159 0x5e, 0xb6, 0xfd, 0x98 | |
160 ])).buffer; | |
161 | |
162 // Pretend to support all types of hashes. | |
163 var TEST_CERTIFICATE_SUPPORTED_HASHES = | |
pmarko
2017/05/11 18:24:42
Should we refer to chrome/common/extensions/api/ce
emaxx
2017/05/11 20:12:30
Done. Decided to refer to the public documentation
| |
164 ['MD5_SHA1', 'SHA1', 'SHA256', 'SHA384', 'SHA512']; | |
165 | |
166 // The expected PIN code. | |
167 var VALID_PIN = '1234'; | |
168 | |
169 // The number of wrong attempts after which requesting the PIN will be stopped. | |
170 var MAXIMUM_PIN_FAILED_ATTEMPT_COUNT = 3; | |
171 | |
172 // Data that is used as a response for the sign digest request. This data is | |
173 // random and invalid (as obtaining the real signature requires bundling the | |
174 // extension with a private key and with a piece of cryptographic code). | |
175 var FAKE_SIGN_DIGEST_REQUEST_RESPONSE = (new Uint8Array([1, 2, 3])).buffer; | |
176 | |
177 | |
178 function log(message) { | |
179 console.log('[Sign-in Screen Test App] ' + message); | |
180 } | |
181 | |
182 function logError(message) { | |
183 console.error('[Sign-in Screen Test App] ' + message); | |
184 } | |
185 | |
186 // Returns the text dump of the array of objects of CertificateInfo type from | |
187 // the chrome.certificateProvider API. | |
188 function dumpCertificateInfos(certificateInfos) { | |
189 var transformedList = certificateInfos.map(function(certificateInfo) { | |
190 var transformedItem = Object.assign({}, certificateInfo); | |
191 transformedItem.certificate = | |
192 Array.from(new Uint8Array(certificateInfo.certificate)); | |
193 return transformedItem; | |
194 }); | |
195 return JSON.stringify(transformedList); | |
196 } | |
197 | |
198 function dumpArrayBuffer(arrayBuffer) { | |
199 return '[' + (new Uint8Array(arrayBuffer)) + ']'; | |
200 } | |
201 | |
202 function arrayBufferEquals(firstArrayBuffer, secondArrayBuffer) { | |
203 return dumpArrayBuffer(firstArrayBuffer) == | |
204 dumpArrayBuffer(secondArrayBuffer); | |
205 } | |
206 | |
207 // Listener for the chrome.certificateProvider.onCertificatesRequested event. | |
208 function certificatesRequestedListener(reportCallback) { | |
209 log('The onCertificatesRequested event received'); | |
210 var response = [{ | |
211 certificate: TEST_CERTIFICATE, | |
212 supportedHashes: TEST_CERTIFICATE_SUPPORTED_HASHES | |
213 }]; | |
214 log('Responding with ' + response.length + | |
215 ' certificate(s): ' + dumpCertificateInfos(response)); | |
216 reportCallback(response, function(rejectedCertificates) { | |
217 if (chrome.runtime.lastError) { | |
218 logError( | |
219 'Failed to report the certificates: ' + | |
220 chrome.runtime.lastError.message); | |
221 return; | |
222 } | |
223 if (rejectedCertificates.length) { | |
224 logError( | |
225 rejectedCertificates.length + ' certificate(s) were rejected: ' + | |
226 dumpCertificateInfos(rejectedCertificates)); | |
pmarko
2017/05/11 18:24:43
nit: This seems to be an array of the certificates
emaxx
2017/05/11 20:12:30
Oh, good catch. Fixed.
| |
227 return; | |
228 } | |
229 log('Successfully reported the certificates'); | |
230 }); | |
231 } | |
232 | |
233 // Listener for the chrome.certificateProvider.onSignDigestRequested event. | |
234 function signDigestRequestedListener(request, reportCallback) { | |
235 log('The onSignDigestRequested event received: signRequestId=' + | |
236 request.signRequestId + ', digest=' + dumpArrayBuffer(request.digest) + | |
237 ', hash="' + request.hash + | |
238 '", certificate=' + dumpArrayBuffer(request.certificate)); | |
239 if (!arrayBufferEquals(request.certificate, TEST_CERTIFICATE)) { | |
240 logError('The signing request refers to an unknown certificate'); | |
241 abandonSignRequest(request, reportCallback); | |
242 return; | |
243 } | |
244 inputPinAndProcessSignRequest( | |
245 1 /* attemptNumber */, null /* errorType */, request, reportCallback); | |
246 } | |
247 | |
248 // Requests the PIN from the user and responds to the sign digest request - with | |
249 // some data if the PIN was entered successfully, or with an error otherwise. | |
250 function inputPinAndProcessSignRequest( | |
251 attemptNumber, errorType, signRequest, signRequestReportCallback) { | |
252 requestPin( | |
253 signRequest.signRequestId, attemptNumber, errorType, function(userInput) { | |
254 if (chrome.runtime.lastError) { | |
255 logError( | |
256 'The PIN request failed: ' + chrome.runtime.lastError.message); | |
257 abandonSignRequest(signRequest, signRequestReportCallback); | |
258 return; | |
259 } | |
260 log('The PIN dialog returned "' + userInput + '"'); | |
261 if (userInput == VALID_PIN) { | |
262 log('The entered PIN is correct'); | |
263 stopPinRequest(null /* errorType */, signRequest.signRequestId); | |
264 processSignRequestWithValidPin( | |
265 signRequest, signRequestReportCallback); | |
266 } else if (attemptNumber < MAXIMUM_PIN_FAILED_ATTEMPT_COUNT) { | |
267 log('The entered PIN is wrong, showing the dialog again'); | |
268 inputPinAndProcessSignRequest( | |
269 attemptNumber + 1, 'INVALID_PIN', signRequest, | |
270 signRequestReportCallback); | |
271 } else { | |
272 log('The entered PIN is wrong, and no attempts left'); | |
273 stopPinRequest('MAX_ATTEMPTS_EXCEEDED', signRequest.signRequestId); | |
274 abandonSignRequest(signRequest, signRequestReportCallback); | |
275 } | |
276 }); | |
277 } | |
278 | |
279 // Requests the PIN from the user by displaying the PIN dialog. The passed | |
280 // callback will be called with the string entered by the user, or with null in | |
281 // case of an error. | |
282 function requestPin(signRequestId, attemptNumber, errorType, callback) { | |
283 var parameters = {signRequestId: signRequestId}; | |
284 if (errorType) { | |
285 parameters.errorType = errorType; | |
286 parameters.attemptsLeft = | |
287 MAXIMUM_PIN_FAILED_ATTEMPT_COUNT - attemptNumber + 1; | |
288 } | |
289 log('Requesting PIN with parameters ' + JSON.stringify(parameters)); | |
290 chrome.certificateProvider.requestPin(parameters, function(result) { | |
291 callback(result ? result.userInput : null); | |
292 }); | |
293 } | |
294 | |
295 // Stops the PIN request: if there is no error passed, the PIN dialog is closed; | |
pmarko
2017/05/11 18:24:42
nit: if no error is passed (null)
emaxx
2017/05/11 20:12:30
Done.
| |
296 // if there is some, then it will be displayed in the inputless dialog. | |
pmarko
2017/05/11 18:24:43
What does inputless mean here?
emaxx
2017/05/11 20:12:30
Reworded this to a clearer "the dialog that allows
| |
297 function stopPinRequest(errorType, signRequestId) { | |
298 var parameters = {signRequestId: signRequestId}; | |
299 if (errorType) | |
300 parameters.errorType = errorType; | |
301 log('Stopping the PIN request with parameters ' + JSON.stringify(parameters)); | |
302 chrome.certificateProvider.stopPinRequest(parameters, function() { | |
303 if (chrome.runtime.lastError) { | |
304 logError( | |
305 'Failed to stop the PIN request: ' + | |
306 chrome.runtime.lastError.message); | |
307 return; | |
308 } | |
309 log('Successfully stopped the PIN request'); | |
310 }); | |
311 } | |
312 | |
313 // Responds to the signing request after the PIN was entered correctly. | |
314 function processSignRequestWithValidPin( | |
315 signRequest, signRequestReportCallback) { | |
316 log('Responding to the signing request with a fake data'); | |
317 signRequestReportCallback(FAKE_SIGN_DIGEST_REQUEST_RESPONSE); | |
318 } | |
319 | |
320 // Responds to the signing request with an error, which unblocks Chrome from | |
321 // waiting for the response from this extension. | |
322 function abandonSignRequest(signRequest, signRequestReportCallback) { | |
323 log('Responding to the signing request with an error'); | |
324 signRequestReportCallback(); | |
325 } | |
326 | |
327 | |
328 log('Loaded'); | |
329 if (chrome.certificateProvider) { | |
330 chrome.certificateProvider.onCertificatesRequested.addListener( | |
331 certificatesRequestedListener); | |
332 chrome.certificateProvider.onSignDigestRequested.addListener( | |
333 signDigestRequestedListener); | |
334 log('Successfully set up listeners for the certificateProvider API'); | |
335 } else { | |
336 logError('The certificateProvider API is unavailable'); | |
337 } | |
OLD | NEW |