diff --git a/README.md b/README.md index 2e1dbef..47bb063 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,12 @@ Usage ----- - In web interfaces, pretend you can't read QR codes, get a secret like `hret 3ij7 kaj4 2jzg` instead. -- Store your secrets as a JSON object in `~/.config/gauth.json`, for example: +- Store one secrets per line in `~/.config/gauth.csv`, in the format `name:secret`, for example: - { - "AWS": "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", - "Airbnb": "abcdefghijklmnop", - "Google": "a2b3c4d5e6f7g8h9", - "Github": "234567qrstuvwxyz" - } + AWS:ABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 + Airbnb:abcdefghijklmnop + Google:a2b3c4d5e6f7g8h9 + Github:234567qrstuvwxyz - Restrict access to your user: diff --git a/gauth.go b/gauth.go index a2038bd..5c1297d 100644 --- a/gauth.go +++ b/gauth.go @@ -1,10 +1,11 @@ package main import ( + "bytes" "crypto/hmac" "crypto/sha1" "encoding/base32" - "encoding/json" + "encoding/csv" "fmt" "io/ioutil" "log" @@ -69,15 +70,18 @@ func main() { if e != nil { log.Fatal(e) } - cfg_path := path.Join(user.HomeDir, ".config/gauth.json") + cfgPath := path.Join(user.HomeDir, ".config/gauth.csv") - conf_content, e := ioutil.ReadFile(cfg_path) + cfgContent, e := ioutil.ReadFile(cfgPath) if e != nil { log.Fatal(e) } - var cfg map[string]string - e = json.Unmarshal(conf_content, &cfg) + cfgReader := csv.NewReader(bytes.NewReader(cfgContent)) + // Unix-style tabular + cfgReader.Comma = ':' + + cfg, e := cfgReader.ReadAll() if e != nil { log.Fatal(e) } @@ -87,8 +91,9 @@ func main() { nextTS := currentTS + 1 fmt.Println(" prev curr next") - for name, rawSecret := range cfg { - secret := normalizeSecret(rawSecret) + for _, record := range cfg { + name := record[0] + secret := normalizeSecret(record[1]) prevToken := authCodeOrDie(secret, prevTS) currentToken := authCodeOrDie(secret, currentTS) nextToken := authCodeOrDie(secret, nextTS)