move to CSV
Preserves order, easier to maintain, more Unixy, less error-prone. Sorry if you have to migrate.
This commit is contained in:
12
README.md
12
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.
|
- 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
|
||||||
"AWS": "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
Airbnb:abcdefghijklmnop
|
||||||
"Airbnb": "abcdefghijklmnop",
|
Google:a2b3c4d5e6f7g8h9
|
||||||
"Google": "a2b3c4d5e6f7g8h9",
|
Github:234567qrstuvwxyz
|
||||||
"Github": "234567qrstuvwxyz"
|
|
||||||
}
|
|
||||||
|
|
||||||
- Restrict access to your user:
|
- Restrict access to your user:
|
||||||
|
|
||||||
|
19
gauth.go
19
gauth.go
@ -1,10 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"encoding/json"
|
"encoding/csv"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -69,15 +70,18 @@ func main() {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatal(e)
|
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 {
|
if e != nil {
|
||||||
log.Fatal(e)
|
log.Fatal(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cfg map[string]string
|
cfgReader := csv.NewReader(bytes.NewReader(cfgContent))
|
||||||
e = json.Unmarshal(conf_content, &cfg)
|
// Unix-style tabular
|
||||||
|
cfgReader.Comma = ':'
|
||||||
|
|
||||||
|
cfg, e := cfgReader.ReadAll()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatal(e)
|
log.Fatal(e)
|
||||||
}
|
}
|
||||||
@ -87,8 +91,9 @@ func main() {
|
|||||||
nextTS := currentTS + 1
|
nextTS := currentTS + 1
|
||||||
|
|
||||||
fmt.Println(" prev curr next")
|
fmt.Println(" prev curr next")
|
||||||
for name, rawSecret := range cfg {
|
for _, record := range cfg {
|
||||||
secret := normalizeSecret(rawSecret)
|
name := record[0]
|
||||||
|
secret := normalizeSecret(record[1])
|
||||||
prevToken := authCodeOrDie(secret, prevTS)
|
prevToken := authCodeOrDie(secret, prevTS)
|
||||||
currentToken := authCodeOrDie(secret, currentTS)
|
currentToken := authCodeOrDie(secret, currentTS)
|
||||||
nextToken := authCodeOrDie(secret, nextTS)
|
nextToken := authCodeOrDie(secret, nextTS)
|
||||||
|
Reference in New Issue
Block a user