Documentation
¶
Overview ¶
Package totp manages authenticator-app MFA and recovery codes.
Index ¶
- Variables
- type Attempt
- type AttemptGuard
- type Authentication
- type Challenge
- type ChallengeHash
- type ChallengeStarted
- type Config
- type Credential
- type Enrollment
- type EnrollmentConfirmed
- type EnrollmentStarted
- type EventType
- type Manager
- func (manager *Manager) BeginChallenge(ctx context.Context, subjectID string) (ChallengeStarted, error)
- func (manager *Manager) BeginEnrollment(ctx context.Context, subjectID string, accountName string) (EnrollmentStarted, error)
- func (manager *Manager) ConfirmEnrollment(ctx context.Context, subjectID string, code string, sourceKey string) (EnrollmentConfirmed, error)
- func (manager *Manager) Disable(ctx context.Context, subjectID, sourceKey string) error
- func (manager *Manager) IsEnabled(ctx context.Context, subjectID string) (bool, error)
- func (manager *Manager) Recover(ctx context.Context, input VerifyInput) (Authentication, error)
- func (manager *Manager) Verify(ctx context.Context, input VerifyInput) (Authentication, error)
- type Operation
- type RecoveryCodeHash
- type SecurityEvent
- type SecurityEventSink
- type Store
- type VerifyInput
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAlreadyEnabled = errors.New("TOTP is already enabled") ErrAttemptBlocked = errors.New("TOTP attempt blocked") ErrConflict = errors.New("TOTP record conflict") ErrInactiveChallenge = errors.New("TOTP challenge is inactive") ErrInactiveEnrollment = errors.New("TOTP enrollment is inactive") ErrInvalidChallenge = errors.New("invalid or expired TOTP challenge") ErrInvalidCode = errors.New("invalid TOTP or recovery code") ErrInvalidConfig = errors.New("invalid TOTP configuration") ErrInvalidInput = errors.New("invalid TOTP input") ErrInvalidRecord = errors.New("invalid TOTP record") ErrNotFound = errors.New("TOTP record not found") )
Functions ¶
This section is empty.
Types ¶
type AttemptGuard ¶
type Authentication ¶
type ChallengeHash ¶
type ChallengeStarted ¶
type Config ¶
type Config struct {
Issuer string
EnrollmentLifetime time.Duration
ChallengeLifetime time.Duration
RecoveryCodeCount int
AttemptGuard AttemptGuard
SecurityEvents SecurityEventSink
Now func() time.Time
}
type Credential ¶
type Enrollment ¶
type EnrollmentConfirmed ¶
type EnrollmentConfirmed struct {
RecoveryCodes []string
}
type EnrollmentStarted ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) BeginChallenge ¶
func (*Manager) BeginEnrollment ¶
func (*Manager) ConfirmEnrollment ¶
func (*Manager) Recover ¶
func (manager *Manager) Recover(ctx context.Context, input VerifyInput) (Authentication, error)
func (*Manager) Verify ¶
func (manager *Manager) Verify(ctx context.Context, input VerifyInput) (Authentication, error)
type RecoveryCodeHash ¶
type RecoveryCodeHash [32]byte
func HashRecoveryCode ¶
func HashRecoveryCode(rawCode string) (RecoveryCodeHash, error)
type SecurityEvent ¶
type SecurityEventSink ¶
type SecurityEventSink interface {
Record(ctx context.Context, event SecurityEvent)
}
type Store ¶
type Store interface {
IsEnabled(ctx context.Context, subjectID string) (bool, error)
BeginEnrollment(ctx context.Context, enrollment Enrollment) error
FindEnrollment(ctx context.Context, subjectID string) (Enrollment, error)
Enable(ctx context.Context, subjectID string, confirmedCounter uint64, recoveryCodes []RecoveryCodeHash, enabledAt time.Time) error
Disable(ctx context.Context, subjectID string, disabledAt time.Time) error
CreateChallenge(ctx context.Context, challenge Challenge) error
FindChallenge(ctx context.Context, challengeHash ChallengeHash) (Challenge, Credential, error)
CompleteCode(ctx context.Context, challengeHash ChallengeHash, counter uint64, completedAt time.Time) (string, error)
CompleteRecovery(ctx context.Context, challengeHash ChallengeHash, recoveryCode RecoveryCodeHash, completedAt time.Time) (string, error)
}
Store encrypts TOTP secrets at rest. Enable consumes the enrollment; challenge completion and replay protection are atomic.
type VerifyInput ¶
Click to show internal directories.
Click to hide internal directories.