otpauth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2023 License: MIT Imports: 13 Imported by: 0

README

About

This package leverages the explanation of the otpauth-migration Authenticator format discussed in https://github.com/google/google-authenticator-android/issues/118 and via blog post https://alexbakker.me/post/parsing-google-auth-export-qr-code.html

migration.pb.go is generated via

protoc --go_out=paths=source_relative:. pkg/otpauth/migration.proto

option go_package = "github.com/richardjennings/totp/pkg/otpauth"; is added to the original proto spec as per the best practice documented.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MigrationPayload_Algorithm_name = map[int32]string{
		0: "ALGORITHM_UNSPECIFIED",
		1: "ALGORITHM_SHA1",
		2: "ALGORITHM_SHA256",
		3: "ALGORITHM_SHA512",
		4: "ALGORITHM_MD5",
	}
	MigrationPayload_Algorithm_value = map[string]int32{
		"ALGORITHM_UNSPECIFIED": 0,
		"ALGORITHM_SHA1":        1,
		"ALGORITHM_SHA256":      2,
		"ALGORITHM_SHA512":      3,
		"ALGORITHM_MD5":         4,
	}
)

Enum value maps for MigrationPayload_Algorithm.

View Source
var (
	MigrationPayload_DigitCount_name = map[int32]string{
		0: "DIGIT_COUNT_UNSPECIFIED",
		1: "DIGIT_COUNT_SIX",
		2: "DIGIT_COUNT_EIGHT",
	}
	MigrationPayload_DigitCount_value = map[string]int32{
		"DIGIT_COUNT_UNSPECIFIED": 0,
		"DIGIT_COUNT_SIX":         1,
		"DIGIT_COUNT_EIGHT":       2,
	}
)

Enum value maps for MigrationPayload_DigitCount.

View Source
var (
	MigrationPayload_OtpType_name = map[int32]string{
		0: "OTP_TYPE_UNSPECIFIED",
		1: "OTP_TYPE_HOTP",
		2: "OTP_TYPE_TOTP",
	}
	MigrationPayload_OtpType_value = map[string]int32{
		"OTP_TYPE_UNSPECIFIED": 0,
		"OTP_TYPE_HOTP":        1,
		"OTP_TYPE_TOTP":        2,
	}
)

Enum value maps for MigrationPayload_OtpType.

View Source
var File_pkg_otpauth_migration_proto protoreflect.FileDescriptor

Functions

func GenerateTOTPFromAuthURI

func GenerateTOTPFromAuthURI(otpAuth AuthURI, timestamp string) (code string, err error)

GenerateTOTPFromAuthURI generates a TOTP code from an AuthURI

Types

type AuthURI

type AuthURI struct {

	// should be otpauth://
	Scheme string

	// Valid types are hotp and totp, to distinguish whether the key will be used for counter-based HOTP or for TOTP.
	Type string

	// label = accountname / issuer (“:” / “%3A”) *”%20” accountname
	Label string

	// REQUIRED: The secret parameter is an arbitrary key value encoded in Base32 according to RFC 3548.
	// The padding specified in RFC 3548 section 2.2 is not required and should be omitted.
	Secret []byte

	// STRONGLY RECOMMENDED: The issuer parameter is a string value indicating the provider or service this account is
	// associated with, URL-encoded according to RFC 3986.
	// If the issuer parameter is absent, issuer information may be taken from the issuer prefix of the label.
	// If both issuer parameter and issuer label prefix are present, they should be equal.
	Issuer string

	// The algorithm may have the values: SHA1, SHA256, SHA512
	Algorithm totp.Algo

	// The digits parameter may have the values 6 or 8, and determines how long of a one-time passcode to display to
	// the user. The default is 6.
	Digits int

	// The counter parameter is required when provisioning a key for use with HOTP. It will set the initial counter
	// value.
	Counter int

	// The period parameter defines a period that a TOTP code will be valid for, in seconds. The default value is 30.
	Period int
}

func AuthURIFromString

