Documentation
¶
Index ¶
- Constants
- type TinyMfa
- func (tinymfa *TinyMfa) BuildPayload(issuer, username string, secret *string, digits uint8) string
- func (tinymfa *TinyMfa) CalculateHMAC(message []byte, key *[]byte) []byte
- func (tinymfa *TinyMfa) ConvertColorSetting(setting structs.ColorSetting) color.Color
- func (tinymfa *TinyMfa) GenerateExtendedSecretKey() (*[]byte, error)
- func (tinymfa *TinyMfa) GenerateMessage(timestamp int64, offsetType uint8) int64
- func (tinymfa *TinyMfa) GenerateMessageBytes(message int64) ([]byte, error)
- func (tinymfa *TinyMfa) GenerateQrCode(issuer, user string, secret *string, digits uint8) ([]byte, error)
- func (tinymfa *TinyMfa) GenerateSecretKey(size int8) (*[]byte, error)
- func (tinymfa *TinyMfa) GenerateStandardSecretKey() (*[]byte, error)
- func (tinymfa *TinyMfa) GenerateValidToken(unixTimestamp int64, key *[]byte, offsetType, tokenlength uint8) (int, error)
- func (tinymfa *TinyMfa) GetFormatString() string
- func (tinymfa *TinyMfa) GetQRCodeConfig() structs.QrCodeConfig
- func (tinymfa *TinyMfa) SetFormatString(formatstring string)
- func (tinymfa *TinyMfa) SetQRCodeConfig(qrcodeConfig structs.QrCodeConfig)
- func (tinymfa *TinyMfa) ValidateToken(token int, key *[]byte, unixTimestamp int64, tokenlength uint8) (bool, error)
- func (tinymfa *TinyMfa) ValidateTokenCurrentTimestamp(token int, key *[]byte, tokenlength uint8) Validation
- func (tinymfa *TinyMfa) ValidateTokenWithTimestamp(token int, key *[]byte, timestamp int64, tokenlength uint8) Validation
- func (tinymfa *TinyMfa) WriteQrCodeImage(issuer, user string, secret *string, digits uint8, filePath string) error
- type TinyMfaInterface
- type Validation
Constants ¶
const ( // Present can be used as an Offset Type Present uint8 = iota // Future can be used as an Offset Type Future // Past can be used as an Offset Type Past )
const ( // OffsetPresent is the offset to add when the OffsetTypePresent was used OffsetPresent int8 = 0 // OffsetFuture is the offset to add when the OffsetTypeFuture was used OffsetFuture int8 = 30 // OffsetPast is the offset to add when the OffsetTypePast was used OffsetPast int8 = -30 // KeySizeStandard is the default size of the SecretKey (128bit) KeySizeStandard int8 = 16 // KeySizeExtended is the extended size of the SecretKey (256bit) KeySizeExtended int8 = 32 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TinyMfa ¶ added in v0.3.0
type TinyMfa struct {
QRCodeConfig structs.QrCodeConfig
FormatString string
}
func (*TinyMfa) BuildPayload ¶ added in v0.3.0
builds the payload for the QRCode. In detail, this takes the otpAuthURL Formatstring constant and formats it using the details provided in the method call.
func (*TinyMfa) CalculateHMAC ¶ added in v0.3.0
CalculateHMAC calculates the hmac-sha1 value for a given message and key (RFC2104)
func (*TinyMfa) ConvertColorSetting ¶ added in v0.3.0
func (tinymfa *TinyMfa) ConvertColorSetting(setting structs.ColorSetting) color.Color
func (*TinyMfa) GenerateExtendedSecretKey ¶ added in v0.3.0
GenerateExtendedSecretKey returns 32bytes to be used as a secret key
func (*TinyMfa) GenerateMessage ¶ added in v0.3.0
GenerateMessage takes in a Unix Timestamp and an offsetType of 0,1,2 offsetTypes: 0=No Offset; 1=Future Offset; 2=Past Offset
func (*TinyMfa) GenerateMessageBytes ¶ added in v0.3.0
GenerateMessageBytes takes in a int64 number and turns it to a BigEndian byte array
func (*TinyMfa) GenerateQrCode ¶ added in v0.3.0
func (tinymfa *TinyMfa) GenerateQrCode(issuer, user string, secret *string, digits uint8) ([]byte, error)
GenerateQrCode Generates a QRCode of the totp url
func (*TinyMfa) GenerateSecretKey ¶ added in v0.3.0
generateSecretKey returns size bytes to be used as a secret key
func (*TinyMfa) GenerateStandardSecretKey ¶ added in v0.3.0
GenerateStandardSecretKey returns 16bytes to be used as a secret key
func (*TinyMfa) GenerateValidToken ¶ added in v0.3.0
func (tinymfa *TinyMfa) GenerateValidToken(unixTimestamp int64, key *[]byte, offsetType, tokenlength uint8) (int, error)
GenerateValidToken takes a Unix Timestamp and a secret key and calculates a valid TOTP token
func (*TinyMfa) GetFormatString ¶ added in v0.3.0
GetFormatString returns the current FormatString for the QRCode.
func (*TinyMfa) GetQRCodeConfig ¶ added in v0.3.0
func (tinymfa *TinyMfa) GetQRCodeConfig() structs.QrCodeConfig
GetQRCodeConfig returns the current QRCodeConfig for the QRCode.
func (*TinyMfa) SetFormatString ¶ added in v0.3.0
SetFormatString sets the FormatString for the QRCode.
func (*TinyMfa) SetQRCodeConfig ¶ added in v0.3.0
func (tinymfa *TinyMfa) SetQRCodeConfig(qrcodeConfig structs.QrCodeConfig)
SetQRCodeConfig sets the QRCodeConfig for the QRCode.
func (*TinyMfa) ValidateToken ¶ added in v0.3.0
func (tinymfa *TinyMfa) ValidateToken(token int, key *[]byte, unixTimestamp int64, tokenlength uint8) (bool, error)
ValidateToken takes a submitted token, a secret key and a Unix Timestamp and validates whether the token is valid
func (*TinyMfa) ValidateTokenCurrentTimestamp ¶ added in v0.3.0
func (tinymfa *TinyMfa) ValidateTokenCurrentTimestamp(token int, key *[]byte, tokenlength uint8) Validation
ValidateTokenCurrentTimestamp takes a submitted token and a secret key and validates against the current Unix Timestamp whether the token is valid
func (*TinyMfa) ValidateTokenWithTimestamp ¶ added in v0.3.0
func (tinymfa *TinyMfa) ValidateTokenWithTimestamp(token int, key *[]byte, timestamp int64, tokenlength uint8) Validation
ValidateTokenWithTimestamp takes a submitted token and a secret key and validates against the current Unix Timestamp whether the token is valid
type TinyMfaInterface ¶ added in v0.3.0
type TinyMfaInterface interface {
// GenerateStandardSecretKey returns 16bytes to be used as a secret key
GenerateStandardSecretKey() (*[]byte, error)
// GenerateExtendedSecretKey returns 32bytes to be used as a secret key
GenerateExtendedSecretKey() (*[]byte, error)
// generateSecretKey returns size bytes to be used as a secret key
GenerateSecretKey(size int8) (*[]byte, error)
// GenerateMessageBytes takes in a int64 number and turns it to a BigEndian byte array
GenerateMessageBytes(message int64) ([]byte, error)
// CalculateHMAC calculates the hmac-sha1 value for a given message and key (RFC2104)
CalculateHMAC(message []byte, key *[]byte) []byte
// GenerateMessage takes in a Unix Timestamp and an offsetType of 0,1,2
// offsetTypes: 0=No Offset; 1=Future Offset; 2=Past Offset
GenerateMessage(timestamp int64, offsetType uint8) int64
// GenerateValidToken takes a Unix Timestamp and a secret key and calculates a valid TOTP token
GenerateValidToken(unixTimestamp int64, key *[]byte, offsetType, tokenlength uint8) (int, error)
// ValidateTokenCurrentTimestamp takes a submitted token and a secret key and validates against the current Unix Timestamp whether the token is valid
ValidateTokenCurrentTimestamp(token int, key *[]byte, tokenlength uint8) Validation
// ValidateTokenWithTimestamp takes a submitted token and a secret key and validates against the current Unix Timestamp whether the token is valid
ValidateTokenWithTimestamp(token int, key *[]byte, timestamp int64, tokenlength uint8) Validation
// ValidateToken takes a submitted token, a secret key and a Unix Timestamp and validates whether the token is valid
ValidateToken(token int, key *[]byte, unixTimestamp int64, tokenlength uint8) (bool, error)
// GenerateQrCode generates a QRCode for the provided issuer, user and secret. It takes in a color setting and number of digits for the TOTP token.
GenerateQrCode(issuer, user string, secret *string, digits uint8) ([]byte, error)
// ConvertColorSetting converts the ColorSetting struct into a color.Color object. This is useful for QRCode generation.
ConvertColorSetting(setting structs.ColorSetting) color.Color
// WriteQrCodeImage writes a png to the filesystem
WriteQrCodeImage(issuer, user string, secret *string, digits uint8, filepath string) error
// builds the payload for the QRCode. In detail, this takes the otpAuthURL Formatstring constant
// and formats it using the details provided in the method call.
BuildPayload(issuer, username string, secret *string, digits uint8) string
// SetFormatString sets the FormatString for the QRCode.
SetFormatString(formatstring string)
// GetFormatString returns the current FormatString for the QRCode.
GetFormatString() string
// SetQRCodeConfig sets the QRCodeConfig for the QRCode.
SetQRCodeConfig(qrcodeConfig structs.QrCodeConfig)
// GetQRCodeConfig returns the current QRCodeConfig for the QRCode.
GetQRCodeConfig() structs.QrCodeConfig
// contains filtered or unexported methods
}
func NewTinyMfa ¶ added in v0.3.0
func NewTinyMfa() TinyMfaInterface
type Validation ¶ added in v0.3.0
Validation is a struct used to return the result of a token validation