forked from emilecantin/node-u2flib-server
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
54 lines (40 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* This is a command-line interface to the library.
*/
var u2f = require('./lib/u2f.js');
var program = require('commander');
program.option('-i, --app-id <string>', 'The application ID (eg.: http://foo.example.com)');
program.command('register-start')
.description('Start the registration process. Outputs the registration challenge JSON.')
.action(function() {
var challenge = u2f.startRegistration(program.appId);
// challenge.json
console.log(JSON.stringify(challenge));
});
program.command('register-end <challengePath> <responsePath>')
.description('Finish the registration process. Outputs the completed registration JSON.')
.action(function(challengePath, responsePath) {
var challenge = require(challengePath);
var response = require(responsePath);
var registration = u2f.finishRegistration(challenge, response);
// registration.json
console.log(JSON.stringify(registration));
});
program.command('authenticate-start <registrationPath>')
.description('Start the authentication process. Outputs the authentication challenge JSON.')
.action(function(registrationPath) {
var registration = require(registrationPath);
var authentication_challenge = u2f.startAuthentication(program.appId, registration);
// authentication_challenge.json
console.log(JSON.stringify(authentication_challenge));
});
program.command('authenticate-end <challengePath> <responsePath> <registrationPath>')
.description('Finish the authentication process. Outputs ????.')
.action(function(challengePath, responsePath, registrationPath) {
var challenge = require(challengePath);
var response = require(responsePath);
var registration = require(registrationPath);
var authentication_result = u2f.finishAuthentication(challenge, response, registration);
console.log(authentication_result);
});
program.parse(process.argv);