func AuthURIFromString(otpAuth string) (uri AuthURI, err error)

AuthURIFromString parses an AuthURI from an otpauth:// string

func NewAuthURI

func NewAuthURI(label string, algo string, digits int, issuer string, secret string, period int) (AuthURI, error)

NewAuthURI creates an AuthURI.

func (AuthURI) URL

func (a AuthURI) URL() *url.URL

URL returns a url.URL representation of an AuthURI

type MigrationPayload

type MigrationPayload struct {
	OtpParameters []*MigrationPayload_OtpParameters `protobuf:"bytes,1,rep,name=otp_parameters,json=otpParameters,proto3" json:"otp_parameters,omitempty"`
	Version       int32                             `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
	BatchSize     int32                             `protobuf:"varint,3,opt,name=batch_size,json=batchSize,proto3" json:"batch_size,omitempty"`
	BatchIndex    int32                             `protobuf:"varint,4,opt,name=batch_index,json=batchIndex,proto3" json:"batch_index,omitempty"`
	BatchId       int32                             `protobuf:"varint,5,opt,name=batch_id,json=batchId,proto3" json:"batch_id,omitempty"`
	// contains filtered or unexported fields
}

func (*MigrationPayload) Descriptor deprecated

func (*MigrationPayload) Descriptor() ([]byte, []int)

Deprecated: Use MigrationPayload.ProtoReflect.Descriptor instead.

func (*MigrationPayload) GetBatchId

func (x *MigrationPayload) GetBatchId() int32

func (*MigrationPayload) GetBatchIndex

func (x *MigrationPayload) GetBatchIndex() int32

func (*MigrationPayload) GetBatchSize

func (x *MigrationPayload) GetBatchSize() int32

func (*MigrationPayload) GetOtpParameters

func (x *MigrationPayload) GetOtpParameters() []*MigrationPayload_OtpParameters

func (*MigrationPayload) GetVersion

func (x *MigrationPayload) GetVersion() int32

func (*MigrationPayload) ProtoMessage

func (*MigrationPayload) ProtoMessage()

func (*MigrationPayload) ProtoReflect

func (x *MigrationPayload) ProtoReflect() protoreflect.Message

func (*MigrationPayload) Reset

func (x *MigrationPayload) Reset()

func (*MigrationPayload) String

func (x *MigrationPayload) String() string

type MigrationPayload_Algorithm

type MigrationPayload_Algorithm int32
const (
	MigrationPayload_ALGORITHM_UNSPECIFIED MigrationPayload_Algorithm = 0
	MigrationPayload_ALGORITHM_SHA1        MigrationPayload_Algorithm = 1
	MigrationPayload_ALGORITHM_SHA256      MigrationPayload_Algorithm = 2
	MigrationPayload_ALGORITHM_SHA512      MigrationPayload_Algorithm = 3
	MigrationPayload_ALGORITHM_MD5         MigrationPayload_Algorithm = 4
)

func (MigrationPayload_Algorithm) Descriptor

func (MigrationPayload_Algorithm) Enum

func (MigrationPayload_Algorithm) EnumDescriptor deprecated

func (MigrationPayload_Algorithm) EnumDescriptor() ([]byte, []int)

Deprecated: Use MigrationPayload_Algorithm.Descriptor instead.

func (MigrationPayload_Algorithm) Number

func (MigrationPayload_Algorithm) String

func (MigrationPayload_Algorithm) Type

type MigrationPayload_DigitCount

type MigrationPayload_DigitCount int32
const (
	MigrationPayload_DIGIT_COUNT_UNSPECIFIED MigrationPayload_DigitCount = 0
	MigrationPayload_DIGIT_COUNT_SIX         MigrationPayload_DigitCount = 1
	MigrationPayload_DIGIT_COUNT_EIGHT       MigrationPayload_DigitCount = 2
)

func (MigrationPayload_DigitCount) Descriptor

func (MigrationPayload_DigitCount) Enum

func (MigrationPayload_DigitCount) EnumDescriptor deprecated

func (MigrationPayload_DigitCount) EnumDescriptor() ([]byte, []int)

Deprecated: Use MigrationPayload_DigitCount.Descriptor instead.

func (MigrationPayload_DigitCount) Number

func (MigrationPayload_DigitCount) String

func (MigrationPayload_DigitCount) Type

type MigrationPayload_OtpParameters

type MigrationPayload_OtpParameters struct {
	Secret    []byte                      `protobuf:"bytes,1,opt,name=secret,proto3" json:"secret,omitempty"`
	Name      string                      `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	Issuer    string                      `protobuf:"bytes,3,opt,name=issuer,proto3" json:"issuer,omitempty"`
	Algorithm MigrationPayload_Algorithm  `protobuf:"varint,4,opt,name=algorithm,proto3,enum=MigrationPayload_Algorithm" json:"algorithm,omitempty"`
	Digits    MigrationPayload_DigitCount `protobuf:"varint,5,opt,name=digits,proto3,enum=MigrationPayload_DigitCount" json:"digits,omitempty"`
	Type      MigrationPayload_OtpType    `protobuf:"varint,6,opt,name=type,proto3,enum=MigrationPayload_OtpType" json:"type,omitempty"`
	Counter   int64                       `protobuf:"varint,7,opt,name=counter,proto3" json:"counter,omitempty"`
	// contains filtered or unexported fields
}

