diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2023-04-15 02:04:42 +1000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-15 02:04:42 +1000 | 
| commit | 2733fc040cc43269889f5e11fd64c1fdb2e09ebd (patch) | |
| tree | 2459462966d202d1177fb166a83a476c2e9c5a51 /internal/storage | |
| parent | 37a49b21af4550525890a84b5a7ccf6f1ed51243 (diff) | |
refactor: webauthn naming (#5243)
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/storage')
| -rw-r--r-- | internal/storage/const.go | 2 | ||||
| -rw-r--r-- | internal/storage/errors.go | 4 | ||||
| -rw-r--r-- | internal/storage/provider.go | 12 | ||||
| -rw-r--r-- | internal/storage/sql_provider.go | 98 | ||||
| -rw-r--r-- | internal/storage/sql_provider_backend_postgres.go | 16 | ||||
| -rw-r--r-- | internal/storage/sql_provider_encryption.go | 34 | ||||
| -rw-r--r-- | internal/storage/sql_provider_queries.go | 22 | ||||
| -rw-r--r-- | internal/storage/types.go | 2 | 
8 files changed, 95 insertions, 95 deletions
diff --git a/internal/storage/const.go b/internal/storage/const.go index a5e4bf8ae..286d39620 100644 --- a/internal/storage/const.go +++ b/internal/storage/const.go @@ -11,7 +11,7 @@ const (  	tableTOTPConfigurations   = "totp_configurations"  	tableUserOpaqueIdentifier = "user_opaque_identifier"  	tableUserPreferences      = "user_preferences" -	tableWebauthnDevices      = "webauthn_devices" +	tableWebAuthnDevices      = "webauthn_devices"  	tableOAuth2BlacklistedJTI          = "oauth2_blacklisted_jti"  	tableOAuth2ConsentSession          = "oauth2_consent_session" diff --git a/internal/storage/errors.go b/internal/storage/errors.go index f3098f643..412a4b5ac 100644 --- a/internal/storage/errors.go +++ b/internal/storage/errors.go @@ -11,8 +11,8 @@ var (  	// ErrNoTOTPConfiguration error thrown when no TOTP configuration has been found in DB.  	ErrNoTOTPConfiguration = errors.New("no TOTP configuration for user") -	// ErrNoWebauthnDevice error thrown when no Webauthn device handle has been found in DB. -	ErrNoWebauthnDevice = errors.New("no Webauthn device found") +	// ErrNoWebAuthnDevice error thrown when no WebAuthn device handle has been found in DB. +	ErrNoWebAuthnDevice = errors.New("no WebAuthn device found")  	// ErrNoDuoDevice error thrown when no Duo device and method has been found in DB.  	ErrNoDuoDevice = errors.New("no Duo device and method saved") diff --git a/internal/storage/provider.go b/internal/storage/provider.go index 68e939a04..651cdadfa 100644 --- a/internal/storage/provider.go +++ b/internal/storage/provider.go @@ -38,12 +38,12 @@ type Provider interface {  	LoadTOTPConfiguration(ctx context.Context, username string) (config *model.TOTPConfiguration, err error)  	LoadTOTPConfigurations(ctx context.Context, limit, page int) (configs []model.TOTPConfiguration, err error) -	SaveWebauthnDevice(ctx context.Context, device model.WebAuthnDevice) (err error) -	UpdateWebauthnDeviceSignIn(ctx context.Context, id int, rpid string, lastUsedAt sql.NullTime, signCount uint32, cloneWarning bool) (err error) -	DeleteWebauthnDevice(ctx context.Context, kid string) (err error) -	DeleteWebauthnDeviceByUsername(ctx context.Context, username, description string) (err error) -	LoadWebauthnDevices(ctx context.Context, limit, page int) (devices []model.WebAuthnDevice, err error) -	LoadWebauthnDevicesByUsername(ctx context.Context, username string) (devices []model.WebAuthnDevice, err error) +	SaveWebAuthnDevice(ctx context.Context, device model.WebAuthnDevice) (err error) +	UpdateWebAuthnDeviceSignIn(ctx context.Context, id int, rpid string, lastUsedAt sql.NullTime, signCount uint32, cloneWarning bool) (err error) +	DeleteWebAuthnDevice(ctx context.Context, kid string) (err error) +	DeleteWebAuthnDeviceByUsername(ctx context.Context, username, description string) (err error) +	LoadWebAuthnDevices(ctx context.Context, limit, page int) (devices []model.WebAuthnDevice, err error) +	LoadWebAuthnDevicesByUsername(ctx context.Context, username string) (devices []model.WebAuthnDevice, err error)  	SavePreferredDuoDevice(ctx context.Context, device model.DuoDevice) (err error)  	DeletePreferredDuoDevice(ctx context.Context, username string) (err error) diff --git a/internal/storage/sql_provider.go b/internal/storage/sql_provider.go index 7467114a8..0c4d6376e 100644 --- a/internal/storage/sql_provider.go +++ b/internal/storage/sql_provider.go @@ -46,16 +46,16 @@ func NewSQLProvider(config *schema.Configuration, name, driverName, dataSourceNa  		sqlUpdateTOTPConfigRecordSignIn:           fmt.Sprintf(queryFmtUpdateTOTPConfigRecordSignIn, tableTOTPConfigurations),  		sqlUpdateTOTPConfigRecordSignInByUsername: fmt.Sprintf(queryFmtUpdateTOTPConfigRecordSignInByUsername, tableTOTPConfigurations), -		sqlUpsertWebauthnDevice:            fmt.Sprintf(queryFmtUpsertWebauthnDevice, tableWebauthnDevices), -		sqlSelectWebauthnDevices:           fmt.Sprintf(queryFmtSelectWebauthnDevices, tableWebauthnDevices), -		sqlSelectWebauthnDevicesByUsername: fmt.Sprintf(queryFmtSelectWebauthnDevicesByUsername, tableWebauthnDevices), +		sqlUpsertWebAuthnDevice:            fmt.Sprintf(queryFmtUpsertWebAuthnDevice, tableWebAuthnDevices), +		sqlSelectWebAuthnDevices:           fmt.Sprintf(queryFmtSelectWebAuthnDevices, tableWebAuthnDevices), +		sqlSelectWebAuthnDevicesByUsername: fmt.Sprintf(queryFmtSelectWebAuthnDevicesByUsername, tableWebAuthnDevices), -		sqlUpdateWebauthnDeviceRecordSignIn:           fmt.Sprintf(queryFmtUpdateWebauthnDeviceRecordSignIn, tableWebauthnDevices), -		sqlUpdateWebauthnDeviceRecordSignInByUsername: fmt.Sprintf(queryFmtUpdateWebauthnDeviceRecordSignInByUsername, tableWebauthnDevices), +		sqlUpdateWebAuthnDeviceRecordSignIn:           fmt.Sprintf(queryFmtUpdateWebAuthnDeviceRecordSignIn, tableWebAuthnDevices), +		sqlUpdateWebAuthnDeviceRecordSignInByUsername: fmt.Sprintf(queryFmtUpdateWebAuthnDeviceRecordSignInByUsername, tableWebAuthnDevices), -		sqlDeleteWebauthnDevice:                         fmt.Sprintf(queryFmtDeleteWebauthnDevice, tableWebauthnDevices), -		sqlDeleteWebauthnDeviceByUsername:               fmt.Sprintf(queryFmtDeleteWebauthnDeviceByUsername, tableWebauthnDevices), -		sqlDeleteWebauthnDeviceByUsernameAndDescription: fmt.Sprintf(queryFmtDeleteWebauthnDeviceByUsernameAndDescription, tableWebauthnDevices), +		sqlDeleteWebAuthnDevice:                         fmt.Sprintf(queryFmtDeleteWebAuthnDevice, tableWebAuthnDevices), +		sqlDeleteWebAuthnDeviceByUsername:               fmt.Sprintf(queryFmtDeleteWebAuthnDeviceByUsername, tableWebAuthnDevices), +		sqlDeleteWebAuthnDeviceByUsernameAndDescription: fmt.Sprintf(queryFmtDeleteWebAuthnDeviceByUsernameAndDescription, tableWebAuthnDevices),  		sqlUpsertDuoDevice: fmt.Sprintf(queryFmtUpsertDuoDevice, tableDuoDevices),  		sqlDeleteDuoDevice: fmt.Sprintf(queryFmtDeleteDuoDevice, tableDuoDevices), @@ -63,7 +63,7 @@ func NewSQLProvider(config *schema.Configuration, name, driverName, dataSourceNa  		sqlUpsertPreferred2FAMethod: fmt.Sprintf(queryFmtUpsertPreferred2FAMethod, tableUserPreferences),  		sqlSelectPreferred2FAMethod: fmt.Sprintf(queryFmtSelectPreferred2FAMethod, tableUserPreferences), -		sqlSelectUserInfo:           fmt.Sprintf(queryFmtSelectUserInfo, tableTOTPConfigurations, tableWebauthnDevices, tableDuoDevices, tableUserPreferences), +		sqlSelectUserInfo:           fmt.Sprintf(queryFmtSelectUserInfo, tableTOTPConfigurations, tableWebAuthnDevices, tableDuoDevices, tableUserPreferences),  		sqlInsertUserOpaqueIdentifier:            fmt.Sprintf(queryFmtInsertUserOpaqueIdentifier, tableUserOpaqueIdentifier),  		sqlSelectUserOpaqueIdentifier:            fmt.Sprintf(queryFmtSelectUserOpaqueIdentifier, tableUserOpaqueIdentifier), @@ -165,16 +165,16 @@ type SQLProvider struct {  	sqlUpdateTOTPConfigRecordSignInByUsername string  	// Table: webauthn_devices. -	sqlUpsertWebauthnDevice            string -	sqlSelectWebauthnDevices           string -	sqlSelectWebauthnDevicesByUsername string +	sqlUpsertWebAuthnDevice            string +	sqlSelectWebAuthnDevices           string +	sqlSelectWebAuthnDevicesByUsername string -	sqlUpdateWebauthnDeviceRecordSignIn           string -	sqlUpdateWebauthnDeviceRecordSignInByUsername string +	sqlUpdateWebAuthnDeviceRecordSignIn           string +	sqlUpdateWebAuthnDeviceRecordSignInByUsername string -	sqlDeleteWebauthnDevice                         string -	sqlDeleteWebauthnDeviceByUsername               string -	sqlDeleteWebauthnDeviceByUsernameAndDescription string +	sqlDeleteWebAuthnDevice                         string +	sqlDeleteWebAuthnDeviceByUsername               string +	sqlDeleteWebAuthnDeviceByUsernameAndDescription string  	// Table: duo_devices.  	sqlUpsertDuoDevice string @@ -823,7 +823,7 @@ func (p *SQLProvider) SaveTOTPConfiguration(ctx context.Context, config model.TO  	return nil  } -// UpdateTOTPConfigurationSignIn updates a registered Webauthn devices sign in information. +// UpdateTOTPConfigurationSignIn updates a registered WebAuthn devices sign in information.  func (p *SQLProvider) UpdateTOTPConfigurationSignIn(ctx context.Context, id int, lastUsedAt sql.NullTime) (err error) {  	if _, err = p.db.ExecContext(ctx, p.sqlUpdateTOTPConfigRecordSignIn, lastUsedAt, id); err != nil {  		return fmt.Errorf("error updating TOTP configuration id %d: %w", id, err) @@ -881,95 +881,95 @@ func (p *SQLProvider) LoadTOTPConfigurations(ctx context.Context, limit, page in  	return configs, nil  } -// SaveWebauthnDevice saves a registered Webauthn device. -func (p *SQLProvider) SaveWebauthnDevice(ctx context.Context, device model.WebAuthnDevice) (err error) { +// SaveWebAuthnDevice saves a registered WebAuthn device. +func (p *SQLProvider) SaveWebAuthnDevice(ctx context.Context, device model.WebAuthnDevice) (err error) {  	if device.PublicKey, err = p.encrypt(device.PublicKey); err != nil { -		return fmt.Errorf("error encrypting Webauthn device public key for user '%s' kid '%x': %w", device.Username, device.KID, err) +		return fmt.Errorf("error encrypting WebAuthn device public key for user '%s' kid '%x': %w", device.Username, device.KID, err)  	} -	if _, err = p.db.ExecContext(ctx, p.sqlUpsertWebauthnDevice, +	if _, err = p.db.ExecContext(ctx, p.sqlUpsertWebAuthnDevice,  		device.CreatedAt, device.LastUsedAt,  		device.RPID, device.Username, device.Description,  		device.KID, device.PublicKey,  		device.AttestationType, device.Transport, device.AAGUID, device.SignCount, device.CloneWarning,  	); err != nil { -		return fmt.Errorf("error upserting Webauthn device for user '%s' kid '%x': %w", device.Username, device.KID, err) +		return fmt.Errorf("error upserting WebAuthn device for user '%s' kid '%x': %w", device.Username, device.KID, err)  	}  	return nil  } -// UpdateWebauthnDeviceSignIn updates a registered Webauthn devices sign in information. -func (p *SQLProvider) UpdateWebauthnDeviceSignIn(ctx context.Context, id int, rpid string, lastUsedAt sql.NullTime, signCount uint32, cloneWarning bool) (err error) { -	if _, err = p.db.ExecContext(ctx, p.sqlUpdateWebauthnDeviceRecordSignIn, rpid, lastUsedAt, signCount, cloneWarning, id); err != nil { -		return fmt.Errorf("error updating Webauthn signin metadata for id '%x': %w", id, err) +// UpdateWebAuthnDeviceSignIn updates a registered WebAuthn devices sign in information. +func (p *SQLProvider) UpdateWebAuthnDeviceSignIn(ctx context.Context, id int, rpid string, lastUsedAt sql.NullTime, signCount uint32, cloneWarning bool) (err error) { +	if _, err = p.db.ExecContext(ctx, p.sqlUpdateWebAuthnDeviceRecordSignIn, rpid, lastUsedAt, signCount, cloneWarning, id); err != nil { +		return fmt.Errorf("error updating WebAuthn signin metadata for id '%x': %w", id, err)  	}  	return nil  } -// DeleteWebauthnDevice deletes a registered Webauthn device. -func (p *SQLProvider) DeleteWebauthnDevice(ctx context.Context, kid string) (err error) { -	if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebauthnDevice, kid); err != nil { -		return fmt.Errorf("error deleting webauthn device with kid '%s': %w", kid, err) +// DeleteWebAuthnDevice deletes a registered WebAuthn device. +func (p *SQLProvider) DeleteWebAuthnDevice(ctx context.Context, kid string) (err error) { +	if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebAuthnDevice, kid); err != nil { +		return fmt.Errorf("error deleting WebAuthn device with kid '%s': %w", kid, err)  	}  	return nil  } -// DeleteWebauthnDeviceByUsername deletes registered Webauthn devices by username or username and description. -func (p *SQLProvider) DeleteWebauthnDeviceByUsername(ctx context.Context, username, description string) (err error) { +// DeleteWebAuthnDeviceByUsername deletes registered WebAuthn devices by username or username and description. +func (p *SQLProvider) DeleteWebAuthnDeviceByUsername(ctx context.Context, username, description string) (err error) {  	if len(username) == 0 { -		return fmt.Errorf("error deleting webauthn device with username '%s' and description '%s': username must not be empty", username, description) +		return fmt.Errorf("error deleting WebAuthn device with username '%s' and description '%s': username must not be empty", username, description)  	}  	if len(description) == 0 { -		if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebauthnDeviceByUsername, username); err != nil { -			return fmt.Errorf("error deleting webauthn devices for username '%s': %w", username, err) +		if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebAuthnDeviceByUsername, username); err != nil { +			return fmt.Errorf("error deleting WebAuthn devices for username '%s': %w", username, err)  		}  	} else { -		if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebauthnDeviceByUsernameAndDescription, username, description); err != nil { -			return fmt.Errorf("error deleting webauthn device with username '%s' and description '%s': %w", username, description, err) +		if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebAuthnDeviceByUsernameAndDescription, username, description); err != nil { +			return fmt.Errorf("error deleting WebAuthn device with username '%s' and description '%s': %w", username, description, err)  		}  	}  	return nil  } -// LoadWebauthnDevices loads Webauthn device registrations. -func (p *SQLProvider) LoadWebauthnDevices(ctx context.Context, limit, page int) (devices []model.WebAuthnDevice, err error) { +// LoadWebAuthnDevices loads WebAuthn device registrations. +func (p *SQLProvider) LoadWebAuthnDevices(ctx context.Context, limit, page int) (devices []model.WebAuthnDevice, err error) {  	devices = make([]model.WebAuthnDevice, 0, limit) -	if err = p.db.SelectContext(ctx, &devices, p.sqlSelectWebauthnDevices, limit, limit*page); err != nil { +	if err = p.db.SelectContext(ctx, &devices, p.sqlSelectWebAuthnDevices, limit, limit*page); err != nil {  		if errors.Is(err, sql.ErrNoRows) {  			return nil, nil  		} -		return nil, fmt.Errorf("error selecting Webauthn devices: %w", err) +		return nil, fmt.Errorf("error selecting WebAuthn devices: %w", err)  	}  	for i, device := range devices {  		if devices[i].PublicKey, err = p.decrypt(device.PublicKey); err != nil { -			return nil, fmt.Errorf("error decrypting Webauthn public key for user '%s': %w", device.Username, err) +			return nil, fmt.Errorf("error decrypting WebAuthn public key for user '%s': %w", device.Username, err)  		}  	}  	return devices, nil  } -// LoadWebauthnDevicesByUsername loads all webauthn devices registration for a given username. -func (p *SQLProvider) LoadWebauthnDevicesByUsername(ctx context.Context, username string) (devices []model.WebAuthnDevice, err error) { -	if err = p.db.SelectContext(ctx, &devices, p.sqlSelectWebauthnDevicesByUsername, username); err != nil { +// LoadWebAuthnDevicesByUsername loads all WebAuthn devices registration for a given username. +func (p *SQLProvider) LoadWebAuthnDevicesByUsername(ctx context.Context, username string) (devices []model.WebAuthnDevice, err error) { +	if err = p.db.SelectContext(ctx, &devices, p.sqlSelectWebAuthnDevicesByUsername, username); err != nil {  		if errors.Is(err, sql.ErrNoRows) { -			return nil, ErrNoWebauthnDevice +			return nil, ErrNoWebAuthnDevice  		} -		return nil, fmt.Errorf("error selecting Webauthn devices for user '%s': %w", username, err) +		return nil, fmt.Errorf("error selecting WebAuthn devices for user '%s': %w", username, err)  	}  	for i, device := range devices {  		if devices[i].PublicKey, err = p.decrypt(device.PublicKey); err != nil { -			return nil, fmt.Errorf("error decrypting Webauthn public key for user '%s': %w", username, err) +			return nil, fmt.Errorf("error decrypting WebAuthn public key for user '%s': %w", username, err)  		}  	} diff --git a/internal/storage/sql_provider_backend_postgres.go b/internal/storage/sql_provider_backend_postgres.go index bc6387a38..252ec3e0e 100644 --- a/internal/storage/sql_provider_backend_postgres.go +++ b/internal/storage/sql_provider_backend_postgres.go @@ -31,7 +31,7 @@ func NewPostgreSQLProvider(config *schema.Configuration, caCertPool *x509.CertPo  	// Specific alterations to this provider.  	// PostgreSQL doesn't have a UPSERT statement but has an ON CONFLICT operation instead. -	provider.sqlUpsertWebauthnDevice = fmt.Sprintf(queryFmtUpsertWebauthnDevicePostgreSQL, tableWebauthnDevices) +	provider.sqlUpsertWebAuthnDevice = fmt.Sprintf(queryFmtUpsertWebAuthnDevicePostgreSQL, tableWebAuthnDevices)  	provider.sqlUpsertDuoDevice = fmt.Sprintf(queryFmtUpsertDuoDevicePostgreSQL, tableDuoDevices)  	provider.sqlUpsertTOTPConfig = fmt.Sprintf(queryFmtUpsertTOTPConfigurationPostgreSQL, tableTOTPConfigurations)  	provider.sqlUpsertPreferred2FAMethod = fmt.Sprintf(queryFmtUpsertPreferred2FAMethodPostgreSQL, tableUserPreferences) @@ -59,13 +59,13 @@ func NewPostgreSQLProvider(config *schema.Configuration, caCertPool *x509.CertPo  	provider.sqlDeleteTOTPConfig = provider.db.Rebind(provider.sqlDeleteTOTPConfig)  	provider.sqlSelectTOTPConfigs = provider.db.Rebind(provider.sqlSelectTOTPConfigs) -	provider.sqlSelectWebauthnDevices = provider.db.Rebind(provider.sqlSelectWebauthnDevices) -	provider.sqlSelectWebauthnDevicesByUsername = provider.db.Rebind(provider.sqlSelectWebauthnDevicesByUsername) -	provider.sqlUpdateWebauthnDeviceRecordSignIn = provider.db.Rebind(provider.sqlUpdateWebauthnDeviceRecordSignIn) -	provider.sqlUpdateWebauthnDeviceRecordSignInByUsername = provider.db.Rebind(provider.sqlUpdateWebauthnDeviceRecordSignInByUsername) -	provider.sqlDeleteWebauthnDevice = provider.db.Rebind(provider.sqlDeleteWebauthnDevice) -	provider.sqlDeleteWebauthnDeviceByUsername = provider.db.Rebind(provider.sqlDeleteWebauthnDeviceByUsername) -	provider.sqlDeleteWebauthnDeviceByUsernameAndDescription = provider.db.Rebind(provider.sqlDeleteWebauthnDeviceByUsernameAndDescription) +	provider.sqlSelectWebAuthnDevices = provider.db.Rebind(provider.sqlSelectWebAuthnDevices) +	provider.sqlSelectWebAuthnDevicesByUsername = provider.db.Rebind(provider.sqlSelectWebAuthnDevicesByUsername) +	provider.sqlUpdateWebAuthnDeviceRecordSignIn = provider.db.Rebind(provider.sqlUpdateWebAuthnDeviceRecordSignIn) +	provider.sqlUpdateWebAuthnDeviceRecordSignInByUsername = provider.db.Rebind(provider.sqlUpdateWebAuthnDeviceRecordSignInByUsername) +	provider.sqlDeleteWebAuthnDevice = provider.db.Rebind(provider.sqlDeleteWebAuthnDevice) +	provider.sqlDeleteWebAuthnDeviceByUsername = provider.db.Rebind(provider.sqlDeleteWebAuthnDeviceByUsername) +	provider.sqlDeleteWebAuthnDeviceByUsernameAndDescription = provider.db.Rebind(provider.sqlDeleteWebAuthnDeviceByUsernameAndDescription)  	provider.sqlSelectDuoDevice = provider.db.Rebind(provider.sqlSelectDuoDevice)  	provider.sqlDeleteDuoDevice = provider.db.Rebind(provider.sqlDeleteDuoDevice) diff --git a/internal/storage/sql_provider_encryption.go b/internal/storage/sql_provider_encryption.go index 29d334510..858ad6efa 100644 --- a/internal/storage/sql_provider_encryption.go +++ b/internal/storage/sql_provider_encryption.go @@ -34,7 +34,7 @@ func (p *SQLProvider) SchemaEncryptionChangeKey(ctx context.Context, key string)  	encChangeFuncs := []EncryptionChangeKeyFunc{  		schemaEncryptionChangeKeyTOTP, -		schemaEncryptionChangeKeyWebauthn, +		schemaEncryptionChangeKeyWebAuthn,  	}  	for i := 0; true; i++ { @@ -90,7 +90,7 @@ func (p *SQLProvider) SchemaEncryptionCheckKey(ctx context.Context, verbose bool  	if verbose {  		encCheckFuncs := []EncryptionCheckKeyFunc{  			schemaEncryptionCheckKeyTOTP, -			schemaEncryptionCheckKeyWebauthn, +			schemaEncryptionCheckKeyWebAuthn,  		}  		for i := 0; true; i++ { @@ -153,10 +153,10 @@ func schemaEncryptionChangeKeyTOTP(ctx context.Context, provider *SQLProvider, t  	return nil  } -func schemaEncryptionChangeKeyWebauthn(ctx context.Context, provider *SQLProvider, tx *sqlx.Tx, key [32]byte) (err error) { +func schemaEncryptionChangeKeyWebAuthn(ctx context.Context, provider *SQLProvider, tx *sqlx.Tx, key [32]byte) (err error) {  	var count int -	if err = tx.GetContext(ctx, &count, fmt.Sprintf(queryFmtSelectRowCount, tableWebauthnDevices)); err != nil { +	if err = tx.GetContext(ctx, &count, fmt.Sprintf(queryFmtSelectRowCount, tableWebAuthnDevices)); err != nil {  		return err  	} @@ -164,29 +164,29 @@ func schemaEncryptionChangeKeyWebauthn(ctx context.Context, provider *SQLProvide  		return nil  	} -	devices := make([]encWebauthnDevice, 0, count) +	devices := make([]encWebAuthnDevice, 0, count) -	if err = tx.SelectContext(ctx, &devices, fmt.Sprintf(queryFmtSelectWebauthnDevicesEncryptedData, tableWebauthnDevices)); err != nil { +	if err = tx.SelectContext(ctx, &devices, fmt.Sprintf(queryFmtSelectWebAuthnDevicesEncryptedData, tableWebAuthnDevices)); err != nil {  		if errors.Is(err, sql.ErrNoRows) {  			return nil  		} -		return fmt.Errorf("error selecting Webauthn devices: %w", err) +		return fmt.Errorf("error selecting WebAuthn devices: %w", err)  	} -	query := provider.db.Rebind(fmt.Sprintf(queryFmtUpdateWebauthnDevicePublicKey, tableWebauthnDevices)) +	query := provider.db.Rebind(fmt.Sprintf(queryFmtUpdateWebAuthnDevicePublicKey, tableWebAuthnDevices))  	for _, d := range devices {  		if d.PublicKey, err = provider.decrypt(d.PublicKey); err != nil { -			return fmt.Errorf("error decrypting Webauthn device public key with id '%d': %w", d.ID, err) +			return fmt.Errorf("error decrypting WebAuthn device public key with id '%d': %w", d.ID, err)  		}  		if d.PublicKey, err = utils.Encrypt(d.PublicKey, &key); err != nil { -			return fmt.Errorf("error encrypting Webauthn device public key with id '%d': %w", d.ID, err) +			return fmt.Errorf("error encrypting WebAuthn device public key with id '%d': %w", d.ID, err)  		}  		if _, err = tx.ExecContext(ctx, query, d.PublicKey, d.ID); err != nil { -			return fmt.Errorf("error updating Webauthn device public key with id '%d': %w", d.ID, err) +			return fmt.Errorf("error updating WebAuthn device public key with id '%d': %w", d.ID, err)  		}  	} @@ -262,17 +262,17 @@ func schemaEncryptionCheckKeyTOTP(ctx context.Context, provider *SQLProvider) (t  	return tableTOTPConfigurations, result  } -func schemaEncryptionCheckKeyWebauthn(ctx context.Context, provider *SQLProvider) (table string, result EncryptionValidationTableResult) { +func schemaEncryptionCheckKeyWebAuthn(ctx context.Context, provider *SQLProvider) (table string, result EncryptionValidationTableResult) {  	var (  		rows *sqlx.Rows  		err  error  	) -	if rows, err = provider.db.QueryxContext(ctx, fmt.Sprintf(queryFmtSelectWebauthnDevicesEncryptedData, tableWebauthnDevices)); err != nil { -		return tableWebauthnDevices, EncryptionValidationTableResult{Error: fmt.Errorf("error selecting Webauthn devices: %w", err)} +	if rows, err = provider.db.QueryxContext(ctx, fmt.Sprintf(queryFmtSelectWebAuthnDevicesEncryptedData, tableWebAuthnDevices)); err != nil { +		return tableWebAuthnDevices, EncryptionValidationTableResult{Error: fmt.Errorf("error selecting WebAuthn devices: %w", err)}  	} -	var device encWebauthnDevice +	var device encWebAuthnDevice  	for rows.Next() {  		result.Total++ @@ -280,7 +280,7 @@ func schemaEncryptionCheckKeyWebauthn(ctx context.Context, provider *SQLProvider  		if err = rows.StructScan(&device); err != nil {  			_ = rows.Close() -			return tableWebauthnDevices, EncryptionValidationTableResult{Error: fmt.Errorf("error scanning Webauthn device to struct: %w", err)} +			return tableWebAuthnDevices, EncryptionValidationTableResult{Error: fmt.Errorf("error scanning WebAuthn device to struct: %w", err)}  		}  		if _, err = provider.decrypt(device.PublicKey); err != nil { @@ -290,7 +290,7 @@ func schemaEncryptionCheckKeyWebauthn(ctx context.Context, provider *SQLProvider  	_ = rows.Close() -	return tableWebauthnDevices, result +	return tableWebAuthnDevices, result  }  func schemaEncryptionCheckKeyOpenIDConnect(typeOAuth2Session OAuth2SessionType) EncryptionCheckKeyFunc { diff --git a/internal/storage/sql_provider_queries.go b/internal/storage/sql_provider_queries.go index 5f1aa3cec..b089e23ce 100644 --- a/internal/storage/sql_provider_queries.go +++ b/internal/storage/sql_provider_queries.go @@ -119,59 +119,59 @@ const (  )  const ( -	queryFmtSelectWebauthnDevices = ` +	queryFmtSelectWebAuthnDevices = `  		SELECT id, created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning  		FROM %s  		LIMIT ?  		OFFSET ?;` -	queryFmtSelectWebauthnDevicesEncryptedData = ` +	queryFmtSelectWebAuthnDevicesEncryptedData = `  		SELECT id, public_key  		FROM %s;` -	queryFmtSelectWebauthnDevicesByUsername = ` +	queryFmtSelectWebAuthnDevicesByUsername = `  		SELECT id, created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning  		FROM %s  		WHERE username = ?;` -	queryFmtUpdateWebauthnDevicePublicKey = ` +	queryFmtUpdateWebAuthnDevicePublicKey = `  		UPDATE %s  		SET public_key = ?  		WHERE id = ?;` -	queryFmtUpdateWebauthnDeviceRecordSignIn = ` +	queryFmtUpdateWebAuthnDeviceRecordSignIn = `  		UPDATE %s  		SET  			rpid = ?, last_used_at = ?, sign_count = ?,  			clone_warning = CASE clone_warning WHEN TRUE THEN TRUE ELSE ? END  		WHERE id = ?;` -	queryFmtUpdateWebauthnDeviceRecordSignInByUsername = ` +	queryFmtUpdateWebAuthnDeviceRecordSignInByUsername = `  		UPDATE %s  		SET  			rpid = ?, last_used_at = ?, sign_count = ?,  			clone_warning = CASE clone_warning WHEN TRUE THEN TRUE ELSE ? END  		WHERE username = ? AND kid = ?;` -	queryFmtUpsertWebauthnDevice = ` +	queryFmtUpsertWebAuthnDevice = `  		REPLACE INTO %s (created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning)  		VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);` -	queryFmtUpsertWebauthnDevicePostgreSQL = ` +	queryFmtUpsertWebAuthnDevicePostgreSQL = `  		INSERT INTO %s (created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning)  		VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)  			ON CONFLICT (username, description)  			DO UPDATE SET created_at = $1, last_used_at = $2, rpid = $3, kid = $6, public_key = $7, attestation_type = $8, transport = $9, aaguid = $10, sign_count = $11, clone_warning = $12;` -	queryFmtDeleteWebauthnDevice = ` +	queryFmtDeleteWebAuthnDevice = `  		DELETE FROM %s  		WHERE kid = ?;` -	queryFmtDeleteWebauthnDeviceByUsername = ` +	queryFmtDeleteWebAuthnDeviceByUsername = `  		DELETE FROM %s  		WHERE username = ?;` -	queryFmtDeleteWebauthnDeviceByUsernameAndDescription = ` +	queryFmtDeleteWebAuthnDeviceByUsernameAndDescription = `  		DELETE FROM %s  		WHERE username = ? AND description = ?;`  ) diff --git a/internal/storage/types.go b/internal/storage/types.go index 327f52c4d..7537c7695 100644 --- a/internal/storage/types.go +++ b/internal/storage/types.go @@ -32,7 +32,7 @@ type encOAuth2Session struct {  	Session []byte `db:"session_data"`  } -type encWebauthnDevice struct { +type encWebAuthnDevice struct {  	ID        int    `db:"id"`  	PublicKey []byte `db:"public_key"`  }  | 
