diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/eno/cobra.go | 4 | ||||
| -rw-r--r-- | cmd/eno/cobra_ssh.go | 22 |
2 files changed, 18 insertions, 8 deletions
diff --git a/cmd/eno/cobra.go b/cmd/eno/cobra.go index 4a7443e..cf373d5 100644 --- a/cmd/eno/cobra.go +++ b/cmd/eno/cobra.go @@ -70,6 +70,7 @@ var encryptCmd = &cobra.Command{ } encrypted, _, err := crypt.EncryptBytesSSH(fileBytes, pubKeys) if err != nil { + clear(fileBytes) cmd.PrintErrln("Error:", err) os.Exit(1) } @@ -91,6 +92,8 @@ var encryptCmd = &cobra.Command{ encrypted, err := crypt.EncryptBytesPass(fileBytes, password) if err != nil { + clear(fileBytes) + clear(password) cmd.PrintErrln("Error:", err) os.Exit(1) } @@ -166,6 +169,7 @@ var decryptCmd = &cobra.Command{ plaintext, err := crypt.DecryptBytesPass(fileBytes, password) if err != nil { + clear(password) cmd.PrintErrln("Error:", err) os.Exit(1) } diff --git a/cmd/eno/cobra_ssh.go b/cmd/eno/cobra_ssh.go index f684e95..084960a 100644 --- a/cmd/eno/cobra_ssh.go +++ b/cmd/eno/cobra_ssh.go @@ -1,7 +1,6 @@ package main import ( - "bufio" "crypto" "errors" "fmt" @@ -39,8 +38,6 @@ var sshInitCmd = &cobra.Command{ Short: "setup ssh for Eno notes", Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { - scanner := bufio.NewScanner(os.Stdin) - if Conf.SSHInitialized { cmd.PrintErrln("SSH is already initialized") ok, err := utils.AskUserYesNo("Reinitialize SSH?", false) @@ -70,22 +67,22 @@ var sshInitCmd = &cobra.Command{ if privateKeyPath == "" { fmt.Print("Enter path to SSH private key: ") - if !scanner.Scan() { + if !utils.StdinScanner.Scan() { cmd.PrintErrln("failed to read input") os.Exit(1) } - privateKeyPath = expandPath(strings.TrimSpace(scanner.Text())) + privateKeyPath = expandPath(strings.TrimSpace(utils.StdinScanner.Text())) } publicKeyPath := privateKeyPath + ".pub" if _, err := os.Stat(publicKeyPath); os.IsNotExist(err) { cmd.PrintErrln("public key not found at " + publicKeyPath) fmt.Print("Enter path to SSH public key: ") - if !scanner.Scan() { + if !utils.StdinScanner.Scan() { cmd.PrintErrln("failed to read input") os.Exit(1) } - publicKeyPath = strings.TrimSpace(scanner.Text()) + publicKeyPath = strings.TrimSpace(utils.StdinScanner.Text()) publicKeyPath = expandPath(publicKeyPath) } @@ -110,14 +107,16 @@ var sshInitCmd = &cobra.Command{ fmt.Printf("Enter the ssh key passphrase: ") sshPassword, err := utils.TakeSecureUserInput() if err != nil { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } crypt.TryMlock(sshPassword) defer clear(sshPassword) - privKey, err = ssh.ParseRawPrivateKeyWithPassphrase(privKeyBytes, []byte(sshPassword)) + privKey, err = ssh.ParseRawPrivateKeyWithPassphrase(privKeyBytes, sshPassword) } else { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } @@ -125,6 +124,7 @@ var sshInitCmd = &cobra.Command{ signer, ok := privKey.(crypto.Signer) if !ok { + clear(privKeyBytes) cmd.PrintErrln("failed to extract public key from private key") os.Exit(1) } @@ -132,30 +132,36 @@ var sshInitCmd = &cobra.Command{ givenPubKey, _, _, _, err := ssh.ParseAuthorizedKey(givenPubKeyBytes) if err != nil { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } extractedPubKey, err := ssh.NewPublicKey(extractedPubKeyRaw) if err != nil { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } if ssh.FingerprintSHA256(extractedPubKey) != ssh.FingerprintSHA256(givenPubKey) { + clear(privKeyBytes) cmd.PrintErrln("public key file does not match private key") os.Exit(1) } if err := updateConfig("DefaultSSHPrivPath", privateKeyPath); err != nil { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } if err := updateConfig("DefaultSSHPubPath", publicKeyPath); err != nil { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } if err := updateConfig("SSHInitialized", true); err != nil { + clear(privKeyBytes) cmd.PrintErrln(err) os.Exit(1) } |