models

package
v0.0.0-...-7527e3a Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSessionType = errors.New("SessionType needs to be 'reg' or 'att'")

ErrInvalidSessionType is thrown when an invalid session type is created

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

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

Logger is a global logger used to show informational, warning, and error messages

Functions

func AssembleUncompressedECPoint

func AssembleUncompressedECPoint(xCoord []byte, yCoord []byte) ([]byte, error)

AssembleUncompressedECPoint will properly format the EC coordinates into

func CreateChallenge

func CreateChallenge(len int) ([]byte, error)

CreateChallenge - Create a new challenge to be sent to the authenticator

func CreateCredential

func CreateCredential(c *Credential) error

CreateCredential creates a new credential object

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 FormatPublicKey

func FormatPublicKey(pk PublicKey) (ecdsa.PublicKey, error)

FormatPublicKey formats a `models.PublicKey` into an `ecdsa.PublicKey`

func GetPublicKeyForCredential

func GetPublicKeyForCredential(c *Credential) (ecdsa.PublicKey, error)

GetPublicKeyForCredential gets the formatted `models.PublicKey` for a provided credential

func PutRelyingParty

func PutRelyingParty(rp *RelyingParty) error

PutRelyingParty creates or updates a Relying Party

func PutSession

func PutSession(sd *SessionData) error

PutSession - Update or Create SessionData

func PutUser

func PutUser(u *User) error

PutUser updates the given user

func Setup

func Setup() error

Setup initializes the Conn object It also populates the Config object

func UpdateCredential

func UpdateCredential(c *Credential) error

UpdateCredential updates the credential with new attributes.

Types

type Credential

type Credential struct {
	ID        int64 `json:"id"`
	CreatedAt time.Time
	Counter   []byte `json:"sign_count"`

	RelyingParty   RelyingParty `json:"rp" storm:"inline"`
	RelyingPartyID string       `json:"rp_id"`

	User   User  `json:"user" storm:"inline"`
	UserID int64 `json:"user_id"`

	Type   string `json:"type,omitempty"`
	Format string `json:"format,omitempty"`
	Flags  []byte `json:"flags,omitempty"`

	CredID string `json:"credential_id,omitempty"`

	PublicKey PublicKey `json:"public_key,omitempty" storm:"inline"`
}

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 GetCredentialForUserAndRelyingParty

func GetCredentialForUserAndRelyingParty(user *User, rp *RelyingParty) (Credential, error)

GetCredentialForUserAndRelyingParty retrieves the first credential for a provided user and relying party.

func GetCredentialsForUser

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

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

func GetCredentialsForUserAndRelyingParty

func GetCredentialsForUserAndRelyingParty(user *User, rp *RelyingParty) ([]Credential, error)

GetCredentialsForUserAndRelyingParty retrieves all credentials for a provided user for a relying party.

type PublicKey

type PublicKey struct {
	KeyType      int8   `codec:"1"`
	Type         int8   `codec:"3"`
	XCoord       []byte `codec:"-2"`
	YCoord       []byte `codec:"-3"`
	Curve        int8   `codec:"-1"`
	CredentialID int64  `codec:"-,omitempty"`
	// contains filtered or unexported fields
}

PublicKey is parsed from the credential creation response

func GetUnformattedPublicKeyForCredential

func GetUnformattedPublicKeyForCredential(c *Credential) (PublicKey, error)

GetUnformattedPublicKeyForCredential gives you the raw PublicKey model for a credential

type RelyingParty

type RelyingParty struct {
	ID          string `json:"id" storm:"id"`
	DisplayName string `json:"display_name"`
	Icon        string `json:"icon,omitempty"`
	Users       []User `json:"users,omitempty" storm:"unique"`
}

RelyingParty is the group the User is authenticating with

func GetDefaultRelyingParty

func GetDefaultRelyingParty() (RelyingParty, error)

GetDefaultRelyingParty gets the RP associated with the configured hostname

func GetRelyingPartyByHost

func GetRelyingPartyByHost(hostname string) (RelyingParty, error)

GetRelyingPartyByHost gets the RP by hostname which in this case is the ID

type SessionData

type SessionData struct {
	ID          int64  `json:"id" storm:"id,increment"`
	Challenge   []byte `json:"challenge"`
	Origin      string `json:"origin"`
	SessionType string `json:"session_type"`

	User   User  `json:"user"`
	UserID int64 `json:"user_id"`

	RelyingParty   RelyingParty `json:"rp"`
	RelyingPartyID string       `json:"rp_id"`
}

SessionData is the Model

func CreateNewSession

func CreateNewSession(u *User, rp *RelyingParty, st string) (SessionData, error)

CreateNewSession - Create new user/rp session

func GetSessionData

func GetSessionData(id int64) (SessionData, error)

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

func GetSessionForRequest

func GetSessionForRequest(r *http.Request, store *sessions.CookieStore) (SessionData, error)

GetSessionForRequest gets the stored session data for a provided request.

func GetSessionsByUsernameAndRelyingParty

func GetSessionsByUsernameAndRelyingParty(uid int64, rpid string) (SessionData, error)

GetSessionsByUsernameAndRelyingParty - Get the last recorded SessionData for a user/rp

type User

type User struct {
	ID             int64        `json:"id" storm:"id,increment"`
	Name           string       `json:"name"`
	DisplayName    string       `json:"display_name"`
	Icon           string       `json:"icon,omitempty"`
	Credentials    []Credential `json:"credentials,omitempty"`
	RelyingParties []RelyingParty
}

User represents the user model.

func GetSessionByUsername

func GetSessionByUsername(username string) (User, error)

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

func GetUser

func GetUser(id int64) (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.

Jump to

Keyboard shortcuts

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