OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // The script requests pin infinitely when the dialog is closed, and requests | |
6 // the input again when the PIN is wrong till 3 times. When the correct | |
7 // PIN (1234) is given, the script requests to close the dialog. | |
8 function userInputCallback(codeValue) { | |
9 if(chrome.runtime.lastError != null) { | |
Devlin
2016/10/20 21:20:45
need a space after if (everywhere)
igorcov
2016/10/25 16:38:36
Done.
| |
10 console.error("Error: " + chrome.runtime.lastError.message); | |
Devlin
2016/10/20 21:20:45
It seems like we should be using chrome.test metho
Devlin
2016/10/20 21:20:45
prefer single quotes in js
igorcov
2016/10/25 16:38:36
Done.
igorcov
2016/10/25 16:38:36
Done.
| |
11 return; | |
12 } | |
13 | |
14 if(attempts >= 3) { | |
15 console.info("Returning after maximum attempts exceeded"); | |
16 return; | |
17 } | |
18 | |
19 console.info("UserInput received, value = " + codeValue); | |
20 if (!codeValue || !codeValue.userInput) { | |
21 console.info("User closed the dialog"); | |
22 chrome.certificateProvider.requestPin({signRequestId: 123}, | |
23 userInputCallback); | |
24 return; | |
25 } | |
26 | |
27 var success = (codeValue.userInput == "1234"); // validatePIN(codeValue); | |
28 if (success) { | |
29 console.info("Success"); | |
30 chrome.certificateProvider.stopPinRequest({signRequestId: 123}, | |
31 closeCallback); | |
32 } else { | |
33 attempts++; | |
34 console.info("Invalid PIN"); | |
35 var code = attempts < 3 ? | |
36 {signRequestId: 123, errorType: "INVALID_PIN"} : | |
37 {signRequestId: 123, requestType: "PUK", | |
38 errorType: "MAX_ATTEMPTS_EXCEEDED", | |
39 attemptsLeft: 0}; | |
40 chrome.certificateProvider.requestPin(code, userInputCallback); | |
41 } | |
42 } | |
43 | |
44 function closeCallback() { | |
45 console.info("Close finished on Chrome side"); | |
46 if(chrome.runtime.lastError != null) { | |
47 console.error("Error: " + chrome.runtime.lastError.message); | |
48 return; | |
49 } | |
50 | |
51 // User authenticated. | |
52 console.info("Successfully authenticated!"); | |
53 } | |
54 | |
55 var attempts = 0; | |
56 chrome.certificateProvider.requestPin({signRequestId: 123}, userInputCallback); | |
OLD | NEW |