TwoFaGo

package module
v0.0.0-...-ce5a8db Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

README

TOTP client for the Yivi app

Development commands

Renerate the Google protobuf with the following command:

protoc --go_out=paths=source_relative:. googleMigration.proto

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_googleMigration_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type BboltMFASecretStorage

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

func NewBboltMFASecretStorage

func NewBboltMFASecretStorage(db *bbolt.DB, aesKey [32]byte) *BboltMFASecretStorage

func (*BboltMFASecretStorage) ClearStorage

func (s *BboltMFASecretStorage) ClearStorage() error

func (*BboltMFASecretStorage) DeleteTOTPSecretBySecret

func (s *BboltMFASecretStorage) DeleteTOTPSecretBySecret(secretStr string) error

func (*BboltMFASecretStorage) GetAllTOTPSecrets

func (s *BboltMFASecretStorage) GetAllTOTPSecrets() ([]TOTPStored, error)

func (*BboltMFASecretStorage) StoreTOTPSecret

func (s *BboltMFASecretStorage) StoreTOTPSecret(secret TOTPStored) error

type Export

type Export interface {
	ProcessURLTOTPCode(s TOTPSecretStorage, inputUrl string) error
	ExportSecretsAsURL(secrets []TOTPStored, isGoogle bool) ([]string, error)
	EncryptExportFile(password, fileContent string) (string, error)
	DecryptExportFile(password, envelope string) (string, error)
}

type MFAClient

type MFAClient struct {
	MFASecretStorage TOTPSecretStorage
	// contains filtered or unexported fields
}

func New

func New(storagePath string, aesKey [32]byte) *MFAClient

func (*MFAClient) Close

func (c *MFAClient) Close() error

func (*MFAClient) DecryptExportFile

func (c *MFAClient) DecryptExportFile(encryptedContent, password string) (string, error)

func (*MFAClient) EncryptExportFile

func (c *MFAClient) EncryptExportFile(fileContent, password string) (string, error)

func (*MFAClient) ExportSecrets

func (c *MFAClient) ExportSecrets() ([]TOTPStored, error)

func (*MFAClient) ExportSecretsToUrl

func (c *MFAClient) ExportSecretsToUrl(secrets []TOTPStored, isGoogle bool) ([]string, error)

func (*MFAClient) GetAllTOTPSecrets

func (c *MFAClient) GetAllTOTPSecrets() ([]TOTPcode, error)

func (*MFAClient) OpenStorage

func (c *MFAClient) OpenStorage() (*MFAClient, error)

OpenStorage initializes and opens the storage for MFA secrets. We did this so we can always start the client without risk of errors but only open the storage when experimental features are enabled. so we don't need to restart the whole app when they're toggled and so integration tests run properly.

func (*MFAClient) RemoveTOTPSecretByCode

func (c *MFAClient) RemoveTOTPSecretByCode(code TOTPcode) error

func (*MFAClient) StoreTOTPSecret

func (c *MFAClient) StoreTOTPSecret(secret TOTPStored) error

func (*MFAClient) StoreTOTPSecretByURL

func (c *MFAClient) StoreTOTPSecretByURL(inputUrl string) error

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=TwoFaGo.MigrationPayload_Algorithm" json:"algorithm,omitempty"`
	Digits    MigrationPayload_DigitCount `protobuf:"varint,5,opt,name=digits,proto3,enum=TwoFaGo.MigrationPayload_DigitCount" json:"digits,omitempty"`
	Type      MigrationPayload_OtpType    `protobuf:"varint,6,opt,name=type,proto3,enum=TwoFaGo.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 TOTP

type TOTP interface {
	GetAllCodes() ([]TOTPcode, error)
	RemoveCodeByTOTPCode(code TOTPcode, currentTimestamp uint64) error
}

type TOTPImpl

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

func (*TOTPImpl) GetAllCodes

func (T *TOTPImpl) GetAllCodes() ([]TOTPcode, error)

func (*TOTPImpl) RemoveCodeByTOTPCode

func (T *TOTPImpl) RemoveCodeByTOTPCode(code TOTPcode, currentTimestamp uint64) error

type TOTPSecretStorage

type TOTPSecretStorage interface {
	// StoreTOTPSecret stores the given MFA secret. If a secret with the same Secret field already exists, it is updated.
	StoreTOTPSecret(secret TOTPStored) error

	GetAllTOTPSecrets() ([]TOTPStored, error)

	DeleteTOTPSecretBySecret(secretStr string) error

	ClearStorage() error
}

type TOTPStored

type TOTPStored struct {
	Issuer      string // e.g "cloudflare
	UserAccount string // e.g [email protected]
	Secret      string // base32 encoded secret
	Period      int    // in seconds, e.g. 30
	Algorithm   string // Can be "SHA1", "SHA256", "SHA512"
}

type TOTPcode

type TOTPcode struct {
	Issuer        string
	UserAccount   string
	Code          string
	NextCode      string
	Period        int
	TimerProgress int
}

Jump to

Keyboard shortcuts

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