auth

package
v0.0.0-...-5154e19 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Raw passwords should be 24 characters long
	DefaultPasswordLength = 24

	// MinSaltSize a minimum salt size recommended by the RFC
	SaltSize = 64

	// Iterations
	Iterations = 10000
)
View Source
const (
	// All credential password prefixes
	CredentialIDPrefix = "zeus"
)
View Source
const (
	CredentialStoreStoragePrefix = "credentials"
)

Variables

View Source
var (
	CredentialDoesNotExistError = errors.New("credential does not exist")
)
View Source
var DefaultPasswordFactory = NewPasswordFactory()

DefaultPasswordFactory is the default password factory for zeus

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomStringURLSafe

func GenerateRandomStringURLSafe(n int) (string, error)

GenerateRandomStringURLSafe returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

type Credential

type Credential struct {
	// ID is the ID of the token. It behaves as a username, which is randomly generated
	ID string `json:"id"`

	// TenantID is the tenant which the credential belongs to.
	TenantID string `json:"tenant_id"`

	// Password is the HashedPassword used for authorizing traffic for
	// the tenant's credential.
	// Raw passwords should be 24 characters long and contain alphanumeric characters.
	// Raw passwords are never stored, only the hash and salt are stored.
	Password HashedPassword `json:"password"`
}

Credential represents a tenant's credential. It should contain the tenant's ID, username, and password. It can be used as a basic authentication token which can be used for most requests.

func NewCredential

func NewCredential(tenant, password string) *Credential

NewCredential

type CredentialStore

type CredentialStore interface {
	// GetCredential retrieves a credential from the store
	GetCredential(ctx context.Context, id string) (*Credential, error)

	// CacheCredential caches a credential in the store
	CacheCredential(id string, cred *Credential)
}

func NewObjectCredentialStore

func NewObjectCredentialStore(store storage.ObjectStore) (CredentialStore, error)

type HashedPassword

type HashedPassword struct {
	CipherText string `json:"cipher_text"`
	Salt       string `json:"salt"`
}

type ObjectCredentialStore

type ObjectCredentialStore struct {
	// contains filtered or unexported fields
}

func (*ObjectCredentialStore) CacheCredential

func (ocs *ObjectCredentialStore) CacheCredential(id string, cred *Credential)

func (*ObjectCredentialStore) GetCredential

func (ocs *ObjectCredentialStore) GetCredential(ctx context.Context, id string) (*Credential, error)

type PasswordFactory

type PasswordFactory struct {
	Digest     func() hash.Hash
	SaltSize   int
	KeyLen     int
	Iterations int
}

func NewPasswordFactory

func NewPasswordFactory() *PasswordFactory

func (*PasswordFactory) HashPassword

func (p *PasswordFactory) HashPassword(password string) HashedPassword

func (*PasswordFactory) VerifyPassword

func (p *PasswordFactory) VerifyPassword(password, cipherText, salt string) bool

Jump to

Keyboard shortcuts

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