lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 53ac277434b2fd1787b938615e59a4ebb002ece4
parent ad6a786a4886a716716bfbf137f4003ad63ed2d6
Author: Sean Enck <sean@ttypty.com>
Date:   Wed, 13 Jul 2022 19:49:44 -0400

totp has changed

Diffstat:
MREADME.md | 6+++---
Mcmd/lb-totp/main.go | 37++++++++++++++++++++++++++-----------
Mtests/run.sh | 4++--
3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md @@ -20,8 +20,8 @@ LOCKBOX_KEY="gpg --decrypt /Users/alice/.secrets/key.gpg" LOCKBOX_STORE=/Users/alice/.passwords # the keymode is a command LOCKBOX_KEYMODE="command" -# to utilize totp token generation set the offset (within the repository) where totp tokens are saved -LOCKBOX_TOTP=keys/totp/ +# to utilize totp token generation set the name of files for TOTP tokens +LOCKBOX_TOTP=totp ``` In cases where `lb` outputs colored terminal output this coloring behavior can be disabled: @@ -79,7 +79,7 @@ lb show my/key/value To get a totp token ``` lb totp token -# 'token' must be within the subdir of LOCKBOX_TOTP +# 'token' must contain an entry with the name of LOCKBOX_TOTP ``` The token can be automatically copied to the clipboard too diff --git a/cmd/lb-totp/main.go b/cmd/lb-totp/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io/fs" "os" "os/exec" "path/filepath" @@ -13,22 +14,32 @@ import ( otp "github.com/pquerna/otp/totp" ) -func getEnv() string { - return filepath.Join(internal.GetStore(), os.Getenv("LOCKBOX_TOTP")) -} - func list() ([]string, error) { - path := getEnv() - files, err := os.ReadDir(path) + files := []string{} + token := totpToken() + store := internal.GetStore() + err := filepath.Walk(store, func(path string, info fs.FileInfo, err error) error { + name := info.Name() + if name != token { + return nil + } + dir := strings.TrimPrefix(filepath.Dir(path), store) + if strings.HasSuffix(dir, "/") { + dir = dir[0:len(dir)-1] + } + if strings.HasPrefix(dir, "/") { + dir = dir[1:] + } + files = append(files, dir) + return nil + }) if err != nil { return nil, err } + var results []string for _, obj := range files { - f := obj.Name() - if strings.HasSuffix(f, internal.Extension) { - results = append(results, strings.TrimSuffix(f, internal.Extension)) - } + results = append(results, obj) } if len(results) == 0 { return nil, internal.NewLockboxError("no objects found") @@ -44,6 +55,10 @@ func clear() { } } +func totpToken() string { + return os.Getenv("LOCKBOX_TOTP") + internal.Extension +} + func display(token string, clip, once, short bool) error { interactive, err := internal.IsInteractive() if err != nil { @@ -60,7 +75,7 @@ func display(token string, clip, once, short bool) error { return err } tok := strings.TrimSpace(token) - store := filepath.Join(getEnv(), tok+internal.Extension) + store := filepath.Join(internal.GetStore(), tok, totpToken()) if !internal.PathExists(store) { return internal.NewLockboxError("object does not exist") } diff --git a/tests/run.sh b/tests/run.sh @@ -46,13 +46,13 @@ _run() { "$BIN/lb" show keys/one2 "$BIN/lb" show keys2/three echo "y" | "$BIN/lb" dump keys2/three - echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | "$BIN/lb" insert totp/test + echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | "$BIN/lb" insert test/totp "$BIN/lb-totp" -ls "$BIN/lb-totp" test | tr '[:digit:]' 'X' "$BIN/lb-diff" bin/lb/keys/one.lb bin/lb/keys/one2.lb yes 2>/dev/null | "$BIN/lb" rm keys2/three echo - yes 2>/dev/null | "$BIN/lb" rm totp/test + yes 2>/dev/null | "$BIN/lb" rm test/totp echo LOCKBOX_KEY="invalid" "$BIN/lb" show keys/one2 "$BIN/lb-rekey" -outkey "test" -outmode "plaintext"