lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 11352691609e31dd99dce6ac604ad09824d11935
parent b90b47178330c406587cb2eeac219d8fc7cac3b3
Author: Sean Enck <sean@ttypty.com>
Date:   Sun,  2 Oct 2022 11:54:11 -0400

totp handling

Diffstat:
Minternal/backend/actions.go | 8++++++++
Minternal/backend/actions_test.go | 3+++
Minternal/inputs/env.go | 5+++++
Minternal/totp/core.go | 8++------
4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/internal/backend/actions.go b/internal/backend/actions.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/enckse/lockbox/internal/inputs" + otp "github.com/pquerna/otp/totp" "github.com/tobischo/gokeepasslib/v3" "github.com/tobischo/gokeepasslib/v3/wrappers" ) @@ -188,6 +189,13 @@ func (t *Transaction) Move(src QueryEntity, dst string) error { if multi { field = notesKey } + if NewSuffix(dTitle) == NewSuffix(inputs.TOTPToken()) { + token, err := otp.Generate(otp.GenerateOpts{Issuer: titleKey, AccountName: dTitle}) + if err != nil { + return err + } + e.Values = append(e.Values, protectedValue("otp", token.URL())) + } e.Values = append(e.Values, protectedValue(field, src.Value)) c.insertEntity(dOffset, dTitle, e) diff --git a/internal/backend/actions_test.go b/internal/backend/actions_test.go @@ -106,6 +106,9 @@ func TestInserts(t *testing.T) { if q.Value != "pass\npass" { t.Errorf("invalid retrieval") } + if err := fullSetup(t, true).Insert(filepath.Join("test", "offset", "totp"), "5ae472abqdekjqykoyxk7hvc2leklq5n"); err != nil { + t.Errorf("no error: %v", err) + } } func TestRemoves(t *testing.T) { diff --git a/internal/inputs/env.go b/internal/inputs/env.go @@ -121,3 +121,8 @@ func IsNoColorEnabled() (bool, error) { func IsInteractive() (bool, error) { return isYesNoEnv(true, interactiveEnv) } + +// TOTPToken gets the name of the totp special case tokens +func TOTPToken() string { + return EnvOrDefault(TotpEnv, "totp") +} diff --git a/internal/totp/core.go b/internal/totp/core.go @@ -33,10 +33,6 @@ func clear() { } } -func totpEnv() string { - return inputs.EnvOrDefault(inputs.TotpEnv, "totp") -} - func colorWhenRules() ([]colorWhen, error) { envTime := os.Getenv(inputs.ColorBetweenEnv) if envTime == "" { @@ -93,7 +89,7 @@ func display(token string, args cli.Arguments) error { if err != nil { return err } - entity, err := t.Get(backend.NewPath(token, totpEnv()), backend.SecretValue) + entity, err := t.Get(backend.NewPath(token, inputs.TOTPToken()), backend.SecretValue) if err != nil { return err } @@ -194,7 +190,7 @@ func Call(args []string) error { if err != nil { return err } - e, err := t.QueryCallback(backend.QueryOptions{Mode: backend.SuffixMode, Criteria: backend.NewSuffix(totpEnv())}) + e, err := t.QueryCallback(backend.QueryOptions{Mode: backend.SuffixMode, Criteria: backend.NewSuffix(inputs.TOTPToken())}) if err != nil { return err }