Skip to content

Commit

Permalink
cli/decrypt: improve debugging of gpg command (#2913)
Browse files Browse the repository at this point in the history
When gopass-jsonapi is running these functions, the stderr of the gpg
command won't reach anywhere visible without writing it to the log as
well. Also adding 2 --verbose arguments to gpg helps debugging potential
issues.

Signed-off-by: Doron Behar <[email protected]>
  • Loading branch information
doronbehar authored Jul 28, 2024
1 parent e302ae7 commit 51c2bdc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions internal/backend/crypto/gpg/cli/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"bytes"
"context"
"io"
"os"
"os/exec"

Expand All @@ -15,11 +16,21 @@ func (g *GPG) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) {
defer cancel()

args := append(g.args, "--decrypt")
// Useful information may appear there
if debug.IsEnabled() {
args = append(args, "--verbose", "--verbose")
}
cmd := exec.CommandContext(ctx, g.binary, args...)
cmd.Stdin = bytes.NewReader(ciphertext)
cmd.Stderr = os.Stderr
// If gopass-jsonapi is used, there is no way to reach this os.Stderr, so
// we write this stderr to the log file as well.
cmd.Stderr = io.MultiWriter(os.Stderr, debug.LogWriter)

debug.Log("%s %+v", cmd.Path, cmd.Args)
debug.Log("Running %s %+v", cmd.Path, cmd.Args)
stdout, err := cmd.Output()
if err != nil {
debug.Log("Got %+v when running gpg command!", err)
}

return cmd.Output()
return stdout, err
}

0 comments on commit 51c2bdc

Please sign in to comment.