@@ -11,6 +11,7 @@ import {
11
11
verifyAuthenticationResponse ,
12
12
verifyRegistrationResponse ,
13
13
} from '@simplewebauthn/server' ;
14
+ import { isoBase64URL } from '@simplewebauthn/server/helpers' ;
14
15
import { AuthenticationResponseJSON , RegistrationResponseJSON } from '@simplewebauthn/types' ;
15
16
16
17
import { expectedOrigin , rpID } from './index' ;
@@ -77,23 +78,8 @@ fetch('https://mds3.fido.tools/getEndpoints', {
77
78
console . log ( '🔐 FIDO Conformance routes ready' ) ;
78
79
} ) ;
79
80
80
- const inMemoryUserDeviceDB : { [ username : string ] : LoggedInFIDOUser } = {
81
- // [username]: string: {
82
- // id: loggedInUserId,
83
-
84
- // devices: [
85
- // /**
86
- // * {
87
- // * credentialID: string,
88
- // * publicKey: string,
89
- // * counter: number,
90
- // * }
91
- // */
92
- // ],
93
- // currentChallenge: undefined,
94
- // currentAuthenticationUserVerification: undefined,
95
- // },
96
- } ;
81
+ const inMemoryUserDB : { [ username : string ] : LoggedInFIDOUser } = { } ;
82
+
97
83
// A cheap way of remembering who's "logged in" between the request for options and the response
98
84
let loggedInUsername : string | undefined = undefined ;
99
85
@@ -126,31 +112,31 @@ fidoConformanceRouter.post('/attestation/options', async (req, res) => {
126
112
127
113
loggedInUsername = username ;
128
114
129
- let user = inMemoryUserDeviceDB [ username ] ;
115
+ let user = inMemoryUserDB [ username ] ;
130
116
if ( ! user ) {
131
117
const newUser = {
132
118
id : username ,
133
119
username,
134
- devices : [ ] ,
120
+ credentials : [ ] ,
135
121
} ;
136
122
137
- inMemoryUserDeviceDB [ username ] = newUser ;
123
+ inMemoryUserDB [ username ] = newUser ;
138
124
user = newUser ;
139
125
}
140
126
141
- const { devices } = user ;
127
+ const { credentials } = user ;
142
128
143
129
const opts = await generateRegistrationOptions ( {
144
130
rpName,
145
131
rpID,
146
- userID : username ,
132
+ userID : isoBase64URL . toBuffer ( username ) ,
147
133
userName : username ,
148
134
userDisplayName : displayName ,
149
135
attestationType : attestation ,
150
136
authenticatorSelection,
151
137
extensions,
152
- excludeCredentials : devices . map ( ( dev ) => ( {
153
- id : dev . credentialID ,
138
+ excludeCredentials : credentials . map ( ( cred ) => ( {
139
+ id : cred . id ,
154
140
type : 'public-key' ,
155
141
transports : [ 'usb' , 'ble' , 'nfc' , 'internal' ] ,
156
142
} ) ) ,
@@ -175,7 +161,7 @@ fidoConformanceRouter.post('/attestation/options', async (req, res) => {
175
161
fidoConformanceRouter . post ( '/attestation/result' , async ( req , res ) => {
176
162
const body : RegistrationResponseJSON = req . body ;
177
163
178
- const user = inMemoryUserDeviceDB [ `${ loggedInUsername } ` ] ;
164
+ const user = inMemoryUserDB [ `${ loggedInUsername } ` ] ;
179
165
180
166
const expectedChallenge = req . session . currentChallenge ;
181
167
@@ -197,18 +183,18 @@ fidoConformanceRouter.post('/attestation/result', async (req, res) => {
197
183
const { verified, registrationInfo } = verification ;
198
184
199
185
if ( verified && registrationInfo ) {
200
- const { credentialPublicKey , credentialID , counter } = registrationInfo ;
186
+ const { credential } = registrationInfo ;
201
187
202
- const existingDevice = user . devices . find ( ( device ) => device . credentialID === credentialID ) ;
188
+ const existingCredential = user . credentials . find ( ( cred ) => cred . id === credential . id ) ;
203
189
204
- if ( ! existingDevice ) {
190
+ if ( ! existingCredential ) {
205
191
/**
206
- * Add the returned device to the user's list of devices
192
+ * Add the returned credential to the user's list of credentials
207
193
*/
208
- user . devices . push ( {
209
- credentialPublicKey ,
210
- credentialID ,
211
- counter,
194
+ user . credentials . push ( {
195
+ id : credential . id ,
196
+ publicKey : credential . publicKey ,
197
+ counter : credential . counter ,
212
198
} ) ;
213
199
}
214
200
}
@@ -228,16 +214,16 @@ fidoConformanceRouter.post('/assertion/options', async (req, res) => {
228
214
229
215
loggedInUsername = username ;
230
216
231
- const user = inMemoryUserDeviceDB [ username ] ;
217
+ const user = inMemoryUserDB [ username ] ;
232
218
233
- const { devices } = user ;
219
+ const { credentials } = user ;
234
220
235
221
const opts = await generateAuthenticationOptions ( {
236
222
rpID,
237
223
extensions,
238
224
userVerification,
239
- allowCredentials : devices . map ( ( dev ) => ( {
240
- id : dev . credentialID ,
225
+ allowCredentials : credentials . map ( ( cred ) => ( {
226
+ id : cred . id ,
241
227
type : 'public-key' ,
242
228
transports : [ 'usb' , 'ble' , 'nfc' , 'internal' ] ,
243
229
} ) ) ,
@@ -257,7 +243,7 @@ fidoConformanceRouter.post('/assertion/result', async (req, res) => {
257
243
const body : AuthenticationResponseJSON = req . body ;
258
244
const { id } = body ;
259
245
260
- const user = inMemoryUserDeviceDB [ `${ loggedInUsername } ` ] ;
246
+ const user = inMemoryUserDB [ `${ loggedInUsername } ` ] ;
261
247
262
248
// Pull up values specified when generation authentication options
263
249
const expectedChallenge = req . session . currentChallenge ;
@@ -269,10 +255,10 @@ fidoConformanceRouter.post('/assertion/result', async (req, res) => {
269
255
return res . status ( 400 ) . send ( { errorMessage : msg } ) ;
270
256
}
271
257
272
- const existingDevice = user . devices . find ( ( device ) => device . credentialID === id ) ;
258
+ const existingCredential = user . credentials . find ( ( cred ) => cred . id === id ) ;
273
259
274
- if ( ! existingDevice ) {
275
- const msg = `Could not find device matching ${ id } ` ;
260
+ if ( ! existingCredential ) {
261
+ const msg = `Could not find credential matching ${ id } ` ;
276
262
console . error ( `RP - authentication: ${ msg } ` ) ;
277
263
return res . status ( 400 ) . send ( { errorMessage : msg } ) ;
278
264
}
@@ -284,7 +270,7 @@ fidoConformanceRouter.post('/assertion/result', async (req, res) => {
284
270
expectedChallenge : `${ expectedChallenge } ` ,
285
271
expectedOrigin,
286
272
expectedRPID : rpID ,
287
- authenticator : existingDevice ,
273
+ credential : existingCredential ,
288
274
advancedFIDOConfig : { userVerification } ,
289
275
requireUserVerification : false ,
290
276
} ) ;
@@ -297,7 +283,7 @@ fidoConformanceRouter.post('/assertion/result', async (req, res) => {
297
283
const { verified, authenticationInfo } = verification ;
298
284
299
285
if ( verified ) {
300
- existingDevice . counter = authenticationInfo . newCounter ;
286
+ existingCredential . counter = authenticationInfo . newCounter ;
301
287
}
302
288
303
289
return res . send ( {
0 commit comments