@@ -28,9 +28,9 @@ const WebAuthnTablePK = "uuid"
28
28
// have this in its ID field.
29
29
const LegacyU2FCredID = "u2f"
30
30
31
- // DynamoUser holds user data from DynamoDB, in both encrypted and unencrypted form. It also holds a Webauthn client
31
+ // WebauthnUser holds user data from DynamoDB, in both encrypted and unencrypted form. It also holds a Webauthn client
32
32
// and Webauthn API data.
33
- type DynamoUser struct {
33
+ type WebauthnUser struct {
34
34
// Shared fields between U2F and WebAuthn
35
35
ID string `dynamodbav:"uuid" json:"uuid"`
36
36
ApiKeyValue string `dynamodbav:"apiKey" json:"apiKey"`
@@ -59,9 +59,9 @@ type DynamoUser struct {
59
59
Icon string `dynamodbav:"-" json:"-"`
60
60
}
61
61
62
- // NewDynamoUser creates a new DynamoUser from API input data, a storage client and a Webauthn client.
63
- func NewDynamoUser (apiConfig ApiMeta , storage * Storage , apiKey ApiKey , webAuthnClient * webauthn.WebAuthn ) DynamoUser {
64
- u := DynamoUser {
62
+ // 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 {
64
+ u := WebauthnUser {
65
65
ID : apiConfig .UserUUID ,
66
66
Name : apiConfig .Username ,
67
67
DisplayName : apiConfig .UserDisplayName ,
@@ -85,7 +85,7 @@ func NewDynamoUser(apiConfig ApiMeta, storage *Storage, apiKey ApiKey, webAuthnC
85
85
86
86
// RemoveU2F clears U2F fields in the user struct. To be used when a user has requested removal of their legacy U2F key.
87
87
// Should be followed by a database store operation.
88
- func (u * DynamoUser ) RemoveU2F () {
88
+ func (u * WebauthnUser ) RemoveU2F () {
89
89
u .AppId = ""
90
90
u .EncryptedAppId = ""
91
91
u .KeyHandle = ""
@@ -95,14 +95,14 @@ func (u *DynamoUser) RemoveU2F() {
95
95
}
96
96
97
97
// unsetSessionData clears the encrypted session data from a user and stores the updated record in the database.
98
- func (u * DynamoUser ) unsetSessionData () error {
98
+ func (u * WebauthnUser ) unsetSessionData () error {
99
99
u .EncryptedSessionData = nil
100
100
return u .Store .Store (envConfig .WebauthnTable , u )
101
101
}
102
102
103
103
// saveSessionData encrypts the user's session data and updates the database record.
104
104
// CAUTION: user data is refreshed from the database by this function. Any unsaved data will be lost.
105
- func (u * DynamoUser ) saveSessionData (sessionData webauthn.SessionData ) error {
105
+ func (u * WebauthnUser ) saveSessionData (sessionData webauthn.SessionData ) error {
106
106
// load to be sure working with latest data
107
107
err := u .Load ()
108
108
if err != nil {
@@ -127,7 +127,7 @@ func (u *DynamoUser) saveSessionData(sessionData webauthn.SessionData) error {
127
127
// saveNewCredential appends a new credential to the user's credential list, encrypts the list, and updates the
128
128
// database record.
129
129
// CAUTION: user data is refreshed from the database by this function. Any unsaved data will be lost.
130
- func (u * DynamoUser ) saveNewCredential (credential webauthn.Credential ) error {
130
+ func (u * WebauthnUser ) saveNewCredential (credential webauthn.Credential ) error {
131
131
// load to be sure working with latest data
132
132
err := u .Load ()
133
133
if err != nil {
@@ -153,7 +153,7 @@ func (u *DynamoUser) saveNewCredential(credential webauthn.Credential) error {
153
153
// should be removed (i.e. by matching the string "u2f") then that user is saved with all of its legacy u2f fields
154
154
// blanked out.
155
155
// CAUTION: user data is refreshed from the database by this function. Any unsaved data will be lost.
156
- func (u * DynamoUser ) DeleteCredential (credIDHash string ) (int , error ) {
156
+ func (u * WebauthnUser ) DeleteCredential (credIDHash string ) (int , error ) {
157
157
// load to be sure working with the latest data
158
158
err := u .Load ()
159
159
if err != nil {
@@ -197,7 +197,7 @@ func (u *DynamoUser) DeleteCredential(credIDHash string) (int, error) {
197
197
}
198
198
199
199
// encryptAndStoreCredentials encrypts the user's credential list and updates the database record
200
- func (u * DynamoUser ) encryptAndStoreCredentials () error {
200
+ func (u * WebauthnUser ) encryptAndStoreCredentials () error {
201
201
js , err := json .Marshal (u .Credentials )
202
202
if err != nil {
203
203
return err
@@ -213,7 +213,7 @@ func (u *DynamoUser) encryptAndStoreCredentials() error {
213
213
}
214
214
215
215
// Load refreshes a user object from the database record and decrypts the session data and credential list
216
- func (u * DynamoUser ) Load () error {
216
+ func (u * WebauthnUser ) Load () error {
217
217
err := u .Store .Load (envConfig .WebauthnTable , WebAuthnTablePK , u .ID , u )
218
218
if err != nil {
219
219
return errors .Wrap (err , "failed to load user" )
@@ -262,15 +262,15 @@ func (u *DynamoUser) Load() error {
262
262
}
263
263
264
264
// Delete removes the user from the database
265
- func (u * DynamoUser ) Delete () error {
265
+ func (u * WebauthnUser ) Delete () error {
266
266
return u .Store .Delete (envConfig .WebauthnTable , WebAuthnTablePK , u .ID )
267
267
}
268
268
269
269
// BeginRegistration processes the first half of the Webauthn Registration flow for the user and returns the
270
270
// CredentialCreation data to pass back to the client. User session data is saved in the database.
271
- func (u * DynamoUser ) BeginRegistration () (* protocol.CredentialCreation , error ) {
271
+ func (u * WebauthnUser ) BeginRegistration () (* protocol.CredentialCreation , error ) {
272
272
if u .WebAuthnClient == nil {
273
- return nil , fmt .Errorf ("dynamoUser , %s, missing WebAuthClient in BeginRegistration" , u .Name )
273
+ return nil , fmt .Errorf ("webauthnUser , %s, missing WebAuthClient in BeginRegistration" , u .Name )
274
274
}
275
275
276
276
rrk := false
@@ -295,7 +295,7 @@ func (u *DynamoUser) BeginRegistration() (*protocol.CredentialCreation, error) {
295
295
// FinishRegistration processes the last half of the Webauthn Registration flow for the user and returns the
296
296
// key_handle_hash to pass back to the client. The client should store this value for later use. User session data is
297
297
// cleared from the database.
298
- func (u * DynamoUser ) FinishRegistration (r * http.Request ) (string , error ) {
298
+ func (u * WebauthnUser ) FinishRegistration (r * http.Request ) (string , error ) {
299
299
if r .Body == nil {
300
300
return "" , fmt .Errorf ("request Body may not be nil in FinishRegistration" )
301
301
}
@@ -330,7 +330,7 @@ func (u *DynamoUser) FinishRegistration(r *http.Request) (string, error) {
330
330
331
331
// BeginLogin processes the first half of the Webauthn Authentication flow for the user and returns the
332
332
// CredentialAssertion data to pass back to the client. User session data is saved in the database.
333
- func (u * DynamoUser ) BeginLogin () (* protocol.CredentialAssertion , error ) {
333
+ func (u * WebauthnUser ) BeginLogin () (* protocol.CredentialAssertion , error ) {
334
334
extensions := protocol.AuthenticationExtensions {}
335
335
if u .EncryptedAppId != "" {
336
336
appid , err := u .ApiKey .DecryptLegacy ([]byte (u .EncryptedAppId ))
@@ -356,7 +356,7 @@ func (u *DynamoUser) BeginLogin() (*protocol.CredentialAssertion, error) {
356
356
357
357
// FinishLogin processes the last half of the Webauthn Authentication flow for the user and returns the
358
358
// Credential data to pass back to the client. User session data is untouched by this function.
359
- func (u * DynamoUser ) FinishLogin (r * http.Request ) (* webauthn.Credential , error ) {
359
+ func (u * WebauthnUser ) FinishLogin (r * http.Request ) (* webauthn.Credential , error ) {
360
360
if r .Body == nil {
361
361
return nil , fmt .Errorf ("request Body may not be nil in FinishLogin" )
362
362
}
@@ -400,27 +400,27 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
400
400
}
401
401
402
402
// WebAuthnID returns the user's ID according to the Relying Party
403
- func (u * DynamoUser ) WebAuthnID () []byte {
403
+ func (u * WebauthnUser ) WebAuthnID () []byte {
404
404
return []byte (u .ID )
405
405
}
406
406
407
407
// WebAuthnName returns the user's name according to the Relying Party
408
- func (u * DynamoUser ) WebAuthnName () string {
408
+ func (u * WebauthnUser ) WebAuthnName () string {
409
409
return u .Name
410
410
}
411
411
412
412
// WebAuthnDisplayName returns the display name of the user
413
- func (u * DynamoUser ) WebAuthnDisplayName () string {
413
+ func (u * WebauthnUser ) WebAuthnDisplayName () string {
414
414
return u .DisplayName
415
415
}
416
416
417
417
// WebAuthnIcon returns the user's icon URL
418
- func (u * DynamoUser ) WebAuthnIcon () string {
418
+ func (u * WebauthnUser ) WebAuthnIcon () string {
419
419
return u .Icon
420
420
}
421
421
422
422
// WebAuthnCredentials returns an array of credentials (passkeys) plus a U2F credential if present
423
- func (u * DynamoUser ) WebAuthnCredentials () []webauthn.Credential {
423
+ func (u * WebauthnUser ) WebAuthnCredentials () []webauthn.Credential {
424
424
if u .EncryptedKeyHandle == "" || u .EncryptedPublicKey == "" {
425
425
// no U2F credential found
426
426
return u .Credentials
0 commit comments