Skip to content

Commit

Permalink
Upgrade go-otp and let it handle base32 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
simmel committed May 2, 2015
1 parent 8a233b8 commit e0c106e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bufio"
"encoding/base32"
"fmt"
"github.com/hgfischer/go-otp"
"io"
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e0c106e

Please sign in to comment.