move to CSV

Preserves order, easier to maintain, more Unixy, less error-prone.
Sorry if you have to migrate.
This commit is contained in:
Pierre Carrier 2013-11-14 03:11:21 -08:00
parent 5bc8ff087a
commit efee605b1d
2 changed files with 17 additions and 14 deletions

@ -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:

@ -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)