From 6fa78a174a3e3d265c285301cff1dbf4edd34747 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sat, 12 Mar 2022 19:51:33 -0700 Subject: [PATCH 01/11] refactor: simplify file orgqanization --- cmd/gophrase/main.go | 24 -------------- internal/constant.go | 16 ---------- {assets => src/assets}/defaults.json | 0 .../assets}/eff_large_wordlist.json | 0 .../assets}/eff_short_wordlist_1.json | 0 .../assets}/eff_short_wordlist_2_0.json | 0 {assets => src/assets}/list_options.txt | 0 {assets => src/assets}/reinhold_wordlist.json | 0 .../assets}/special_characters.json | 0 {internal/argument => src/command}/command.go | 10 +++--- {pkg => src}/config/config.go | 14 +++++++-- {pkg => src}/config/config_test.go | 0 {pkg => src}/corpus/corpus.go | 15 +++++---- {pkg => src}/corpus/corpus_test.go | 0 .../cpuguy83/go-md2man/v2/md2man/LICENSE.md | 0 .../github.com/gobuffalo/logger/LICENSE | 0 .../github.com/gobuffalo/packd/LICENSE | 0 .../takeon/github.com/markbates/errx/LICENSE | 0 .../github.com/gobuffalo/packr/v2/LICENSE.txt | 0 .../github.com/karrick/godirwalk/LICENSE | 0 .../github.com/markbates/errx/LICENSE | 0 .../github.com/markbates/oncer/LICENSE | 0 .../github.com/markbates/safe/LICENSE | 0 .../nbutton23/zxcvbn-go/LICENSE.txt | 0 .../russross/blackfriday/v2/LICENSE.txt | 0 .../shurcooL/sanitized_anchor_name/LICENSE | 0 .../github.com/sirupsen/logrus/LICENSE | 0 .../github.com/urfave/cli/v2/LICENSE | 0 .../golang.org/x/crypto/ssh/terminal/LICENSE | 0 .../golang.org/x/sys/unix/LICENSE | 0 {pkg => src}/entropy/entropy.go | 0 {pkg => src}/entropy/entropy_test.go | 0 {pkg => src}/generate/generate.go | 6 ++-- {pkg => src}/generate/generate_test.go | 2 +- go.mod => src/go.mod | 5 ++- go.sum => src/go.sum | 5 --- src/main.go | 31 +++++++++++++++++++ 37 files changed, 60 insertions(+), 68 deletions(-) delete mode 100644 cmd/gophrase/main.go delete mode 100644 internal/constant.go rename {assets => src/assets}/defaults.json (100%) rename {assets => src/assets}/eff_large_wordlist.json (100%) rename {assets => src/assets}/eff_short_wordlist_1.json (100%) rename {assets => src/assets}/eff_short_wordlist_2_0.json (100%) rename {assets => src/assets}/list_options.txt (100%) rename {assets => src/assets}/reinhold_wordlist.json (100%) rename {assets => src/assets}/special_characters.json (100%) rename {internal/argument => src/command}/command.go (93%) rename {pkg => src}/config/config.go (66%) rename {pkg => src}/config/config_test.go (100%) rename {pkg => src}/corpus/corpus.go (78%) rename {pkg => src}/corpus/corpus_test.go (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/cpuguy83/go-md2man/v2/md2man/LICENSE.md (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/gobuffalo/logger/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/gobuffalo/packd/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/gobuffalo/packd/internal/takeon/github.com/markbates/errx/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/gobuffalo/packr/v2/LICENSE.txt (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/karrick/godirwalk/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/markbates/errx/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/markbates/oncer/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/markbates/safe/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/nbutton23/zxcvbn-go/LICENSE.txt (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/russross/blackfriday/v2/LICENSE.txt (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/shurcooL/sanitized_anchor_name/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/sirupsen/logrus/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/github.com/urfave/cli/v2/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/golang.org/x/crypto/ssh/terminal/LICENSE (100%) rename {embedded_licenses => src/embedded_licenses}/golang.org/x/sys/unix/LICENSE (100%) rename {pkg => src}/entropy/entropy.go (100%) rename {pkg => src}/entropy/entropy_test.go (100%) rename {pkg => src}/generate/generate.go (94%) rename {pkg => src}/generate/generate_test.go (98%) rename go.mod => src/go.mod (62%) rename go.sum => src/go.sum (97%) create mode 100644 src/main.go diff --git a/cmd/gophrase/main.go b/cmd/gophrase/main.go deleted file mode 100644 index 582cbc5..0000000 --- a/cmd/gophrase/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "github.com/gophrase/internal" - "github.com/gophrase/internal/argument" - "github.com/urfave/cli/v2" - "log" - "os" -) - -func main() { - app := *cli.NewApp() - app.Name = internal.APP_NAME - app.Usage = internal.APP_USAGE - app.UsageText = internal.APP_USAGETEXT - app.Version = internal.APP_VERSION - app.HideHelp = false - app.HideVersion = false - app.Commands = argument.Commands - err := app.Run(os.Args) - if err != nil { - log.Fatal(err) - } -} diff --git a/internal/constant.go b/internal/constant.go deleted file mode 100644 index 5e53031..0000000 --- a/internal/constant.go +++ /dev/null @@ -1,16 +0,0 @@ -package internal - -// App information constants -const APP_NAME = "Go Phrase" -const APP_USAGE = "CLI for generating secure, memorable passwords" -const APP_VERSION = "v1.0.0 | release: 5.10.20" -const APP_USAGETEXT = "gophrase gen [word count] [word list] [--flags]" - -// Static asset constants -const EFF_LARGE = "eff_large_wordlist.json" -const EFF_SHORT_1 = "eff_short_wordlist_1.json" -const EFF_SHORT_2 = "eff_short_wordlist_2_0.json" -const REINHOLD = "reinhold_wordlist.json" -const CHARACTERS = "special_characters.json" -const LIST_OPTIONS = "list_options.txt" -const DEFAULTS = "defaults.json" diff --git a/assets/defaults.json b/src/assets/defaults.json similarity index 100% rename from assets/defaults.json rename to src/assets/defaults.json diff --git a/assets/eff_large_wordlist.json b/src/assets/eff_large_wordlist.json similarity index 100% rename from assets/eff_large_wordlist.json rename to src/assets/eff_large_wordlist.json diff --git a/assets/eff_short_wordlist_1.json b/src/assets/eff_short_wordlist_1.json similarity index 100% rename from assets/eff_short_wordlist_1.json rename to src/assets/eff_short_wordlist_1.json diff --git a/assets/eff_short_wordlist_2_0.json b/src/assets/eff_short_wordlist_2_0.json similarity index 100% rename from assets/eff_short_wordlist_2_0.json rename to src/assets/eff_short_wordlist_2_0.json diff --git a/assets/list_options.txt b/src/assets/list_options.txt similarity index 100% rename from assets/list_options.txt rename to src/assets/list_options.txt diff --git a/assets/reinhold_wordlist.json b/src/assets/reinhold_wordlist.json similarity index 100% rename from assets/reinhold_wordlist.json rename to src/assets/reinhold_wordlist.json diff --git a/assets/special_characters.json b/src/assets/special_characters.json similarity index 100% rename from assets/special_characters.json rename to src/assets/special_characters.json diff --git a/internal/argument/command.go b/src/command/command.go similarity index 93% rename from internal/argument/command.go rename to src/command/command.go index b460e6c..5e69e2e 100644 --- a/internal/argument/command.go +++ b/src/command/command.go @@ -1,11 +1,11 @@ -package argument +package main import ( "fmt" - "github.com/gophrase/pkg/config" - "github.com/gophrase/pkg/corpus" - "github.com/gophrase/pkg/entropy" - "github.com/gophrase/pkg/generate" + "github.com/jmillerv/gophrase/config" + "github.com/jmillerv/gophrase/corpus" + "github.com/jmillerv/gophrase/entropy" + "github.com/jmillerv/gophrase/generate" "github.com/urfave/cli/v2" "strconv" ) diff --git a/pkg/config/config.go b/src/config/config.go similarity index 66% rename from pkg/config/config.go rename to src/config/config.go index 7525b70..8caffcd 100644 --- a/pkg/config/config.go +++ b/src/config/config.go @@ -4,11 +4,19 @@ import ( "encoding/json" "fmt" "github.com/gobuffalo/packr/v2" - "github.com/gophrase/internal" "io/ioutil" "log" ) +// Static asset constants +const EFF_LARGE = "eff_large_wordlist.json" +const EFF_SHORT_1 = "eff_short_wordlist_1.json" +const EFF_SHORT_2 = "eff_short_wordlist_2_0.json" +const REINHOLD = "reinhold_wordlist.json" +const CHARACTERS = "special_characters.json" +const LIST_OPTIONS = "list_options.txt" +const DEFAULTS = "defaults.json" + type Default struct { WordCount int `json:"wordCount"` WordList string `json:"wordList"` @@ -18,7 +26,7 @@ var Assets = packr.New("assets", "../../assets") var Defaults = new(Default) func SetConfigDefaults(config *Default, count int, list string) { - fileLocation := internal.DEFAULTS //TODO create better implementation + fileLocation := DEFAULTS // TODO create better implementation config.WordCount = count config.WordList = list file, err := json.MarshalIndent(config, "", "\t") @@ -32,7 +40,7 @@ func SetConfigDefaults(config *Default, count int, list string) { } func LoadConfigDefaults() { - fileLocation, err := Assets.Find(internal.DEFAULTS) + fileLocation, err := Assets.Find(DEFAULTS) if err != nil { log.Fatal(err) } diff --git a/pkg/config/config_test.go b/src/config/config_test.go similarity index 100% rename from pkg/config/config_test.go rename to src/config/config_test.go diff --git a/pkg/corpus/corpus.go b/src/corpus/corpus.go similarity index 78% rename from pkg/corpus/corpus.go rename to src/corpus/corpus.go index 27fce6d..c358f11 100644 --- a/pkg/corpus/corpus.go +++ b/src/corpus/corpus.go @@ -2,15 +2,14 @@ package corpus import ( "encoding/json" - "github.com/gophrase/internal" - "github.com/gophrase/pkg/config" + "github.com/jmillerv/gophrase/config" "log" "math/rand" "time" ) func getSpecialCharList() []byte { - fileLocation, err := config.Assets.Find(internal.CHARACTERS) + fileLocation, err := config.Assets.Find(config.CHARACTERS) if err != nil { log.Fatal(err) } @@ -52,20 +51,20 @@ func SetWordList(wordlist string) string { // This is organized by my personal preference. switch list := wordlist; list { case "a": - return internal.EFF_SHORT_2 + return config.EFF_SHORT_2 case "b": - return internal.EFF_SHORT_1 + return config.EFF_SHORT_1 case "c": - return internal.EFF_LARGE + return config.EFF_LARGE case "d": - return internal.REINHOLD + return config.REINHOLD default: return config.Defaults.WordList } } func PrintWordListOptions() []byte { - fileLocation, err := config.Assets.Find(internal.LIST_OPTIONS) + fileLocation, err := config.Assets.Find(config.LIST_OPTIONS) if err != nil { log.Fatal(err) } diff --git a/pkg/corpus/corpus_test.go b/src/corpus/corpus_test.go similarity index 100% rename from pkg/corpus/corpus_test.go rename to src/corpus/corpus_test.go diff --git a/embedded_licenses/github.com/cpuguy83/go-md2man/v2/md2man/LICENSE.md b/src/embedded_licenses/github.com/cpuguy83/go-md2man/v2/md2man/LICENSE.md similarity index 100% rename from embedded_licenses/github.com/cpuguy83/go-md2man/v2/md2man/LICENSE.md rename to src/embedded_licenses/github.com/cpuguy83/go-md2man/v2/md2man/LICENSE.md diff --git a/embedded_licenses/github.com/gobuffalo/logger/LICENSE b/src/embedded_licenses/github.com/gobuffalo/logger/LICENSE similarity index 100% rename from embedded_licenses/github.com/gobuffalo/logger/LICENSE rename to src/embedded_licenses/github.com/gobuffalo/logger/LICENSE diff --git a/embedded_licenses/github.com/gobuffalo/packd/LICENSE b/src/embedded_licenses/github.com/gobuffalo/packd/LICENSE similarity index 100% rename from embedded_licenses/github.com/gobuffalo/packd/LICENSE rename to src/embedded_licenses/github.com/gobuffalo/packd/LICENSE diff --git a/embedded_licenses/github.com/gobuffalo/packd/internal/takeon/github.com/markbates/errx/LICENSE b/src/embedded_licenses/github.com/gobuffalo/packd/internal/takeon/github.com/markbates/errx/LICENSE similarity index 100% rename from embedded_licenses/github.com/gobuffalo/packd/internal/takeon/github.com/markbates/errx/LICENSE rename to src/embedded_licenses/github.com/gobuffalo/packd/internal/takeon/github.com/markbates/errx/LICENSE diff --git a/embedded_licenses/github.com/gobuffalo/packr/v2/LICENSE.txt b/src/embedded_licenses/github.com/gobuffalo/packr/v2/LICENSE.txt similarity index 100% rename from embedded_licenses/github.com/gobuffalo/packr/v2/LICENSE.txt rename to src/embedded_licenses/github.com/gobuffalo/packr/v2/LICENSE.txt diff --git a/embedded_licenses/github.com/karrick/godirwalk/LICENSE b/src/embedded_licenses/github.com/karrick/godirwalk/LICENSE similarity index 100% rename from embedded_licenses/github.com/karrick/godirwalk/LICENSE rename to src/embedded_licenses/github.com/karrick/godirwalk/LICENSE diff --git a/embedded_licenses/github.com/markbates/errx/LICENSE b/src/embedded_licenses/github.com/markbates/errx/LICENSE similarity index 100% rename from embedded_licenses/github.com/markbates/errx/LICENSE rename to src/embedded_licenses/github.com/markbates/errx/LICENSE diff --git a/embedded_licenses/github.com/markbates/oncer/LICENSE b/src/embedded_licenses/github.com/markbates/oncer/LICENSE similarity index 100% rename from embedded_licenses/github.com/markbates/oncer/LICENSE rename to src/embedded_licenses/github.com/markbates/oncer/LICENSE diff --git a/embedded_licenses/github.com/markbates/safe/LICENSE b/src/embedded_licenses/github.com/markbates/safe/LICENSE similarity index 100% rename from embedded_licenses/github.com/markbates/safe/LICENSE rename to src/embedded_licenses/github.com/markbates/safe/LICENSE diff --git a/embedded_licenses/github.com/nbutton23/zxcvbn-go/LICENSE.txt b/src/embedded_licenses/github.com/nbutton23/zxcvbn-go/LICENSE.txt similarity index 100% rename from embedded_licenses/github.com/nbutton23/zxcvbn-go/LICENSE.txt rename to src/embedded_licenses/github.com/nbutton23/zxcvbn-go/LICENSE.txt diff --git a/embedded_licenses/github.com/russross/blackfriday/v2/LICENSE.txt b/src/embedded_licenses/github.com/russross/blackfriday/v2/LICENSE.txt similarity index 100% rename from embedded_licenses/github.com/russross/blackfriday/v2/LICENSE.txt rename to src/embedded_licenses/github.com/russross/blackfriday/v2/LICENSE.txt diff --git a/embedded_licenses/github.com/shurcooL/sanitized_anchor_name/LICENSE b/src/embedded_licenses/github.com/shurcooL/sanitized_anchor_name/LICENSE similarity index 100% rename from embedded_licenses/github.com/shurcooL/sanitized_anchor_name/LICENSE rename to src/embedded_licenses/github.com/shurcooL/sanitized_anchor_name/LICENSE diff --git a/embedded_licenses/github.com/sirupsen/logrus/LICENSE b/src/embedded_licenses/github.com/sirupsen/logrus/LICENSE similarity index 100% rename from embedded_licenses/github.com/sirupsen/logrus/LICENSE rename to src/embedded_licenses/github.com/sirupsen/logrus/LICENSE diff --git a/embedded_licenses/github.com/urfave/cli/v2/LICENSE b/src/embedded_licenses/github.com/urfave/cli/v2/LICENSE similarity index 100% rename from embedded_licenses/github.com/urfave/cli/v2/LICENSE rename to src/embedded_licenses/github.com/urfave/cli/v2/LICENSE diff --git a/embedded_licenses/golang.org/x/crypto/ssh/terminal/LICENSE b/src/embedded_licenses/golang.org/x/crypto/ssh/terminal/LICENSE similarity index 100% rename from embedded_licenses/golang.org/x/crypto/ssh/terminal/LICENSE rename to src/embedded_licenses/golang.org/x/crypto/ssh/terminal/LICENSE diff --git a/embedded_licenses/golang.org/x/sys/unix/LICENSE b/src/embedded_licenses/golang.org/x/sys/unix/LICENSE similarity index 100% rename from embedded_licenses/golang.org/x/sys/unix/LICENSE rename to src/embedded_licenses/golang.org/x/sys/unix/LICENSE diff --git a/pkg/entropy/entropy.go b/src/entropy/entropy.go similarity index 100% rename from pkg/entropy/entropy.go rename to src/entropy/entropy.go diff --git a/pkg/entropy/entropy_test.go b/src/entropy/entropy_test.go similarity index 100% rename from pkg/entropy/entropy_test.go rename to src/entropy/entropy_test.go diff --git a/pkg/generate/generate.go b/src/generate/generate.go similarity index 94% rename from pkg/generate/generate.go rename to src/generate/generate.go index 6fea1fe..cda24fa 100644 --- a/pkg/generate/generate.go +++ b/src/generate/generate.go @@ -1,8 +1,8 @@ package generate import ( - "github.com/gophrase/internal" - "github.com/gophrase/pkg/corpus" + "github.com/jmillerv/gophrase/config" + "github.com/jmillerv/gophrase/corpus" "math/rand" "strconv" "strings" @@ -69,7 +69,7 @@ func key(wordList string) int { } func keySize(wordList string) int { - if wordList == internal.EFF_SHORT_1 || wordList == internal.EFF_SHORT_2 { + if wordList == config.EFF_SHORT_1 || wordList == config.EFF_SHORT_2 { return 4 } else { return 5 diff --git a/pkg/generate/generate_test.go b/src/generate/generate_test.go similarity index 98% rename from pkg/generate/generate_test.go rename to src/generate/generate_test.go index 2e4c73c..1b6040d 100644 --- a/pkg/generate/generate_test.go +++ b/src/generate/generate_test.go @@ -1,7 +1,7 @@ package generate import ( - "github.com/gophrase/pkg/corpus" + "github.com/jmillerv/gophrase/corpus" "math" "regexp" "strings" diff --git a/go.mod b/src/go.mod similarity index 62% rename from go.mod rename to src/go.mod index 5e772b6..9fcc6ce 100644 --- a/go.mod +++ b/src/go.mod @@ -1,10 +1,9 @@ -module github.com/gophrase +module github.com/jmillerv/gophrase -go 1.13 +go 1.18 require ( github.com/gobuffalo/packr/v2 v2.8.0 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d github.com/urfave/cli/v2 v2.1.1 - golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 ) diff --git a/go.sum b/src/go.sum similarity index 97% rename from go.sum rename to src/go.sum index 07f8fa0..e638f00 100644 --- a/go.sum +++ b/src/go.sum @@ -13,7 +13,6 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -59,10 +58,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -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= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= @@ -163,7 +160,6 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 h1:9Di9iYgOt9ThCipBxChBVhgNipDoE5mxO84rQV7D0FE= golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -174,7 +170,6 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..324db05 --- /dev/null +++ b/src/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "github.com/jmillerv/gophrase/src/command" + "github.com/urfave/cli/v2" + "log" + "os" +) + +// App information constants +const APP_NAME = "Go Phrase" +const APP_USAGE = "CLI for generating secure, memorable passwords" +const APP_VERSION = "v2.0.0 | release: 3.13.22" +const APP_USAGETEXT = "gophrase gen [word count] [word list] [--flags]" + +// go:embed + +func main() { + app := *cli.NewApp() + app.Name = APP_NAME + app.Usage = APP_USAGE + app.UsageText = APP_USAGETEXT + app.Version = APP_VERSION + app.HideHelp = false + app.HideVersion = false + app.Commands = command.Commands + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} From 7af916c724ec084fbb478b7dfc652a10db1e5f14 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sat, 12 Mar 2022 21:20:18 -0700 Subject: [PATCH 02/11] refactor/assets: move wordlists into their own directory --- src/assets/defaults.json | 4 ---- src/assets/{ => wordlists}/eff_large_wordlist.json | 0 src/assets/{ => wordlists}/eff_short_wordlist_1.json | 0 .../eff_short_wordlist_2.json} | 0 src/assets/{ => wordlists}/reinhold_wordlist.json | 0 src/assets/{ => wordlists}/special_characters.json | 0 6 files changed, 4 deletions(-) delete mode 100644 src/assets/defaults.json rename src/assets/{ => wordlists}/eff_large_wordlist.json (100%) rename src/assets/{ => wordlists}/eff_short_wordlist_1.json (100%) rename src/assets/{eff_short_wordlist_2_0.json => wordlists/eff_short_wordlist_2.json} (100%) rename src/assets/{ => wordlists}/reinhold_wordlist.json (100%) rename src/assets/{ => wordlists}/special_characters.json (100%) diff --git a/src/assets/defaults.json b/src/assets/defaults.json deleted file mode 100644 index 2f8ee80..0000000 --- a/src/assets/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "wordCount": 5, - "wordList": "eff_short_wordlist_2_0.json" -} \ No newline at end of file diff --git a/src/assets/eff_large_wordlist.json b/src/assets/wordlists/eff_large_wordlist.json similarity index 100% rename from src/assets/eff_large_wordlist.json rename to src/assets/wordlists/eff_large_wordlist.json diff --git a/src/assets/eff_short_wordlist_1.json b/src/assets/wordlists/eff_short_wordlist_1.json similarity index 100% rename from src/assets/eff_short_wordlist_1.json rename to src/assets/wordlists/eff_short_wordlist_1.json diff --git a/src/assets/eff_short_wordlist_2_0.json b/src/assets/wordlists/eff_short_wordlist_2.json similarity index 100% rename from src/assets/eff_short_wordlist_2_0.json rename to src/assets/wordlists/eff_short_wordlist_2.json diff --git a/src/assets/reinhold_wordlist.json b/src/assets/wordlists/reinhold_wordlist.json similarity index 100% rename from src/assets/reinhold_wordlist.json rename to src/assets/wordlists/reinhold_wordlist.json diff --git a/src/assets/special_characters.json b/src/assets/wordlists/special_characters.json similarity index 100% rename from src/assets/special_characters.json rename to src/assets/wordlists/special_characters.json From e66aa07250b36c472438c0f144f2970043da7760 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 15:49:14 -0400 Subject: [PATCH 03/11] command/command: update command names. --- src/command/command.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/command/command.go b/src/command/command.go index 5e69e2e..18ed1da 100644 --- a/src/command/command.go +++ b/src/command/command.go @@ -1,4 +1,4 @@ -package main +package command import ( "fmt" @@ -6,6 +6,7 @@ import ( "github.com/jmillerv/gophrase/corpus" "github.com/jmillerv/gophrase/entropy" "github.com/jmillerv/gophrase/generate" + "github.com/jmillerv/gophrase/handlers" "github.com/urfave/cli/v2" "strconv" ) @@ -65,7 +66,7 @@ var Commands = []*cli.Command{ }, }, { - Name: "Wordlist Options", + Name: "wordlist-options", Aliases: []string{"opts"}, Usage: "View the wordlist options for passphrase generation", Action: func(c *cli.Context) error { @@ -74,7 +75,7 @@ var Commands = []*cli.Command{ }, }, { - Name: "Set Defaults", + Name: "set-defaults", Aliases: []string{"sd"}, Usage: "Set default options for word count and word list", Action: func(c *cli.Context) error { @@ -92,7 +93,7 @@ var Commands = []*cli.Command{ }, }, { - Name: "List Defaults", + Name: "list-defaults", Aliases: []string{"ld"}, Usage: "Print default options for word count and word list", Action: func(c *cli.Context) error { @@ -101,4 +102,13 @@ var Commands = []*cli.Command{ return nil }, }, + { + Name: "run-server", + Aliases: []string{"serve"}, + Usage: "Start a gophrase server", + Action: func(c *cli.Context) error { + handlers.RunServer() + return nil + }, + }, } From d507a87545f9685396674b8f17b3a4825116490a Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 15:58:40 -0400 Subject: [PATCH 04/11] entropy/entrpoy: implement PrintEntropy --- src/entropy/entropy.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/entropy/entropy.go b/src/entropy/entropy.go index 691b940..3cdbb0a 100644 --- a/src/entropy/entropy.go +++ b/src/entropy/entropy.go @@ -5,9 +5,10 @@ import ( "github.com/nbutton23/zxcvbn-go" ) -// Initially I wrote my own entropy calculator but found this package that's based on a Dropbox +// Initially I wrote my own entropy calculator but found this package that's based on a Dropbox package // it's more conservative in its estimation than my original and those I found online. So, it's included here. +// PrintEntropy returns the metadata about the strenght of a given passphrase func PrintEntropy(passphrase string) { entropy := zxcvbn.PasswordStrength(passphrase, nil) fmt.Println("Password: " + entropy.Password) From 09b38e4ec3b36b1c42a04e96a009d87e2cede7f5 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 20:13:24 -0400 Subject: [PATCH 05/11] gitignore: update binary exclusion --- .gitignore | 2 +- src/assets/config/config.yaml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/assets/config/config.yaml diff --git a/.gitignore b/.gitignore index 57bc138..12eb2e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.idea -cmd/gophrase/gophrase \ No newline at end of file +src/gophrase \ No newline at end of file diff --git a/src/assets/config/config.yaml b/src/assets/config/config.yaml new file mode 100644 index 0000000..f371311 --- /dev/null +++ b/src/assets/config/config.yaml @@ -0,0 +1,5 @@ +WordCount: 5 +WordList: eff_short_wordlist_1.json +Capital: false +Special: false +Number: true From 59c78ce8858741538e31dfb68de3bd23d8632f3d Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 20:14:01 -0400 Subject: [PATCH 06/11] docs: update list_options.txt --- src/assets/list_options.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assets/list_options.txt b/src/assets/list_options.txt index c2b9daf..e514921 100644 --- a/src/assets/list_options.txt +++ b/src/assets/list_options.txt @@ -2,8 +2,8 @@ Wordlist Options To set the list `gophrase gen 5 a` or `gophrase gen a` if you are okay with a three word passphrase. -a: EFF Short Wordlist 2 -b: EFF Short Wordlist 1 +a: EFF Short Wordlist 1 +b: EFF Short Wordlist 2 c: EFF Large Wordlist d: Reinhold Wordlist From 1ded014898d2ad2e5ad432c6d62333d1dfb6a7bf Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 20:14:57 -0400 Subject: [PATCH 07/11] refactor: remove packr dependency & add configuration functionality --- src/command/command.go | 62 +++++++++++++++++++++++++++++---------- src/config/config.go | 59 +++++++++++++++++++------------------ src/config/config_test.go | 13 -------- src/corpus/corpus.go | 17 +++++------ src/corpus/corpus_test.go | 12 ++++---- src/generate/generate.go | 6 ++-- src/go.mod | 4 ++- src/go.sum | 7 +++++ src/main.go | 27 ++++++++++------- 9 files changed, 122 insertions(+), 85 deletions(-) diff --git a/src/command/command.go b/src/command/command.go index 18ed1da..840e500 100644 --- a/src/command/command.go +++ b/src/command/command.go @@ -11,6 +11,10 @@ import ( "strconv" ) +const ( + defaultWordCount = 5 +) + var Commands = []*cli.Command{ { Name: "generate", @@ -18,27 +22,27 @@ var Commands = []*cli.Command{ Usage: "gen [int]", Action: func(c *cli.Context) error { // TODO input validator to clean up section - config.LoadConfigDefaults() + config.LoadConfig() p := generate.Params{} p.WordCount, _ = strconv.Atoi(c.Args().Get(0)) if p.WordCount == 0 { - p.WordCount = config.Defaults.WordCount + p.WordCount = config.LoadedConfig.WordCount } p.WordList = c.Args().Get(1) if p.WordList == "" { - p.WordList = config.Defaults.WordList + p.WordList = config.LoadedConfig.WordList } - if c.Bool("capital") { + if c.Bool("capital") || config.LoadedConfig.Capital { p.Capitals = true } else { p.Capitals = false } - if c.Bool("special") { + if c.Bool("special") || config.LoadedConfig.Special { p.SpecialChars = true } else { p.SpecialChars = false } - if c.Bool("number") { + if c.Bool("number") || config.LoadedConfig.Number { p.Numbers = true } else { p.Numbers = false @@ -78,17 +82,43 @@ var Commands = []*cli.Command{ Name: "set-defaults", Aliases: []string{"sd"}, Usage: "Set default options for word count and word list", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "capital", + Aliases: []string{"c"}, + Usage: "Add random capitalization to your passwords", + }, + &cli.BoolFlag{ + Name: "special", + Aliases: []string{"s"}, + Usage: "Add random special characters to your passwords", + }, + &cli.BoolFlag{ + Name: "number", + Aliases: []string{"n"}, + Usage: "Add numbers to your passwords", + }, + }, Action: func(c *cli.Context) error { - p := generate.Params{} - p.WordCount, _ = strconv.Atoi(c.Args().Get(0)) - if p.WordCount == 0 { - p.WordCount = config.Defaults.WordCount + conf := &config.Config{} + conf.WordCount, _ = strconv.Atoi(c.Args().Get(0)) + if conf.WordCount == 0 { + conf.WordCount = defaultWordCount } - p.WordList = corpus.SetWordList(c.Args().Get(1)) - if p.WordList == "" { - p.WordList = config.Defaults.WordList + conf.WordList = corpus.SetWordList(c.Args().Get(1)) + if conf.WordList == "" { + conf.WordList = config.EffShort1 + } + if c.Bool("capital") { + conf.Capital = true + } + if c.Bool("special") { + conf.Special = true + } + if c.Bool("number") { + conf.Number = true } - config.SetConfigDefaults(config.Defaults, p.WordCount, p.WordList) + config.SetConfigDefaults(conf) return nil }, }, @@ -97,8 +127,8 @@ var Commands = []*cli.Command{ Aliases: []string{"ld"}, Usage: "Print default options for word count and word list", Action: func(c *cli.Context) error { - config.LoadConfigDefaults() - config.PrintConfigDefaults(config.Defaults) + config.LoadConfig() + config.LoadedConfig.PrintConfig() return nil }, }, diff --git a/src/config/config.go b/src/config/config.go index 8caffcd..d8e9945 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -1,55 +1,58 @@ package config import ( - "encoding/json" - "fmt" - "github.com/gobuffalo/packr/v2" + "embed" + "github.com/jmillerv/go-utilities/format" + "gopkg.in/yaml.v3" "io/ioutil" "log" ) // Static asset constants -const EFF_LARGE = "eff_large_wordlist.json" -const EFF_SHORT_1 = "eff_short_wordlist_1.json" -const EFF_SHORT_2 = "eff_short_wordlist_2_0.json" -const REINHOLD = "reinhold_wordlist.json" -const CHARACTERS = "special_characters.json" -const LIST_OPTIONS = "list_options.txt" -const DEFAULTS = "defaults.json" +const ( + EffLarge = "assets/wordlists/eff_large_wordlist.json" + EffShort1 = "assets/wordlists/eff_short_wordlist_1.json" + EffShort2 = "assets/wordlists/eff_short_wordlist_2.json" + Reinhold = "assets/wordlists/reinhold_wordlist.json" + Characters = "assets/wordlists/special_characters.json" + ListOptions = "assets/list_options.txt" + Configuration = "assets/config/config.yaml" +) + +var Assets embed.FS +var LoadedConfig = new(Config) -type Default struct { - WordCount int `json:"wordCount"` - WordList string `json:"wordList"` +type Config struct { + WordCount int `yaml:"WordCount"` + WordList string `yaml:"WordList"` + Capital bool `yaml:"Capital"` + Special bool `yaml:"Special"` + Number bool `yaml:"Number"` } -var Assets = packr.New("assets", "../../assets") -var Defaults = new(Default) +func (c *Config) PrintConfig() { + log.Print(format.StructToIndentedString(c)) +} -func SetConfigDefaults(config *Default, count int, list string) { - fileLocation := DEFAULTS // TODO create better implementation - config.WordCount = count - config.WordList = list - file, err := json.MarshalIndent(config, "", "\t") +func SetConfigDefaults(config *Config) { + fileLocation := Configuration // TODO create better implementation + file, err := yaml.Marshal(config) if err != nil { log.Fatal(err) } - err = ioutil.WriteFile("../../assets/"+fileLocation, file, 0644) + err = ioutil.WriteFile(fileLocation, file, 0644) if err != nil { log.Fatal(err) } } -func LoadConfigDefaults() { - fileLocation, err := Assets.Find(DEFAULTS) +func LoadConfig() { + fileLocation, err := Assets.ReadFile(Configuration) if err != nil { log.Fatal(err) } - err = json.Unmarshal(fileLocation, &Defaults) + err = yaml.Unmarshal(fileLocation, &LoadedConfig) if err != nil { log.Fatal(err) } } - -func PrintConfigDefaults(config *Default) { - fmt.Printf("Word Count: %d \nWord List: %s \n", config.WordCount, config.WordList) -} diff --git a/src/config/config_test.go b/src/config/config_test.go index e4df9b0..d912156 100644 --- a/src/config/config_test.go +++ b/src/config/config_test.go @@ -1,14 +1 @@ package config - -import ( - "github.com/gophrase/internal" - "testing" -) - -func TestPrintConfigDefaults(t *testing.T) { - var defaults = Default{ - WordCount: 3, - WordList: internal.EFF_SHORT_2, - } - PrintConfigDefaults(&defaults) -} diff --git a/src/corpus/corpus.go b/src/corpus/corpus.go index c358f11..853b3b9 100644 --- a/src/corpus/corpus.go +++ b/src/corpus/corpus.go @@ -9,7 +9,7 @@ import ( ) func getSpecialCharList() []byte { - fileLocation, err := config.Assets.Find(config.CHARACTERS) + fileLocation, err := config.Assets.ReadFile(config.Characters) if err != nil { log.Fatal(err) } @@ -29,7 +29,7 @@ func GetSpecialChar() string { } func getWordList(wordlist string) []byte { - fileLocation, err := config.Assets.Find(SetWordList(wordlist)) + fileLocation, err := config.Assets.ReadFile(SetWordList(wordlist)) if err != nil { log.Fatal(err) } @@ -48,23 +48,22 @@ func GetWord(key int, wordlist string) string { } func SetWordList(wordlist string) string { - // This is organized by my personal preference. switch list := wordlist; list { case "a": - return config.EFF_SHORT_2 + return config.EffShort1 case "b": - return config.EFF_SHORT_1 + return config.EffShort2 case "c": - return config.EFF_LARGE + return config.EffLarge case "d": - return config.REINHOLD + return config.Reinhold default: - return config.Defaults.WordList + return config.LoadedConfig.WordList } } func PrintWordListOptions() []byte { - fileLocation, err := config.Assets.Find(config.LIST_OPTIONS) + fileLocation, err := config.Assets.ReadFile(config.ListOptions) if err != nil { log.Fatal(err) } diff --git a/src/corpus/corpus_test.go b/src/corpus/corpus_test.go index c026906..db263cf 100644 --- a/src/corpus/corpus_test.go +++ b/src/corpus/corpus_test.go @@ -1,7 +1,7 @@ package corpus import ( - "github.com/gophrase/internal" + "github.com/jmillerv/gophrase/config" "testing" ) @@ -27,19 +27,19 @@ func TestSetWordList(t *testing.T) { var testValues = tables{"a", "b", "c", "d", ""} - if SetWordList(testValues.first) != internal.EFF_SHORT_2 { + if SetWordList(testValues.first) != config.EffShort2 { t.Errorf("SetWordList() failed expected 'eff_short_wordlist_2_0.json', but got %s", SetWordList(testValues.first)) } - if SetWordList(testValues.second) != internal.EFF_SHORT_1 { + if SetWordList(testValues.second) != config.EffShort1 { t.Errorf("SetWordList() failed expected 'eff_short_wordlist_1.json', but got %s", SetWordList(testValues.second)) } - if SetWordList(testValues.third) != internal.EFF_LARGE { + if SetWordList(testValues.third) != config.EffLarge { t.Errorf("SetWordList() failed expected 'eff_large_wordlist.json', but got %s", SetWordList(testValues.third)) } - if SetWordList(testValues.fourth) != internal.REINHOLD { + if SetWordList(testValues.fourth) != config.Reinhold { t.Errorf("SetWordList() failed expected 'reinhold_wordlist.json', but got %s", SetWordList(testValues.fourth)) } - if SetWordList(testValues.fifth) != internal.EFF_SHORT_2 { + if SetWordList(testValues.fifth) != config.EffShort1 { t.Errorf("SetWordList() failed expected 'eff_short_wordlist_2_0.json', but got %s", SetWordList(testValues.fifth)) } } diff --git a/src/generate/generate.go b/src/generate/generate.go index cda24fa..d5061b7 100644 --- a/src/generate/generate.go +++ b/src/generate/generate.go @@ -68,8 +68,9 @@ func key(wordList string) int { return key } +// keySize determines the size of the key for random generation based on the wordlist used. func keySize(wordList string) int { - if wordList == config.EFF_SHORT_1 || wordList == config.EFF_SHORT_2 { + if wordList == config.EffShort1 || wordList == config.EffShort2 { return 4 } else { return 5 @@ -93,11 +94,12 @@ func Password(p *Params) string { func SpecialCharacters(passphrase []string) []string { rand.Seed(time.Now().UnixNano()) passphrase = append(passphrase, "") - charCount := rand.Intn(len(passphrase)) + 1 + charCount := rand.Intn(len(passphrase)) + 1 // add a random number of special characters for i := 0; i < charCount; i++ { char := corpus.GetSpecialChar() passphrase = append(passphrase, char) } + // shuffle the special characters so they aren't just at the end of a string array rand.Shuffle(len(passphrase), func(i, j int) { passphrase[i], passphrase[j] = passphrase[j], passphrase[i] }) return passphrase } diff --git a/src/go.mod b/src/go.mod index 9fcc6ce..97f3345 100644 --- a/src/go.mod +++ b/src/go.mod @@ -3,7 +3,9 @@ module github.com/jmillerv/gophrase go 1.18 require ( - github.com/gobuffalo/packr/v2 v2.8.0 + github.com/jmillerv/go-utilities v0.0.0-20220606212806-2039fdaf4823 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d + github.com/sirupsen/logrus v1.4.2 github.com/urfave/cli/v2 v2.1.1 + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/src/go.sum b/src/go.sum index e638f00..7839c7e 100644 --- a/src/go.sum +++ b/src/go.sum @@ -13,6 +13,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -22,6 +23,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -48,12 +50,15 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmillerv/go-utilities v0.0.0-20220606212806-2039fdaf4823 h1:JOA81tckQ0Ep/P6iE0oHuXbtL25MCf8gD4sz3NwsWgc= +github.com/jmillerv/go-utilities v0.0.0-20220606212806-2039fdaf4823/go.mod h1:okN4LUTlx7FrTlYcVKXZs059xgpOldGWZupW2MeJXuE= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/karrick/godirwalk v1.15.3 h1:0a2pXOgtB16CqIqXTiT7+K9L73f74n/aNQUnH6Ortew= github.com/karrick/godirwalk v1.15.3/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -177,4 +182,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/src/main.go b/src/main.go index 324db05..c24b746 100644 --- a/src/main.go +++ b/src/main.go @@ -1,26 +1,33 @@ package main import ( - "github.com/jmillerv/gophrase/src/command" + "embed" + _ "embed" + "github.com/jmillerv/gophrase/command" + "github.com/jmillerv/gophrase/config" "github.com/urfave/cli/v2" "log" "os" ) // App information constants -const APP_NAME = "Go Phrase" -const APP_USAGE = "CLI for generating secure, memorable passwords" -const APP_VERSION = "v2.0.0 | release: 3.13.22" -const APP_USAGETEXT = "gophrase gen [word count] [word list] [--flags]" +const ( + AppName = "Go Phrase" + AppUsage = "CLI for generating secure, memorable passwords" + AppVersion = "v2.0.0 | release: 8.14.22" + AppUsageText = "gophrase gen [word count] [word list] [--flags]" +) -// go:embed +//go:embed assets/* +var staticFS embed.FS func main() { + config.Assets = staticFS app := *cli.NewApp() - app.Name = APP_NAME - app.Usage = APP_USAGE - app.UsageText = APP_USAGETEXT - app.Version = APP_VERSION + app.Name = AppName + app.Usage = AppUsage + app.UsageText = AppUsageText + app.Version = AppVersion app.HideHelp = false app.HideVersion = false app.Commands = command.Commands From 69b9c89bf221f54f38f0c83d60f678594e9c7de6 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 20:36:32 -0400 Subject: [PATCH 08/11] remove server command --- src/command/command.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/command/command.go b/src/command/command.go index 840e500..f1ad451 100644 --- a/src/command/command.go +++ b/src/command/command.go @@ -6,7 +6,6 @@ import ( "github.com/jmillerv/gophrase/corpus" "github.com/jmillerv/gophrase/entropy" "github.com/jmillerv/gophrase/generate" - "github.com/jmillerv/gophrase/handlers" "github.com/urfave/cli/v2" "strconv" ) @@ -132,13 +131,4 @@ var Commands = []*cli.Command{ return nil }, }, - { - Name: "run-server", - Aliases: []string{"serve"}, - Usage: "Start a gophrase server", - Action: func(c *cli.Context) error { - handlers.RunServer() - return nil - }, - }, } From 9d30b62b552eb368461e79549f8457b5d91525d6 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 20:36:46 -0400 Subject: [PATCH 09/11] update gomod --- src/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go.mod b/src/go.mod index 97f3345..6362434 100644 --- a/src/go.mod +++ b/src/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/jmillerv/go-utilities v0.0.0-20220606212806-2039fdaf4823 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d - github.com/sirupsen/logrus v1.4.2 + github.com/sirupsen/logrus v1.9.0 // indirect github.com/urfave/cli/v2 v2.1.1 gopkg.in/yaml.v3 v3.0.1 ) From 4f25a543cde3500678b506ae133242042e6919a9 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 20:56:26 -0400 Subject: [PATCH 10/11] fix issues with password generation --- src/assets/config/config.yaml | 4 ++-- src/command/command.go | 4 ++-- src/corpus/corpus.go | 16 ++++++++-------- src/go.sum | 6 ++++++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/assets/config/config.yaml b/src/assets/config/config.yaml index f371311..c6c46b0 100644 --- a/src/assets/config/config.yaml +++ b/src/assets/config/config.yaml @@ -1,5 +1,5 @@ WordCount: 5 -WordList: eff_short_wordlist_1.json +WordList: assets/wordlists/eff_short_wordlist_1.json Capital: false Special: false -Number: true +Number: false diff --git a/src/command/command.go b/src/command/command.go index f1ad451..5c5e331 100644 --- a/src/command/command.go +++ b/src/command/command.go @@ -22,7 +22,7 @@ var Commands = []*cli.Command{ Action: func(c *cli.Context) error { // TODO input validator to clean up section config.LoadConfig() - p := generate.Params{} + p := &generate.Params{} p.WordCount, _ = strconv.Atoi(c.Args().Get(0)) if p.WordCount == 0 { p.WordCount = config.LoadedConfig.WordCount @@ -46,7 +46,7 @@ var Commands = []*cli.Command{ } else { p.Numbers = false } - password := generate.Password(&p) + password := generate.Password(p) entropy.PrintEntropy(password) return nil }, diff --git a/src/corpus/corpus.go b/src/corpus/corpus.go index 853b3b9..06cffba 100644 --- a/src/corpus/corpus.go +++ b/src/corpus/corpus.go @@ -3,15 +3,15 @@ package corpus import ( "encoding/json" "github.com/jmillerv/gophrase/config" - "log" + log "github.com/sirupsen/logrus" "math/rand" "time" ) func getSpecialCharList() []byte { - fileLocation, err := config.Assets.ReadFile(config.Characters) + fileLocation, err := config.Assets.ReadFile("../" + config.Characters) if err != nil { - log.Fatal(err) + log.WithField("function", "getSpecialCharList").WithError(err).Fatal("unable to load special characters") } return fileLocation } @@ -22,16 +22,16 @@ func GetSpecialChar() string { corpus := getSpecialCharList() err := json.Unmarshal(corpus, &chars) if err != nil { - log.Fatal(err) + log.WithError(err).Fatal("json.Unmarshal") } key := rand.Intn(len(chars)) + 1 return chars[key] } func getWordList(wordlist string) []byte { - fileLocation, err := config.Assets.ReadFile(SetWordList(wordlist)) + fileLocation, err := config.Assets.ReadFile(wordlist) if err != nil { - log.Fatal(err) + log.WithError(err).Fatal("unable to read file") } return fileLocation } @@ -41,7 +41,7 @@ func GetWord(key int, wordlist string) string { corpus := getWordList(wordlist) err := json.Unmarshal(corpus, &words) if err != nil { - log.Fatal(err) + log.WithField("function", "GetWord").WithError(err).Fatal("json.Unmarshal") } word := words[key] return word @@ -65,7 +65,7 @@ func SetWordList(wordlist string) string { func PrintWordListOptions() []byte { fileLocation, err := config.Assets.ReadFile(config.ListOptions) if err != nil { - log.Fatal(err) + log.WithField("function", "PrintWordListOptions").WithError(err).Error("unable to read file") } return fileLocation } diff --git a/src/go.sum b/src/go.sum index 7839c7e..9b14d0f 100644 --- a/src/go.sum +++ b/src/go.sum @@ -103,6 +103,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= @@ -118,6 +120,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= @@ -159,6 +162,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -182,6 +187,7 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 5cdd8f13ebff370a4533db66957c8e2e50f44f0b Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Sun, 14 Aug 2022 21:08:12 -0400 Subject: [PATCH 11/11] lint: fix issues --- src/command/command.go | 3 ++- src/config/config.go | 11 +++++++++-- src/corpus/corpus.go | 4 ++++ src/generate/generate.go | 7 +++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/command/command.go b/src/command/command.go index 5c5e331..510428a 100644 --- a/src/command/command.go +++ b/src/command/command.go @@ -14,6 +14,7 @@ const ( defaultWordCount = 5 ) +// Commands hold an array of cli.Commands which are used to run the CLI application. var Commands = []*cli.Command{ { Name: "generate", @@ -117,7 +118,7 @@ var Commands = []*cli.Command{ if c.Bool("number") { conf.Number = true } - config.SetConfigDefaults(conf) + config.SetConfig(conf) return nil }, }, diff --git a/src/config/config.go b/src/config/config.go index d8e9945..582d0ce 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -19,9 +19,13 @@ const ( Configuration = "assets/config/config.yaml" ) +// Assets is the embed.FS file system to access embedded files throughout the application. var Assets embed.FS + +// LoadedConfig is the configuration for gophrase throuhgout the application. var LoadedConfig = new(Config) +// Config holds the values from a configuration file for default generation settings. type Config struct { WordCount int `yaml:"WordCount"` WordList string `yaml:"WordList"` @@ -30,12 +34,14 @@ type Config struct { Number bool `yaml:"Number"` } +// PrintConfig outputs the current config to the console func (c *Config) PrintConfig() { log.Print(format.StructToIndentedString(c)) } -func SetConfigDefaults(config *Config) { - fileLocation := Configuration // TODO create better implementation +// SetConfig takes in a config and writes it to the configuration file. +func SetConfig(config *Config) { + fileLocation := Configuration file, err := yaml.Marshal(config) if err != nil { log.Fatal(err) @@ -46,6 +52,7 @@ func SetConfigDefaults(config *Config) { } } +// LoadConfig reads a configuration file and loads it into the LoadedConfig variable. func LoadConfig() { fileLocation, err := Assets.ReadFile(Configuration) if err != nil { diff --git a/src/corpus/corpus.go b/src/corpus/corpus.go index 06cffba..55fee5e 100644 --- a/src/corpus/corpus.go +++ b/src/corpus/corpus.go @@ -16,6 +16,7 @@ func getSpecialCharList() []byte { return fileLocation } +// GetSpecialChar retrieves a special character from the special_characters.json func GetSpecialChar() string { rand.Seed(time.Now().UnixNano()) chars := make(map[int]string) @@ -36,6 +37,7 @@ func getWordList(wordlist string) []byte { return fileLocation } +// GetWord retrieves a word from the passed in wordlist func GetWord(key int, wordlist string) string { words := make(map[int]string) corpus := getWordList(wordlist) @@ -47,6 +49,7 @@ func GetWord(key int, wordlist string) string { return word } +// SetWordList updates the LoadedConfig.Wordlist property func SetWordList(wordlist string) string { switch list := wordlist; list { case "a": @@ -62,6 +65,7 @@ func SetWordList(wordlist string) string { } } +// PrintWordListOptions prints wordlist documentation to the console. func PrintWordListOptions() []byte { fileLocation, err := config.Assets.ReadFile(config.ListOptions) if err != nil { diff --git a/src/generate/generate.go b/src/generate/generate.go index d5061b7..40aff30 100644 --- a/src/generate/generate.go +++ b/src/generate/generate.go @@ -9,6 +9,8 @@ import ( "time" ) +// Functions are exported in this package because they will eventually be imported in other parts of the code. + type Params struct { WordCount int WordList string @@ -17,6 +19,7 @@ type Params struct { Numbers bool } +// Capitals handles adding capitalized letters to a passphrase. // TODO There is a chance this doesn't capitalize. Need to make a validator. func Capitals(passphrase []string) string { rand.Seed(time.Now().UnixNano()) @@ -41,6 +44,7 @@ func choice() int { return opts[rand.Intn(len(opts))] } +// HandleFlags looks at the parameters and updates the passphrase based on the flags func HandleFlags(p *Params, passphrase []string) string { var returnValue string if p.SpecialChars == true { @@ -77,6 +81,7 @@ func keySize(wordList string) int { } } +// Password generates a password func Password(p *Params) string { var passphrase []string for i := 1; i <= p.WordCount; i++ { @@ -91,6 +96,7 @@ func Password(p *Params) string { return returnValue } +// SpecialCharacters handles adding special characters to the passphrase func SpecialCharacters(passphrase []string) []string { rand.Seed(time.Now().UnixNano()) passphrase = append(passphrase, "") @@ -104,6 +110,7 @@ func SpecialCharacters(passphrase []string) []string { return passphrase } +// Numbers handles adding numbers to the passphrase. func Numbers(passphrase []string) []string { rand.Seed(time.Now().UnixNano()) charCount := rand.Intn(len(passphrase)) + 1