func (*MigrationPayload_OtpParameters) Descriptor deprecated

func (*MigrationPayload_OtpParameters) Descriptor() ([]byte, []int)

Deprecated: Use MigrationPayload_OtpParameters.ProtoReflect.Descriptor instead.

func (*MigrationPayload_OtpParameters) GetAlgorithm

func (*MigrationPayload_OtpParameters) GetCounter

func (x *MigrationPayload_OtpParameters) GetCounter() int64

func (*MigrationPayload_OtpParameters) GetDigits

func (*MigrationPayload_OtpParameters) GetIssuer

func (x *MigrationPayload_OtpParameters) GetIssuer() string

func (*MigrationPayload_OtpParameters) GetName

func (*MigrationPayload_OtpParameters) GetSecret

func (x *MigrationPayload_OtpParameters) GetSecret() []byte

func (*MigrationPayload_OtpParameters) GetType

func (*MigrationPayload_OtpParameters) ProtoMessage

func (*MigrationPayload_OtpParameters) ProtoMessage()

func (*MigrationPayload_OtpParameters) ProtoReflect

func (*MigrationPayload_OtpParameters) Reset

func (x *MigrationPayload_OtpParameters) Reset()

func (*MigrationPayload_OtpParameters) String

type MigrationPayload_OtpType

type MigrationPayload_OtpType int32
const (
	MigrationPayload_OTP_TYPE_UNSPECIFIED MigrationPayload_OtpType = 0
	MigrationPayload_OTP_TYPE_HOTP        MigrationPayload_OtpType = 1
	MigrationPayload_OTP_TYPE_TOTP        MigrationPayload_OtpType = 2
)

func (MigrationPayload_OtpType) Descriptor

func (MigrationPayload_OtpType) Enum

func (MigrationPayload_OtpType) EnumDescriptor deprecated

func (MigrationPayload_OtpType) EnumDescriptor() ([]byte, []int)

Deprecated: Use MigrationPayload_OtpType.Descriptor instead.

func (MigrationPayload_OtpType) Number

func (MigrationPayload_OtpType) String

func (x MigrationPayload_OtpType) String() string

func (MigrationPayload_OtpType) Type

type MigrationURI

type MigrationURI []AuthURI

func MigrationURIDecode

func MigrationURIDecode(u *url.URL) (m MigrationURI, err error)

MigrationURIDecode transforms a otpauth-migration type url.URL into a MigrationURL

func (MigrationURI) String

func (m MigrationURI) String() string

String returns a string representation of a MigrationURI

Jump to

Keyboard shortcuts

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