diff --git a/.goreleaser.yml b/.goreleaser.yml index eadb4af..ac24b5f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -164,7 +164,7 @@ builds: goarch: - arm goarm: - - 7 + - "7" env: - CC=arm-linux-gnueabihf-gcc - CXX=arm-linux-gnueabihf-g++ @@ -205,7 +205,7 @@ checksum: name_template: "{{ .ProjectName }}_checksums.txt" snapshot: - name_template: "{{ incpatch .Version }}-dev" + version_template: "{{ incpatch .Version }}-dev" changelog: sort: asc diff --git a/go.mod b/go.mod index bdf3969..dbc24ca 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/fatih/color v1.17.0 github.com/spf13/cobra v1.8.1 golang.org/x/crypto v0.26.0 - golang.org/x/term v0.23.0 + golang.org/x/term v0.24.0 ) require ( @@ -17,5 +17,5 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.24.0 // indirect + golang.org/x/sys v0.25.0 // indirect ) diff --git a/go.sum b/go.sum index 7444116..cf4fae6 100644 --- a/go.sum +++ b/go.sum @@ -19,9 +19,9 @@ golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= -golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= 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= diff --git a/internal/cli/commands/decrypt.go b/internal/cli/commands/decrypt.go index 6787a1c..9ff3945 100644 --- a/internal/cli/commands/decrypt.go +++ b/internal/cli/commands/decrypt.go @@ -31,11 +31,11 @@ func getSecretKeyOrPwd() (string, error) { secret = new(string) *secret = os.Getenv(envar_XIPHER_SECRET) if *secret == "" { - password, err := getPasswordFromUser(false, true) + passwordOrSecretKey, err := getPasswordOrSecretKeyFromUser(false, true) if err != nil { return "", err } - *secret = string(password) + *secret = string(passwordOrSecretKey) } } return *secret, nil diff --git a/internal/cli/commands/input.go b/internal/cli/commands/input.go index bc72b46..1fe9606 100644 --- a/internal/cli/commands/input.go +++ b/internal/cli/commands/input.go @@ -8,6 +8,7 @@ import ( "syscall" "unicode" + "dev.shib.me/xipher/utils" "golang.org/x/term" ) @@ -63,28 +64,28 @@ func getHiddenInputFromUser(prompt string) ([]byte, error) { return input, err } -func getPasswordFromUser(confirm, ignorePolicyCheck bool) ([]byte, error) { - initialPrompt := "Enter a Password: " - if !confirm { - initialPrompt = "Enter Password/Secret Key: " - } - password, err := getHiddenInputFromUser(initialPrompt) +func getPasswordOrSecretKeyFromUser(confirm, ignorePolicyCheck bool) ([]byte, error) { + initialPrompt := "Enter a Password/Secret Key: " + passwordOrSecretKey, err := getHiddenInputFromUser(initialPrompt) if err != nil { return nil, err } + if utils.IsSecretKeyStr(string(passwordOrSecretKey)) { + return passwordOrSecretKey, nil + } if !ignorePolicyCheck { - if err = pwdCheck(string(password)); err != nil { + if err = pwdCheck(string(passwordOrSecretKey)); err != nil { return nil, err } } if confirm { - if confirmPassword, err := getHiddenInputFromUser("Confirm Password: "); err != nil { + if confirmPassword, err := getHiddenInputFromUser("Confirm Password/Secret Key: "); err != nil { return nil, err - } else if !bytes.Equal(password, confirmPassword) { + } else if !bytes.Equal(passwordOrSecretKey, confirmPassword) { return nil, fmt.Errorf("passwords do not match") } } - return password, nil + return passwordOrSecretKey, nil } func readBufferFromStdin(prompt string) ([]byte, error) { diff --git a/internal/cli/commands/keygen.go b/internal/cli/commands/keygen.go index d9d88c5..c38d54d 100644 --- a/internal/cli/commands/keygen.go +++ b/internal/cli/commands/keygen.go @@ -16,7 +16,7 @@ func keygenCommand() *cobra.Command { } keygenCmd = &cobra.Command{ Use: "keygen", - Short: "Generate a new key pair or public key based on a password", + Short: "Generate a new random key pair or a public key based on a given password or secret key", Run: func(cmd *cobra.Command, args []string) { publicKeyFilePath := cmd.Flag(publicKeyFileFlag.name).Value.String() ignoreFlag, _ := cmd.Flags().GetBool(ignorePasswordCheckFlag.name) @@ -30,7 +30,7 @@ func keygenCommand() *cobra.Command { } fmt.Println("Secret Key:", color.HiBlackString(secret)) } else { - password, err := getPasswordFromUser(true, ignoreFlag) + password, err := getPasswordOrSecretKeyFromUser(true, ignoreFlag) if err != nil { exitOnError(err) }