Skip to content

Commit 6a25128

Browse files
committed
gpg: Pass the passphrase to the gpg2 tool using a file
Rather than passing the passphrase via command line write it into a temp. file and pass the name of the file using passphrase-file option. Signed-off-by: Stefan Berger <[email protected]>
1 parent 29930e9 commit 6a25128

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pkg/encryption/gpg.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,16 @@ func (gc *gpgv2Client) GetGPGPrivateKey(keyid uint64, passphrase string) ([]byte
131131
args = append(args, []string{"--homedir", gc.gpgHomeDir}...)
132132
}
133133

134-
args = append(args, []string{"--pinentry-mode", "loopback", "--batch", "--passphrase", passphrase, "--export-secret-key", fmt.Sprintf("0x%x", keyid)}...)
134+
tempfile, err := ioutil.TempFile("", "gpg2*")
135+
if err != nil {
136+
return nil, errors.Wrapf(err, "could not create temporary file")
137+
}
138+
defer os.Remove(tempfile.Name())
139+
if err := ioutil.WriteFile(tempfile.Name(), []byte(passphrase), 0600); err != nil {
140+
return nil, errors.Wrapf(err, "could not write to temporary file")
141+
}
142+
143+
args = append(args, []string{"--pinentry-mode", "loopback", "--batch", "--passphrase-file", tempfile.Name(), "--export-secret-key", fmt.Sprintf("0x%x", keyid)}...)
135144

136145
cmd := exec.Command("gpg2", args...)
137146

0 commit comments

Comments
 (0)