common

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Restrictions
	TokenLength       = 32
	PublicIDMaxLength = 16
	OTPMinLength      = TokenLength
	OTPMaxLength      = TokenLength + PublicIDMaxLength
	NonceMinLength    = 16
	NonceMaxLength    = 40
)

Variables

View Source
var (
	ErrStorageNoKey       = errors.New("client key not found")
	ErrStorageKeyInactive = errors.New("client key is not active")
	ErrStorageDecryptFail = errors.New("otp request decryption failed")
)
View Source
var TestVectors = map[string]TestVector{
	"dvgtiblfkbgturecfllberrvkinnctnn": {
		AESKey: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
		OTP: OTP{
			PrivateID:        [6]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
			UsageCounter:     1,
			TimestampCounter: [3]byte{0x01, 0x00, 0x01},
			SessionCounter:   1,
			CRC:              0xfe36,
		},
	},
	"rnibcnfhdninbrdebccrndfhjgnhftee": {
		AESKey: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
		OTP: OTP{
			PrivateID:        [6]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
			UsageCounter:     1,
			TimestampCounter: [3]byte{0x01, 0x00, 0x01},
			SessionCounter:   2,
			CRC:              0x1152,
		},
	},
	"iikkijbdknrrdhfdrjltvgrbkkjblcbh": {
		AESKey: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
		OTP: OTP{
			PrivateID:        [6]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
			UsageCounter:     0x0fff,
			TimestampCounter: [3]byte{0x01, 0x00, 0x01},
			SessionCounter:   1,
			CRC:              0x9454,
		},
	},
	"dcihgvrhjeucvrinhdfddbjhfjftjdei": {
		AESKey: []byte{0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88},
		OTP: OTP{
			PrivateID:        [6]byte{0x88, 0x88, 0x88, 0x88, 0x88, 0x88},
			UsageCounter:     0x8888,
			TimestampCounter: [3]byte{0x88, 0x88, 0x88},
			SessionCounter:   0x88,
			Random:           0x8888,
			CRC:              0xd3b6,
		},
	},
	"kkkncjnvcnenkjvjgncjihljiibgbhbh": {
		AESKey: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
		OTP: OTP{
			PrivateID:        [6]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
			TimestampCounter: [3]byte{0x00, 0x00, 0x00},
			CRC:              0xa96a,
		},
	},
	"iucvrkjiegbhidrcicvlgrcgkgurhjnj": {
		AESKey: []byte{0xc4, 0x42, 0x28, 0x90, 0x65, 0x30, 0x76, 0xcd, 0xe7, 0x3d, 0x44, 0x9b, 0x19, 0x1b, 0x41, 0x6a},
		OTP: OTP{
			PrivateID:        [6]byte{0x33, 0xc6, 0x9e, 0x7f, 0x24, 0x9e},
			UsageCounter:     0x01,
			TimestampCounter: [3]byte{0x24, 0x13, 0xa7},
			Random:           0xc63c,
			CRC:              0x1c86,
		},
	},
}

Functions

func Serve

func Serve(handler fasthttp.RequestHandler, req *http.Request) (*http.Response, error)

Serve serves http request using provided fasthttp handler

func SignMap

func SignMap(m []string, apiKey []byte) []byte

* SignMap - signs specified strings slice with given apiKey @return []byte Raw HMAC signature

func SignMapToBase64

func SignMapToBase64(m []string, apiKey []byte) string

* SignMapToBase64 - signs specified strings slice with given apiKey @return []byte Base64-encoded HMAC signature

Types

type OTP

type OTP struct {
	PrivateID        [6]byte
	UsageCounter     uint16
	TimestampCounter [3]byte
	SessionCounter   uint8
	Random           uint16
	CRC              uint16
}

func (*OTP) Decrypt

func (o *OTP) Decrypt(key []byte, payload []byte) error

func (*OTP) Encrypt

func (o *OTP) Encrypt(key []byte) ([]byte, error)

func (*OTP) EncryptToModhex

func (o *OTP) EncryptToModhex(key []byte) (string, error)

func (*OTP) MarshalBinary

func (o *OTP) MarshalBinary() (data []byte, err error)

func (*OTP) String

func (o *OTP) String() string

func (*OTP) UnmarshalBinary

func (o *OTP) UnmarshalBinary(data []byte) error

type OTPUser

type OTPUser struct {
	UsageCounter   uint16
	SessionCounter uint8
	Timestamp      [3]byte
}

type OTPUsers

type OTPUsers map[string]*OTPUser

type StorageInterface

type StorageInterface interface {
	// DecryptOTP using stored private AES for specified public identifier
	DecryptOTP(publicID, token string) (*OTP, error)
}

StorageInterface for implementing keys storage

type TestVector

type TestVector struct {
	AESKey []byte
	OTP
}

Jump to

Keyboard shortcuts

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