From e0c106e56a20ded6307735bdb7fd96b435c89b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lundstr=C3=B6m?= Date: Sun, 3 May 2015 00:26:14 +0200 Subject: [PATCH] Upgrade go-otp and let it handle base32 decoding --- Godeps/Godeps.json | 2 +- README.textile | 1 - main.go | 6 ++---- main_test.go | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ede034e..214acdb 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -4,7 +4,7 @@ "Deps": [ { "ImportPath": "github.com/hgfischer/go-otp", - "Rev": "d416f5f98991275c1338b32467f04a24dc8c0cb8" + "Rev": "38f86955cc6459714c4a5945fc6dfbacdb30b624" }, { "ImportPath": "github.com/seletskiy/go-mock-file", diff --git a/README.textile b/README.textile index acd2341..3063e30 100644 --- a/README.textile +++ b/README.textile @@ -32,7 +32,6 @@ h4. TODO * Add tests for: ** multiple keys and OTP-tokens in an hash * Fix FIXME's in the code -* Use IsBase32Secret instead of base32.StdEncoding.DecodeString * Support HOTP * Support these features from Google Authenticator PAM module: ** Support for emergency scratch codes diff --git a/main.go b/main.go index 7243847..89b329e 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "encoding/base32" "fmt" "github.com/hgfischer/go-otp" "io" @@ -51,8 +50,7 @@ var parse_config = func(filename string) (token string) { if len(scanner.Text()) != 16 { check_err(fmt.Errorf("Couldn't read exactly 16 bytes from first line of %q. Got this: %q.", filename, scanner.Text())) } - token_in_bytes, err := base32.StdEncoding.DecodeString(scanner.Text()) - check_err(err) + token_in_bytes := scanner.Text() return string(token_in_bytes) } @@ -103,7 +101,7 @@ func main() { otp_input := read_otp_input() - totp := &otp.TOTP{Secret: token} + totp := &otp.TOTP{Secret: token, IsBase32Secret: true} verified := totp.Verify(otp_input) if verified { diff --git a/main_test.go b/main_test.go index 053b17f..8833255 100644 --- a/main_test.go +++ b/main_test.go @@ -73,7 +73,7 @@ func TestConfigParsing(t *testing.T) { return config_file }).Restore() - expected := "RLYDEADN0B" + expected := "KJGFSRCFIFCE4MCC" ga_token_file := find_config() found := parse_config(ga_token_file) if found != expected {