From 8f74f4189e2f2058b50efd4f0abe5cfdaa86b720 Mon Sep 17 00:00:00 2001 From: OroszBalint Date: Mon, 10 Aug 2020 12:12:32 +0200 Subject: [PATCH 1/2] optional 2fa file storage in XDG_CONFIG_HOME/2fa --- README.md | 3 ++- main.go | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7d7c063..241ec56 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ The default time-based authentication codes are derived from a hash of the key and the current time, so it is important that the system clock have at least one-minute accuracy. -The keychain is stored unencrypted in the text file `$HOME/.2fa`. +The keychain is stored unencrypted in the text file $HOME/.2fa +or in $XDG_CONFIG_HOME/2fa if XDG_CONFIG_HOME is set. ## Example diff --git a/main.go b/main.go index a8d173c..951fe85 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,8 @@ // the key and the current time, so it is important that the system clock have // at least one-minute accuracy. // -// The keychain is stored unencrypted in the text file $HOME/.2fa. +// The keychain is stored unencrypted in the text file $HOME/.2fa +// or in $XDG_CONFIG_HOME/2fa if XDG_CONFIG_HOME is set. // // Example // @@ -106,7 +107,11 @@ func main() { flag.Usage = usage flag.Parse() - k := readKeychain(filepath.Join(os.Getenv("HOME"), ".2fa")) + if os.Getenv("XDG_CONFIG_HOME") == "" { + k := readKeychain(filepath.Join(os.Getenv("HOME"), ".2fa")) + } else { + k := readKeychain(filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "2fa")) + } if *flagList { if flag.NArg() != 0 { From bf7a9eb21521d1a112c311d9a0d4f13ebce85391 Mon Sep 17 00:00:00 2001 From: OroszBalint Date: Mon, 10 Aug 2020 12:30:28 +0200 Subject: [PATCH 2/2] XDG_CONFIG_HOME fix --- main.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 951fe85..b33a315 100644 --- a/main.go +++ b/main.go @@ -107,10 +107,9 @@ func main() { flag.Usage = usage flag.Parse() - if os.Getenv("XDG_CONFIG_HOME") == "" { - k := readKeychain(filepath.Join(os.Getenv("HOME"), ".2fa")) - } else { - k := readKeychain(filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "2fa")) + k := readKeychain(filepath.Join(os.Getenv("HOME"), ".2fa")) + if os.Getenv("XDG_CONFIG_HOME") != "" { + k = readKeychain(filepath.Join(os.Getenv("XDG_CONFIG_HOME"), "2fa")) } if *flagList {