gotp

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: MIT Imports: 15 Imported by: 0

README

gotp

Golang OTP library and Google Authenticator CLI

GoDoc Go Report Card

Installation

Download from the latest release page,

or install from source.

$ go get -u github.com/major1201/gotp/cmd/gotp

Use as command line

Set DB file

# set DB file with envvar
export GOTP_DBFILE=/var/lib/gotp/default.db

# or you can specify db file path every time you execute gotp
gotp --database /var/lib/gotp/default.db

Add an OTP with URI provided

gotp add --uri otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30

Add an OTP with detailed arguments

gotp add --issuer "ACME Co" --accountname "john.doe@email.com" --secret HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ

Display all otp objects and generate values

gotp

# with ID
gotp --id

Delete otp objects

gotp delete 11 13

Export all otp objects

gotp export

Contributing

Just fork the repository and open a pull request with your changes.

Licence

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvAlgoString

func ConvAlgoString(algorithm string) (func() hash.Hash, error)

ConvAlgoString converts an algorithm string to the hash function

func Itob

func Itob(v uint64) []byte

Itob fills uint64 a byte array

Types

type Hotp

type Hotp struct {
	// contains filtered or unexported fields
}

Hotp defines an HOTP object

func NewDefaultHotp

func NewDefaultHotp(secret string, counter uint64) *Hotp

NewDefaultHotp creates an Hotp object with default arguments

func NewHotp

func NewHotp(accountName, issuer, secret string, algorithm func() hash.Hash, algoString string, digits uint8, counter uint64) *Hotp

NewHotp creates an Hotp object with detailed arguments

func (*Hotp) AccountName

func (o *Hotp) AccountName() string

AccountName returns the OTP account name

func (*Hotp) At

func (o *Hotp) At(c uint64) uint32

At actually generate the OTP value

func (*Hotp) Digits

func (o *Hotp) Digits() uint8

Issuer returns the OTP digits

func (*Hotp) Generate

func (o *Hotp) Generate() uint32

Generate an OTP value

func (*Hotp) ID

func (o *Hotp) ID() uint64

ID returns the OTP id

func (*Hotp) Issuer

func (o *Hotp) Issuer() string

Issuer returns the OTP issuer

func (*Hotp) SetID

func (o *Hotp) SetID(id uint64)

SetID sets the OTP id

func (*Hotp) ToString

func (o *Hotp) ToString(d uint32) string

ToString convert the generated OTP value to string

func (*Hotp) Type

func (o *Hotp) Type() string

Type returns "hotp"

func (*Hotp) URI

func (o *Hotp) URI() string

URI reassembles the otp uri

type Otp

type Otp interface {
	ID() uint64
	SetID(id uint64)
	Type() string
	AccountName() string
	Issuer() string
	Digits() uint8
	URI() string

	At(uint64) uint32
	Generate() uint32
	ToString(uint32) string
}

Otp defines an OTP interface

func NewOtpFromURI

func NewOtpFromURI(uri string) (Otp, error)

NewOtpFromURI makes an OTP object from a URI, ref. <https://github.com/google/google-authenticator/wiki/Key-Uri-Format>

type Totp

type Totp struct {
	// contains filtered or unexported fields
}

Totp defines an TOTP object

func NewDefaultTotp

func NewDefaultTotp(secret string) *Totp

NewDefaultTotp creates an Totp object with default arguments

func NewTotp

func NewTotp(accountName, issuer, secret string, algorithm func() hash.Hash, algoString string, digits uint8, period uint64) *Totp

NewTotp creates an Totp object with detailed arguments

func (*Totp) AccountName

func (o *Totp) AccountName() string

AccountName returns the OTP account name

func (*Totp) At

func (o *Totp) At(c uint64) uint32

At actually generate the OTP value

func (*Totp) Digits

func (o *Totp) Digits() uint8

Issuer returns the OTP digits

func (*Totp) Generate

func (o *Totp) Generate() uint32

Generate an OTP value

func (*Totp) GenerateWithRemainingSeconds

func (o *Totp) GenerateWithRemainingSeconds(t time.Time) (uint32, uint64)

GenerateWithRemainingSeconds generates an TOTP value with the remaining seconds

func (*Totp) ID

func (o *Totp) ID() uint64

ID returns the OTP id

func (*Totp) Issuer

func (o *Totp) Issuer() string

Issuer returns the OTP issuer

func (*Totp) SetID

func (o *Totp) SetID(id uint64)

SetID sets the OTP id

func (*Totp) ToString

func (o *Totp) ToString(d uint32) string

ToString convert the generated OTP value to string

func (*Totp) Type

func (o *Totp) Type() string

Type returns "totp"

func (*Totp) URI

func (o *Totp) URI() string

URI reassembles the otp uri

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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