tinymfa

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

func CalculateRFC2104HMAC

func CalculateRFC2104HMAC(message []byte, key []byte) []byte

CalculateRFC2104HMAC calculates the hmac-sha1 value for a given message and key

func GenerateExtendedSecretKey

func GenerateExtendedSecretKey() ([]byte, error)

GenerateExtendedSecretKey returns 32bytes to be used as a secret key

func GenerateMessage

func GenerateMessage(timestamp int64, offsetType uint8) int64

GenerateMessage takes in a Unix Timestamp and an offsetType of 0,1,2 offsetTypes: 0=No Offset; 1=Future Offset; 2=Past Offset

func GenerateMessageBytes

func GenerateMessageBytes(message int64) ([]byte, error)

GenerateMessageBytes takes in a int64 number and turns it to a BigEndian byte array

func GenerateStandardSecretKey

func GenerateStandardSecretKey() ([]byte, error)

GenerateStandardSecretKey returns 16bytes to be used as a secret key

func GenerateValidToken

func 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 ValidateToken

func 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

Types

type Validation added in v0.2.6

type Validation struct {
	Message int64
	Success bool
	Error   error
}

Validation is a struct used to return the result of a token validation

func ValidateTokenCurrentTimestamp

func 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 ValidateTokenWithTimestamp

func 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

Jump to

Keyboard shortcuts

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