diff options
| author | Christine Dodrill <me@christine.website> | 2017-03-29 11:06:00 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2017-03-29 11:06:59 -0700 |
| commit | 33c4ad40f4f8b48c1efbb510956de173b192a5d7 (patch) | |
| tree | db01f81942780fecef467a50f8687ac5b12213ea | |
| parent | 33a8f3c1983c6e889822d0516b571752667536c7 (diff) | |
| download | x-33c4ad40f4f8b48c1efbb510956de173b192a5d7.tar.xz x-33c4ad40f4f8b48c1efbb510956de173b192a5d7.zip | |
yk: new tool for testing yubikey
| -rw-r--r-- | yk/main.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/yk/main.go b/yk/main.go new file mode 100644 index 0000000..56e8417 --- /dev/null +++ b/yk/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strings" + + "github.com/GeertJohan/yubigo" + _ "github.com/joho/godotenv/autoload" + "github.com/kr/pretty" +) + +func main() { + yubiAuth, err := yubigo.NewYubiAuth(os.Getenv("YUBIKEY_CLIENT_ID"), os.Getenv("YUBIKEY_SECRET_KEY")) + if err != nil { + log.Fatal(err) + } + _ = yubiAuth + + reader := bufio.NewReader(os.Stdin) + fmt.Print("yk> ") + text, err := reader.ReadString(byte('\n')) + if err != nil { + log.Fatal(err) + } + + text = strings.TrimSpace(text) + + resp, _, err := yubiAuth.Verify(text) + if err != nil { + log.Fatal(err) + } + + pretty.Println(resp) + + if !resp.IsValidOTP() { + log.Fatal("invalid OTP") + } + + prefix, _, err := yubigo.ParseOTP(text) + if err != nil { + log.Fatal(err) + } + + log.Printf("uid: %s", prefix) +} |
