Skip to content

Commit

Permalink
cli: fix bug when generating key pairs.
Browse files Browse the repository at this point in the history
This commit fixes a file creation bug in
the key generation code. If the force
flag has not been specified the OS file
flags would only contain `O_EXCL` such that
creation attempts will fail.

Now, the code *additionally* sets the `O_EXCL`
flag but preserves all other flags - i.e. `O_CREATE`.
  • Loading branch information
Andreas Auernhammer committed Mar 2, 2021
1 parent 4e3db15 commit 704e402
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/minisign/minisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func generateKeyPair(secKeyFile, pubKeyFile string, force bool) {

fmt.Print("Please enter a password to protect the secret key.\n\n")
var (
password = readPassword(os.Stdin, "Password: ")
passwordAgain = readPassword(os.Stdin, "Password (one more time): ")
password = readPassword(os.Stdin, "Enter Password: ")
passwordAgain = readPassword(os.Stdin, "Enter Password (one more time): ")
)
if password != passwordAgain {
log.Fatal("Error: passwords don't match")
Expand All @@ -157,7 +157,7 @@ func generateKeyPair(secKeyFile, pubKeyFile string, force bool) {

var fileFlags = os.O_CREATE | os.O_WRONLY | os.O_TRUNC
if !force {
fileFlags = os.O_EXCL // fail if the file already exists
fileFlags |= os.O_EXCL // fail if the file already exists
}
skFile, err := os.OpenFile(secKeyFile, fileFlags, 0600)
if err != nil {
Expand Down

0 comments on commit 704e402

Please sign in to comment.