Skip to content

Commit 704e402

Browse files
author
Andreas Auernhammer
committed
cli: fix bug when generating key pairs.
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`.
1 parent 4e3db15 commit 704e402

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cmd/minisign/minisign.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func generateKeyPair(secKeyFile, pubKeyFile string, force bool) {
136136

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

158158
var fileFlags = os.O_CREATE | os.O_WRONLY | os.O_TRUNC
159159
if !force {
160-
fileFlags = os.O_EXCL // fail if the file already exists
160+
fileFlags |= os.O_EXCL // fail if the file already exists
161161
}
162162
skFile, err := os.OpenFile(secKeyFile, fileFlags, 0600)
163163
if err != nil {

0 commit comments

Comments
 (0)