-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest-console.ts
More file actions
115 lines (112 loc) · 3.28 KB
/
test-console.ts
File metadata and controls
115 lines (112 loc) · 3.28 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { FIDO2Client } from './index';
import { Fido2Crypto } from './src/crypto/crypto';
import { logger } from './src/log/debug';
import { question } from 'readline-sync';
const client = new FIDO2Client({
defaultModal: false,
event: {
onRequest: async (req) => {
logger.debug(req);
return true;
},
onDeviceAttached: async (device) => {
logger.debug('new device attached', device);
return device;
},
onEnterPin: async () => {
let pin = question('PIN? ', { hideEchoBack: true })
return pin;
},
onSuccess: () => {
logger.debug('request success');
},
onKeepAlive: (status) => {
logger.debug('keep alive with status', status);
},
onDeviceDetached: (device) => {
logger.debug('device detached', device);
},
onPinInvalid: async (retries) => {
logger.debug(`${retries} attempts left`);
let pin = question('PIN? ', { hideEchoBack: true })
return pin;
},
onKeepAliveCancel: () => {
logger.debug('keep alive cancel');
},
onDeviceSelected: (info) => {
logger.debug('device selected', info);
},
onPinAuthBlocked: () => {
logger.debug('pinAuth blocked, please reinsert your key!!');
},
onPinBlocked: () => {
logger.debug('pin blocked, please reset your key!!!!!');
},
onPinValid: () => {
logger.debug('pin valid, nice');
},
onTimeout: () => {
logger.debug('request timeout');
},
onSetPin: async () => {
let pin = question('New PIN? ', { hideEchoBack: true })
return pin;
},
onError: (e) => {
logger.debug('error', e);
}
}
});
client.makeCredential('https://webauthn.cybersecvn.com', {
publicKey: {
rp: {
name: 'vincss',
id: 'webauthn.cybersecvn.com'
},
challenge: Fido2Crypto.random(32),
user: {
name: 'test',
displayName: 'Test',
id: Fido2Crypto.random(32),
icon: 'icon'
},
pubKeyCredParams: [
{
alg: -7,
type: 'public-key'
}, {
type: "public-key",
alg: -257
}
],
authenticatorSelection: {
userVerification: "required"
},
extensions: {
hmacCreateSecret: true
},
timeout: 100000
}
}).then(x => {
logger.debug(x);
client.getAssertion('https://webauthn.cybersecvn.com', {
publicKey: {
rpId: 'webauthn.cybersecvn.com',
challenge: Fido2Crypto.random(32),
allowCredentials: [
{
id: x.rawId,
type: 'public-key'
}
],
userVerification: 'required',
extensions: {
hmacGetSecret: {
salt1: Fido2Crypto.hash(Buffer.from('salt1')),
salt2: Fido2Crypto.hash(Buffer.from('salt2')),
}
}
}
}).then(x => logger.debug(x));
});