forked from passwordless-id/webauthn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.html
254 lines (196 loc) · 10.1 KB
/
playground.html
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/buefy/dist/buefy.min.css">
<link rel="stylesheet" href="theme.css">
</head>
<body>
<main id="app" class="container">
<header class="m-3" style="display:flex; justify-content: center; flex-wrap: wrap;">
<img src="img/banner-playground.svg" alt="banner" style="max-height: 300px" />
<div class="col p-3">
<h1 class="title">Passwordless.ID /</h1>
<h1 class="title">Webauthn Playground</h1>
</div>
</header>
<p class="mt-5 has-text-centered">This is a playground for <a href="https://www.npmjs.com/package/@passwordless-id/webauthn">the webauthn wrapper library</a>. Nothing here is sent to any server, everything runs locally.</p>
<section id="register-browser">
<header class="with-big-icon">
<img src="img/icon_register.svg"/>
<h2 class="title">Registration</h2>
</header>
<b-field label="Username" horizontal custom-class="required">
<b-input v-model="registration.username" placeholder="Username or E-Mail"></b-input>
<div class="hint">A username, email or other identifier</div>
</b-field>
<b-field label="Challenge" horizontal custom-class="required">
<b-field>
<b-input v-model="registration.challenge" placeholder="Challenge" expanded></b-input>
<p class="control">
<b-button type="is-primary" label="↻" @click="registration.challenge = newChallenge()"/>
</p>
</b-field>
<div class="hint">A server-side randomly generated nonce, base64url encoded.</div>
</b-field>
<b-field label="authenticatorType" horizontal>
<b-select v-model="registration.options.authenticatorType" expanded>
<option>auto</option>
<option>local</option>
<option>roaming</option>
<option>both</option>
</b-select>
<div class="hint">Which device to use as authenticator.</div>
</b-field>
<b-field label="Timeout" horizontal>
<b-input v-model="registration.options.timeout" placeholder="60000" expanded></b-input>
<div class="hint">Number of milliseconds the user has to respond to the biometric/PIN check.</div>
</b-field>
<b-field label="userVerification" horizontal>
<b-select v-model="registration.options.userVerification" expanded>
<option>required</option>
<option>preferred</option>
<option>discouraged</option>
</b-select>
<div class="hint">Whether a biometric/PIN check is required or not. This filters out security keys not having this capability.</div>
</b-field>
<b-field label="debug" horizontal>
<b-checkbox v-model="registration.options.debug" expanded></b-checkbox>
</b-field>
<b-field label="attestation" horizontal>
<b-checkbox v-model="registration.options.attestation" expanded></b-checkbox>
<div class="hint">
<p>If enabled, the device attestation and clientData will be provided as base64 encoded binary data. Not
available on some platforms.</p>
</div>
</b-field>
<pre>await client.register("{{registration.username}}", "{{registration.challenge}}", {{registration.options}})</pre>
<b-button class="my-3" type="is-primary" @click="register()">Register device</b-button>
<pre>{{registration.result ?? '...'}}</pre>
<hr/>
<p>And on the server side, verifying the registration leads to:</p>
<pre>await server.verifyRegistration(registration, {challenge: "{{registration.challenge}}", origin: "{{origin}}"})</pre>
<p>Resulting into:</p>
<pre>{{registration.parsed ?? '...'}}</pre>
<div class="notification is-warning" v-if="registration.parsed">
<p>At this point, you should store the `credential` and associate it with the user account. You will need it later to verify authentication attempts.</p>
</div>
</section>
<section>
<header class="with-big-icon">
<img src="img/icon_authenticate.svg"/>
<h2 class="title">Authentication</h2>
</header>
<b-field label="credentialId" horizontal custom-class="required">
<b-input v-model="authentication.credentialId" placeholder="Credential ID"></b-input>
<div></div>
</b-field>
<b-field label="challenge" horizontal custom-class="required">
<b-field>
<b-input v-model="authentication.challenge" placeholder="Challenge" expanded></b-input>
<p class="control">
<b-button type="is-primary" label="↻" @click="authentication.challenge = newChallenge()"/>
</p>
</b-field>
<div class="hint">A server-side randomly generated nonce, base64url encoded.</div>
</b-field>
<b-field label="authenticatorType" horizontal>
<b-select v-model="authentication.options.authenticatorType" expanded>
<option>auto</option>
<option>local</option>
<option>roaming</option>
<option>both</option>
</b-select>
<div class="hint">Which device to use as authenticator.</div>
</b-field>
<b-field label="timeout" horizontal>
<b-input v-model="authentication.options.timeout" placeholder="60000" expanded></b-input>
<div class="hint">Number of milliseconds the user has to respond to the biometric/PIN check.</div>
</b-field>
<b-field label="userVerification" horizontal>
<b-select v-model="authentication.options.userVerification" expanded>
<option>required</option>
<option>preferred</option>
<option>discouraged</option>
</b-select>
<div class="hint">Whether a biometric/PIN check is required or not. This filters out security keys not having this capability.</div>
</b-field>
<b-field label="debug" horizontal>
<b-checkbox v-model="authentication.options.debug" expanded></b-checkbox>
</b-field>
<pre>webauthn.authenticate(["{{authentication.credentialId}}"], "{{authentication.challenge}}", {{authentication.options}})</pre>
<b-button type="is-primary" @click="login()">Login</b-button>
<pre>{{authentication.result ?? '...'}}</pre>
<hr/>
<p>And on the server side, verifying the authentication leads to:</p>
<pre>
const credentialKey = {
id: "{{registration?.parsed?.credential?.id ?? '...'}}",
publicKey: "{{registration?.parsed?.credential?.publicKey ?? '...'}}",
algorithm: "{{registration?.parsed?.credential?.algorithm ?? '...'}}"
}
const expected = {
challenge: "{{authentication?.challenge ?? '...'}}",
origin: "{{origin}}",
userVerified: {{authentication?.options?.userVerification === 'required'}},
counter: 0
}
const verified = await server.verifyAuthentication(res, credentialKey, expected)
</pre>
<p>Resulting into:</p>
<pre>{{authentication.parsed ?? '...'}}</pre>
<div class="notification is-success" v-if="authentication.parsed">
<p>Please note that the parsed result is returned for the sake of completeness. It is already verified, including the signature.</p>
</div>
</section>
<section>
<header class="with-big-icon">
<img src="img/icon_validate.svg"/>
<h2 class="title">Signature validation</h2>
</header>
<p>This part is mainly for debugging purposes or validation.</p>
<hr/>
<b-field label="Algorithm" horizontal>
<b-select v-model="verification.algorithm" expanded>
<option>RS256</option>
<option>ES256</option>
</b-select>
<div class="hint">The algorithm used for the public key created during registration.</div>
</b-field>
<b-field label="PublicKey" horizontal>
<b-input v-model="verification.publicKey" type="textarea"></b-input>
<div class="hint">The public key created during registration.</div>
</b-field>
<hr/>
<b-field label="AuthenticatorData" horizontal>
<b-input v-model="verification.authenticatorData" type="textarea"></b-input>
<div class="hint"><pre v-if="verification.authenticatorData">{{parseAuthData(verification.authenticatorData)}}</pre></div>
</b-field>
<b-field label="ClientData" horizontal>
<b-input v-model="verification.clientData" type="textarea"></b-input>
<div class="hint"><pre v-if="verification.clientData">{{parseClientData(verification.clientData)}}</pre></div>
</b-field>
<b-field label="Signature" horizontal>
<b-input v-model="verification.signature" type="textarea"></b-input>
<div class="hint">
<p>signature = sign(algorithm, publicKey, authenticatorData + sha256(clientData))</p>
</div>
</b-field>
<b-field horizontal>
<b-button type="is-primary" @click="verifySignature()">Verify</b-button>
<div class="hint message" :class="{'is-success': verification.isValid, 'is-danger': !verification.isValid}"
v-if="verification.isValid !== null">
<div class="message-body">
Signature is {{verification.isValid ? 'valid' : 'invalid'}}
</div>
</div>
</b-field>
</section>
</main>
<script src="https://unpkg.com/vue@2"></script>
<script src="https://unpkg.com/buefy/dist/buefy.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="module" src="js/playground.js"></script>
</body>
</html>