@@ -53,23 +53,21 @@ type WebauthnUser struct {
53
53
Credentials []webauthn.Credential `dynamodbav:"-" json:"-"`
54
54
EncryptedCredentials []byte `dynamodbav:"EncryptedCredentials" json:"EncryptedCredentials,omitempty"`
55
55
56
- WebAuthnClient * webauthn.WebAuthn `dynamodbav:"-" json:"-"`
57
- Name string `dynamodbav:"-" json:"-"`
58
- DisplayName string `dynamodbav:"-" json:"-"`
59
- Icon string `dynamodbav:"-" json:"-"`
56
+ Name string `dynamodbav:"-" json:"-"`
57
+ DisplayName string `dynamodbav:"-" json:"-"`
58
+ Icon string `dynamodbav:"-" json:"-"`
60
59
}
61
60
62
61
// NewWebauthnUser creates a new WebauthnUser from API input data, a storage client and a Webauthn client.
63
- func NewWebauthnUser (apiConfig ApiMeta , storage * Storage , apiKey ApiKey , webAuthnClient * webauthn. WebAuthn ) WebauthnUser {
62
+ func NewWebauthnUser (apiConfig ApiMeta , storage * Storage , apiKey ApiKey ) WebauthnUser {
64
63
u := WebauthnUser {
65
- ID : apiConfig .UserUUID ,
66
- Name : apiConfig .Username ,
67
- DisplayName : apiConfig .UserDisplayName ,
68
- Icon : apiConfig .UserIcon ,
69
- Store : storage ,
70
- WebAuthnClient : webAuthnClient ,
71
- ApiKey : apiKey ,
72
- ApiKeyValue : apiKey .Key ,
64
+ ID : apiConfig .UserUUID ,
65
+ Name : apiConfig .Username ,
66
+ DisplayName : apiConfig .UserDisplayName ,
67
+ Icon : apiConfig .UserIcon ,
68
+ Store : storage ,
69
+ ApiKey : apiKey ,
70
+ ApiKeyValue : apiKey .Key ,
73
71
}
74
72
75
73
if u .ID == "" {
@@ -268,18 +266,14 @@ func (u *WebauthnUser) Delete() error {
268
266
269
267
// BeginRegistration processes the first half of the Webauthn Registration flow for the user and returns the
270
268
// CredentialCreation data to pass back to the client. User session data is saved in the database.
271
- func (u * WebauthnUser ) BeginRegistration () (* protocol.CredentialCreation , error ) {
272
- if u .WebAuthnClient == nil {
273
- return nil , fmt .Errorf ("webauthnUser, %s, missing WebAuthClient in BeginRegistration" , u .Name )
274
- }
275
-
269
+ func (u * WebauthnUser ) BeginRegistration (client * webauthn.WebAuthn ) (* protocol.CredentialCreation , error ) {
276
270
rrk := false
277
271
authSelection := protocol.AuthenticatorSelection {
278
272
RequireResidentKey : & rrk ,
279
273
UserVerification : protocol .VerificationDiscouraged ,
280
274
}
281
275
282
- options , sessionData , err := u . WebAuthnClient .BeginRegistration (u , webauthn .WithAuthenticatorSelection (authSelection ))
276
+ options , sessionData , err := client .BeginRegistration (u , webauthn .WithAuthenticatorSelection (authSelection ))
283
277
if err != nil {
284
278
return & protocol.CredentialCreation {}, fmt .Errorf ("failed to begin registration: %w" , err )
285
279
}
@@ -295,7 +289,7 @@ func (u *WebauthnUser) BeginRegistration() (*protocol.CredentialCreation, error)
295
289
// FinishRegistration processes the last half of the Webauthn Registration flow for the user and returns the
296
290
// key_handle_hash to pass back to the client. The client should store this value for later use. User session data is
297
291
// cleared from the database.
298
- func (u * WebauthnUser ) FinishRegistration (r * http.Request ) (string , error ) {
292
+ func (u * WebauthnUser ) FinishRegistration (r * http.Request , client * webauthn. WebAuthn ) (string , error ) {
299
293
if r .Body == nil {
300
294
return "" , fmt .Errorf ("request Body may not be nil in FinishRegistration" )
301
295
}
@@ -312,7 +306,7 @@ func (u *WebauthnUser) FinishRegistration(r *http.Request) (string, error) {
312
306
return "" , fmt .Errorf ("unable to parse credential creation response body: %w" , err )
313
307
}
314
308
315
- credential , err := u . WebAuthnClient .CreateCredential (u , u .SessionData , parsedResponse )
309
+ credential , err := client .CreateCredential (u , u .SessionData , parsedResponse )
316
310
if err != nil {
317
311
logProtocolError ("unable to create credential" , err )
318
312
return "" , fmt .Errorf ("unable to create credential: %w" , err )
@@ -330,7 +324,7 @@ func (u *WebauthnUser) FinishRegistration(r *http.Request) (string, error) {
330
324
331
325
// BeginLogin processes the first half of the Webauthn Authentication flow for the user and returns the
332
326
// CredentialAssertion data to pass back to the client. User session data is saved in the database.
333
- func (u * WebauthnUser ) BeginLogin () (* protocol.CredentialAssertion , error ) {
327
+ func (u * WebauthnUser ) BeginLogin (client * webauthn. WebAuthn ) (* protocol.CredentialAssertion , error ) {
334
328
extensions := protocol.AuthenticationExtensions {}
335
329
if u .EncryptedAppId != "" {
336
330
appid , err := u .ApiKey .DecryptLegacy ([]byte (u .EncryptedAppId ))
@@ -340,7 +334,7 @@ func (u *WebauthnUser) BeginLogin() (*protocol.CredentialAssertion, error) {
340
334
extensions ["appid" ] = string (appid )
341
335
}
342
336
343
- options , sessionData , err := u . WebAuthnClient .BeginLogin (u , webauthn .WithAssertionExtensions (extensions ), webauthn .WithUserVerification (protocol .VerificationDiscouraged ))
337
+ options , sessionData , err := client .BeginLogin (u , webauthn .WithAssertionExtensions (extensions ), webauthn .WithUserVerification (protocol .VerificationDiscouraged ))
344
338
if err != nil {
345
339
return & protocol.CredentialAssertion {}, err
346
340
}
@@ -356,7 +350,7 @@ func (u *WebauthnUser) BeginLogin() (*protocol.CredentialAssertion, error) {
356
350
357
351
// FinishLogin processes the last half of the Webauthn Authentication flow for the user and returns the
358
352
// Credential data to pass back to the client. User session data is untouched by this function.
359
- func (u * WebauthnUser ) FinishLogin (r * http.Request ) (* webauthn.Credential , error ) {
353
+ func (u * WebauthnUser ) FinishLogin (r * http.Request , client * webauthn. WebAuthn ) (* webauthn.Credential , error ) {
360
354
if r .Body == nil {
361
355
return nil , fmt .Errorf ("request Body may not be nil in FinishLogin" )
362
356
}
@@ -383,14 +377,14 @@ func (u *WebauthnUser) FinishLogin(r *http.Request) (*webauthn.Credential, error
383
377
}
384
378
385
379
appIdHash := sha256 .Sum256 (appid )
386
- rpIdHash := sha256 .Sum256 ([]byte (u . WebAuthnClient .Config .RPID ))
380
+ rpIdHash := sha256 .Sum256 ([]byte (client .Config .RPID ))
387
381
388
382
if fmt .Sprintf ("%x" , parsedResponse .Response .AuthenticatorData .RPIDHash ) == fmt .Sprintf ("%x" , appIdHash ) {
389
383
parsedResponse .Response .AuthenticatorData .RPIDHash = rpIdHash [:]
390
384
}
391
385
}
392
386
393
- credential , err := u . WebAuthnClient .ValidateLogin (u , u .SessionData , parsedResponse )
387
+ credential , err := client .ValidateLogin (u , u .SessionData , parsedResponse )
394
388
if err != nil {
395
389
logProtocolError ("failed to validate login" , err )
396
390
return & webauthn.Credential {}, fmt .Errorf ("failed to validate login: %w" , err )
0 commit comments