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

Side by Side Diff: chrome/test/data/extensions/signin_screen_test_app/app/background.js

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

Powered by Google App Engine
This is Rietveld 408576698