README
¶
twofactor
Author
twofactor
was written by Kyle Isom kyle@tyrfingr.is.
License
Copyright (c) 2017 Kyle Isom <kyle@imap.cc>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Documentation
¶
Overview ¶
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
- Variables
- func Pad(s string) string
- type HOTP
- type OATH
- func (o OATH) Counter() uint64
- func (o OATH) Hash() func() hash.Hash
- func (o OATH) Key() []byte
- func (o OATH) OTP(counter uint64) string
- func (o OATH) QR(t Type, label string) ([]byte, error)
- func (o OATH) SetCounter(counter uint64)
- func (o OATH) Size() int
- func (o OATH) URL(t Type, label string) string
- type OTP
- type TOTP
- type Type
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.
func (*HOTP) SetProvider ¶
SetProvider sets up the provider component of the OTP URL.
type OATH ¶
type OATH struct {
// contains filtered or unexported fields
}
OATH provides a baseline structure for the two OATH algorithms.
func (OATH) 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) QR ¶
QR generates a byte slice containing the a QR code encoded as a PNG with level Q error correction.
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 ¶
NewOTP 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.
func (*TOTP) SetProvider ¶
SetProvider sets up the provider component of the OTP URL.