models

package
v0.0.0-...-fd5a099 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUsernameTaken = errors.New("username already taken")

ErrUsernameTaken is thrown when a user attempts to register a username that is taken.

Functions

func AuthKeyPresent

func AuthKeyPresent(key string, authKeys []AuthKey) bool

func BytesToID

func BytesToID(buf []byte) uint

BytesToID converts a byte slice to a uint. This is needed because the WebAuthn specification deals with byte buffers, while the primary keys in our database are uints.

func CreateAuthKey

func CreateAuthKey(k *AuthKey) error

CreateAuthKey creates a new AuthKey object in the database

func CreateCredential

func CreateCredential(c *Credential) error

CreateCredential creates a new credential object

func CreateUser

func CreateUser(u *User) error

CreateUser creates the given user

func DeleteAuthKey

func DeleteAuthKey(key string) error

DeleteAuthKey deletes an AuthKey using its key. This should only be called by the authorized user, after they have logged in (so at the finish part of a FIDO2 login).

func DeleteCredentialByID

func DeleteCredentialByID(credentialID string) error

DeleteCredentialByID gets a credential by its ID. In practice, this would be a bad function without some other checks (like what user is logged in) because someone could hypothetically delete ANY credential.

func Setup

func Setup(config *util.Config) error

Setup initializes the Conn object It also populates the Config object

func UpdateAuthenticatorSignCount

func UpdateAuthenticatorSignCount(c *Credential, count uint32) error

func UpdateCredential

func UpdateCredential(c *Credential) error

UpdateCredential updates the credential with new attributes.

func UpdateUser

func UpdateUser(u *User) error

UpdateUser updates the given user

Types

type AuthKey

type AuthKey struct {
	gorm.Model

	Key    string
	UserID uint
}

When signing authenticator certificates, we will only sign a CSR if the public key is valid for the account.

func GetAuthKeysForUser

func GetAuthKeysForUser(user User) ([]AuthKey, error)

GetAuthKeysForUser retrieves all AuthKeys for a provided user

type Authenticator

type Authenticator struct {
	AAGUID       []byte
	SignCount    uint32
	CloneWarning bool
}

The model for an Authenticator. Not implemented in gorm. Separate for readability.

func MakeAuthenticator

func MakeAuthenticator(a *webauthn.Authenticator) Authenticator

type Credential

type Credential struct {
	gorm.Model

	CredentialID string        `json:"credential_id"`
	Auth         Authenticator `gorm:"embedded" json:"authenticator"`
	PublicKey    []byte        `json:"public_key,omitempty"`
	UserID       uint
}

Credential is the stored credential for Auth

func GetCredentialForUser

func GetCredentialForUser(user *User, credentialID string) (Credential, error)

GetCredentialForUser retrieves a specific credential for a user.

func GetCredentialsForUser

func GetCredentialsForUser(user *User) ([]Credential, error)

GetCredentialsForUser retrieves all credentials for a provided user regardless of relying party.

type User

type User struct {
	gorm.Model
	Username    string       `json:"name" gorm:"not null" validate:"required,min=2,max=25,alphanumunicode"`
	DisplayName string       `json:"display_name" gorm:"not null"`
	Credentials []Credential `json:"credentials"`
}

User represents the user model

func GetUser

func GetUser(id uint) (User, error)

GetUser returns the user that the given id corresponds to. If no user is found, an error is thrown.

func GetUserByUsername

func GetUserByUsername(username string) (User, error)

GetUserByUsername returns the user that the given username corresponds to. If no user is found, an error is thrown.

func NewUser

func NewUser(name string) User

NewUser creates and returns a new User

func (User) CredentialExcludeList

func (u User) CredentialExcludeList() []protocol.CredentialDescriptor

CredentialExcludeList returns a CredentialDescriptor array filled with all the user's credentials

func (User) WebAuthnCredentials

func (u User) WebAuthnCredentials() []webauthn.Credential

WebAuthnCredentials helps implement the webauthn.User interface by loading the user's credentials from the underlying database.

func (User) WebAuthnDisplayName

func (u User) WebAuthnDisplayName() string

WebAuthnDisplayName returns the user's display name

func (User) WebAuthnID

func (u User) WebAuthnID() []byte

WebAuthnID returns the user's ID

func (User) WebAuthnIcon

func (u User) WebAuthnIcon() string

WebAuthnIcon is not (yet) implemented

func (User) WebAuthnName

func (u User) WebAuthnName() string

WebAuthnName returns the user's username

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL