Skip to content

Commit

Permalink
Update dependencies and refactor the code for certificate info prompt…
Browse files Browse the repository at this point in the history
…ing.

Signed-off-by: Dex Wood <slash2314@gmail.com>
  • Loading branch information
slash2314 committed Mar 18, 2024
1 parent d312813 commit 1577ced
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VERSION := $$(cat VERSION)
all: build strip
build: ssltool_linux_amd64 ssltool_linux_arm64 ssltool_linux_arm ssltool_linux_arm64 ssltool_mac_amd64 ssltool_mac_arm64 ssltool_mac_amd64 ssltool_windows_amd64.exe ssltool_windows_arm64.exe
ssltool_linux_amd64:
CGO_ENABLED=0 go build -o build/ssltool_linux_amd64_$(VERSION)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/ssltool_linux_amd64_$(VERSION)
ssltool_windows_amd64.exe:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o build/ssltool_win_amd64_$(VERSION).exe
ssltool_windows_arm64.exe:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
v0.0.3
35 changes: 15 additions & 20 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,12 @@ var genCmd = &cobra.Command{
or you can enter them interactively: COUNTRY, ORG, OU, LOCALITY, and PROVINCE.`,
Run: func(cmd *cobra.Command, args []string) {
scanner := bufio.NewScanner(os.Stdin)
country, exists := os.LookupEnv("COUNTRY")
if !exists {
country = input(scanner, "COUNTRY: ")
}
org, exists := os.LookupEnv("ORG")
if !exists {
org = input(scanner, "ORG: ")
}
ou, exists := os.LookupEnv("OU")
if !exists {
ou = input(scanner, "OU: ")
}
locality, exists := os.LookupEnv("LOCALITY")
if !exists {
locality = input(scanner, "LOCALITY: ")
}
province, exists := os.LookupEnv("PROVINCE")
if !exists {
province = input(scanner, "PROVINCE: ")
}

country := promptForInfo(scanner, "COUNTRY", "COUNTRY: ")
org := promptForInfo(scanner, "ORG", "ORG: ")
ou := promptForInfo(scanner, "OU", "OU: ")
locality := promptForInfo(scanner, "LOCALITY", "LOCALITY: ")
province := promptForInfo(scanner, "PROVINCE", "PROVINCE: ")

if len(commonName) == 0 {
fmt.Println("The common name must not be blank.")
Expand All @@ -57,6 +43,7 @@ or you can enter them interactively: COUNTRY, ORG, OU, LOCALITY, and PROVINCE.`,
encryptKeyPass := ""
if encryptKey {
fmt.Print("Password: ")
// int cast is required for windows
password, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
fmt.Println("Couldn't get password.")
Expand Down Expand Up @@ -104,6 +91,14 @@ or you can enter them interactively: COUNTRY, ORG, OU, LOCALITY, and PROVINCE.`,
},
}

func promptForInfo(scan *bufio.Scanner, env, prompt string) string {
data, exists := os.LookupEnv(env)
if !exists {
data = input(scan, prompt)
}
return data
}

func trimStrings(s []string) []string {
for i := range s {
s[i] = strings.Trim(s[i], " ")
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module ssltool

go 1.19
go 1.22

require (
github.com/spf13/cobra v1.7.0
golang.org/x/crypto v0.10.0
github.com/spf13/cobra v1.8.0
golang.org/x/crypto v0.21.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
)
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28=
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 1577ced

Please sign in to comment.