|
@@ -28,26 +28,14 @@ import (
|
|
|
"gopkg.in/urfave/cli.v1"
|
|
"gopkg.in/urfave/cli.v1"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-// getPassPhrase obtains a passphrase given by the user. It first checks the
|
|
|
|
|
-// --passphrase command line flag and ultimately prompts the user for a
|
|
|
|
|
-// passphrase.
|
|
|
|
|
-func getPassPhrase(ctx *cli.Context, confirmation bool) string {
|
|
|
|
|
- // Look for the --passphrase flag.
|
|
|
|
|
- passphraseFile := ctx.String(passphraseFlag.Name)
|
|
|
|
|
- if passphraseFile != "" {
|
|
|
|
|
- content, err := ioutil.ReadFile(passphraseFile)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- utils.Fatalf("Failed to read passphrase file '%s': %v",
|
|
|
|
|
- passphraseFile, err)
|
|
|
|
|
- }
|
|
|
|
|
- return strings.TrimRight(string(content), "\r\n")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Otherwise prompt the user for the passphrase.
|
|
|
|
|
|
|
+// promptPassphrase prompts the user for a passphrase. Set confirmation to true
|
|
|
|
|
+// to require the user to confirm the passphrase.
|
|
|
|
|
+func promptPassphrase(confirmation bool) string {
|
|
|
passphrase, err := console.Stdin.PromptPassword("Passphrase: ")
|
|
passphrase, err := console.Stdin.PromptPassword("Passphrase: ")
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
utils.Fatalf("Failed to read passphrase: %v", err)
|
|
utils.Fatalf("Failed to read passphrase: %v", err)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if confirmation {
|
|
if confirmation {
|
|
|
confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
|
|
confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -57,9 +45,29 @@ func getPassPhrase(ctx *cli.Context, confirmation bool) string {
|
|
|
utils.Fatalf("Passphrases do not match")
|
|
utils.Fatalf("Passphrases do not match")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return passphrase
|
|
return passphrase
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// getPassphrase obtains a passphrase given by the user. It first checks the
|
|
|
|
|
+// --passfile command line flag and ultimately prompts the user for a
|
|
|
|
|
+// passphrase.
|
|
|
|
|
+func getPassphrase(ctx *cli.Context) string {
|
|
|
|
|
+ // Look for the --passwordfile flag.
|
|
|
|
|
+ passphraseFile := ctx.String(passphraseFlag.Name)
|
|
|
|
|
+ if passphraseFile != "" {
|
|
|
|
|
+ content, err := ioutil.ReadFile(passphraseFile)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ utils.Fatalf("Failed to read passphrase file '%s': %v",
|
|
|
|
|
+ passphraseFile, err)
|
|
|
|
|
+ }
|
|
|
|
|
+ return strings.TrimRight(string(content), "\r\n")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Otherwise prompt the user for the passphrase.
|
|
|
|
|
+ return promptPassphrase(false)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// signHash is a helper function that calculates a hash for the given message
|
|
// signHash is a helper function that calculates a hash for the given message
|
|
|
// that can be safely used to calculate a signature from.
|
|
// that can be safely used to calculate a signature from.
|
|
|
//
|
|
//
|