From 2d322f5093c10aaae5053f2e4f4a959a08040e5d Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 30 Nov 2019 16:40:22 +0000 Subject: [PATCH] initial commit --- .gitignore | 1 + LICENSE | 12 ++++++++++++ README.md | 3 +++ go.mod | 15 +++++++++++++++ go.sum | 21 +++++++++++++++++++++ main.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87df039 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (c) 2019 Christine Dodrill + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..363de0e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# yubidude + +Yubidude is a small yubikey OTP tester and username extractor sample. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1e750b2 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module tulpa.dev/cadey/yubidude + +go 1.13 + +require ( + github.com/GeertJohan/yubigo v0.0.0-20190917122436-175bc097e60e + github.com/conformal/yubikey v0.0.0-20140117205816-65ac3de5ed8f + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 // indirect + github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456 + github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect + github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect + github.com/joho/godotenv v1.3.0 + github.com/kr/pretty v0.1.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3124774 --- /dev/null +++ b/go.sum @@ -0,0 +1,21 @@ +github.com/GeertJohan/yubigo v0.0.0-20190917122436-175bc097e60e h1:Bqtt5C+uVk+vH/t5dmB47uDCTwxw16EYHqvJnmY2aQc= +github.com/GeertJohan/yubigo v0.0.0-20190917122436-175bc097e60e/go.mod h1:njRCDrl+1RQ/A/+KVU8Ho2EWAxUSkohOWczdW3dzDG0= +github.com/conformal/yubikey v0.0.0-20140117205816-65ac3de5ed8f h1:6arIzlpAngUFbjJmFwqdKXCr0iQZkaiAzpDPprqM3Ss= +github.com/conformal/yubikey v0.0.0-20140117205816-65ac3de5ed8f/go.mod h1:zVcG9twkhqcPdA/KivDkevbYHZFWN3gAJkHuxqH4OCc= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ= +github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= +github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456 h1:CkmB2l68uhvRlwOTPrwnuitSxi/S3Cg4L5QYOcL9MBc= +github.com/facebookgo/flagenv v0.0.0-20160425205200-fcd59fca7456/go.mod h1:zFhibDvPDWmtk4dAQ05sRobtyoffEHygEt3wSNuAzz8= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= +github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= +github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y= +github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= diff --git a/main.go b/main.go new file mode 100644 index 0000000..a0141b6 --- /dev/null +++ b/main.go @@ -0,0 +1,55 @@ +package main + +import ( + "bufio" + "flag" + "fmt" + "log" + "os" + "strings" + + "github.com/GeertJohan/yubigo" + "github.com/facebookgo/flagenv" + _ "github.com/joho/godotenv/autoload" +) + +var ( + clientID = flag.String("client-id", "", "yubikey client ID") + secretKey = flag.String("secret-key", "", "yubikey secret key") +) + +func main() { + flagenv.Parse() + flag.Parse() + + ya, err := yubigo.NewYubiAuth(*clientID, *secretKey) + if err != nil { + log.Fatal("bad creds:", err) + } + + reader := bufio.NewReader(os.Stdin) + fmt.Print("Enter text: ") + otp, err := reader.ReadString('\n') + if err != nil { + log.Fatal("error reading OTP:", err) + } + otp = strings.TrimSpace(otp) + fmt.Println("input: ", otp) + + pubID, _, err := yubigo.ParseOTP(otp) + if err != nil { + log.Fatal("error parsing OTP:", err) + } + + fmt.Println("prefix:", string(pubID)) + + _, ok, err := ya.Verify(otp) + if err != nil { + log.Fatal("bad response:", err) + } + if !ok { + log.Fatal("not ok") + } + + fmt.Println("code is valid") +}