Documentation ¶
Overview ¶
Package twofactor implements two-factor authentication.
Currently supported are RFC 4226 HOTP one-time passwords and RFC 6238 TOTP SHA-1 one-time passwords.
Index ¶
Constants ¶
const ( OATH_HOTP = iota OATH_TOTP )
Variables ¶
var ( ErrInvalidURL = errors.New("twofactor: invalid URL") ErrInvalidAlgo = errors.New("twofactor: invalid algorithm") )
var PRNG = rand.Reader
PRNG is an io.Reader that provides a cryptographically secure random byte stream.
Functions ¶
Types ¶
type HOTP ¶
type HOTP struct {
*OATH
}
HOTP represents an RFC-4226 Hash-based One Time Password instance.
func GenerateGoogleHOTP ¶
func GenerateGoogleHOTP() *HOTP
GenerateGoogleHOTP generates a new HOTP instance as used by Google Authenticator.
func NewHOTP ¶
NewHOTP takes the key, the initial counter value, and the number of digits (typically 6 or 8) and returns a new HOTP instance.
type OATH ¶
type OATH struct {
// contains filtered or unexported fields
}
OATH provides a baseline structure for the two OATH algorithms.
func (OATH) OTP ¶
OTP The top-level type should provide a counter; for example, HOTP will provide the counter directly while TOTP will provide the time-stepped counter.
func (OATH) SetCounter ¶
SetCounter updates the OATH token's counter to a new value.
type OTP ¶
type OTP interface { // Returns the current counter value; the meaning of the // returned value is algorithm-specific. Counter() uint64 // Set the counter to a specific value. SetCounter(uint64) // the secret key contained in the OTP Key() []byte // generate a new OTP OTP() string // the output size of the OTP Size() int // the hash function used by the OTP Hash() func() hash.Hash // Returns the type of this OTP. Type() Type }
Type OTP represents a one-time password token -- whether a software taken (as in the case of Google Authenticator) or a hardware token (as in the case of a YubiKey).
type TOTP ¶
type TOTP struct { *OATH // contains filtered or unexported fields }
TOTP represents an RFC 6238 Time-based One-Time Password instance.
func GenerateGoogleTOTP ¶
func GenerateGoogleTOTP() *TOTP
GenerateGoogleTOTP produces a new TOTP token with the defaults expected by Google Authenticator.
func NewGoogleTOTP ¶
NewGoogleTOTP takes a secret as a base32-encoded string and returns an appropriate Google Authenticator TOTP instance.
func NewTOTP ¶
NewTOTP takes a new key, a starting time, a step, the number of digits of output (typically 6 or 8) and the hash algorithm to use, and builds a new OTP.
func NewTOTPSHA1 ¶
NewTOTPSHA1 will build a new TOTP using SHA-1.
func (*TOTP) OTPCounter ¶
OTPCounter returns the current time value for the OTP.