diff options
Diffstat (limited to 'lib/crypto/gpg/gpgbin')
-rw-r--r-- | lib/crypto/gpg/gpgbin/encrypt.go | 9 | ||||
-rw-r--r-- | lib/crypto/gpg/gpgbin/gpgbin.go | 12 | ||||
-rw-r--r-- | lib/crypto/gpg/gpgbin/keys.go | 5 | ||||
-rw-r--r-- | lib/crypto/gpg/gpgbin/sign.go | 9 | ||||
-rw-r--r-- | lib/crypto/gpg/gpgbin/verify.go | 13 |
5 files changed, 36 insertions, 12 deletions
diff --git a/lib/crypto/gpg/gpgbin/encrypt.go b/lib/crypto/gpg/gpgbin/encrypt.go index 31245a74..9ca45269 100644 --- a/lib/crypto/gpg/gpgbin/encrypt.go +++ b/lib/crypto/gpg/gpgbin/encrypt.go @@ -25,15 +25,18 @@ func Encrypt(r io.Reader, to []string, from string) ([]byte, error) { args = append(args, "--encrypt", "-") g := newGpg(r, args) - g.cmd.Run() + err := g.cmd.Run() + if err != nil { + return nil, fmt.Errorf("gpg: failed to run encryption: %w", err) + } outRdr := bytes.NewReader(g.stdout.Bytes()) var md models.MessageDetails - err := parse(outRdr, &md) + err = parse(outRdr, &md) if err != nil { return nil, fmt.Errorf("gpg: failure to encrypt: %v. check public key(s)", err) } var buf bytes.Buffer - io.Copy(&buf, md.Body) + _, _ = io.Copy(&buf, md.Body) return buf.Bytes(), nil } diff --git a/lib/crypto/gpg/gpgbin/gpgbin.go b/lib/crypto/gpg/gpgbin/gpgbin.go index 2eb83dc9..1e8c7dcd 100644 --- a/lib/crypto/gpg/gpgbin/gpgbin.go +++ b/lib/crypto/gpg/gpgbin/gpgbin.go @@ -63,7 +63,11 @@ func getIdentity(key uint64) string { var outbuf strings.Builder cmd.Stdout = &outbuf - cmd.Run() + err := cmd.Run() + if err != nil { + logging.Errorf("gpg: failed to get identity: %v", err) + return "" + } out := strings.Split(outbuf.String(), "\n") for _, line := range out { if strings.HasPrefix(line, "uid") { @@ -85,7 +89,11 @@ func getKeyId(s string, private bool) string { var outbuf strings.Builder cmd.Stdout = &outbuf - cmd.Run() + err := cmd.Run() + if err != nil { + logging.Errorf("gpg: failed to get key ID: %v", err) + return "" + } out := strings.Split(outbuf.String(), "\n") for _, line := range out { if strings.HasPrefix(line, "fpr") { diff --git a/lib/crypto/gpg/gpgbin/keys.go b/lib/crypto/gpg/gpgbin/keys.go index bef90cf6..ca166e9d 100644 --- a/lib/crypto/gpg/gpgbin/keys.go +++ b/lib/crypto/gpg/gpgbin/keys.go @@ -36,7 +36,10 @@ func ExportPublicKey(k string) (io.Reader, error) { var stderr strings.Builder cmd.Stdout = &outbuf cmd.Stderr = &stderr - cmd.Run() + err := cmd.Run() + if err != nil { + return nil, fmt.Errorf("gpg: export failed: %w", err) + } if strings.Contains(stderr.String(), "gpg") { return nil, fmt.Errorf("gpg: error exporting key") } diff --git a/lib/crypto/gpg/gpgbin/sign.go b/lib/crypto/gpg/gpgbin/sign.go index 31fd2b5a..caf31d14 100644 --- a/lib/crypto/gpg/gpgbin/sign.go +++ b/lib/crypto/gpg/gpgbin/sign.go @@ -17,15 +17,18 @@ func Sign(r io.Reader, from string) ([]byte, string, error) { } g := newGpg(r, args) - g.cmd.Run() + err := g.cmd.Run() + if err != nil { + return nil, "", fmt.Errorf("failed to run signing: %w", err) + } outRdr := bytes.NewReader(g.stdout.Bytes()) var md models.MessageDetails - err := parse(outRdr, &md) + err = parse(outRdr, &md) if err != nil { return nil, "", fmt.Errorf("failed to parse messagedetails: %v", err) } var buf bytes.Buffer - io.Copy(&buf, md.Body) + _, _ = io.Copy(&buf, md.Body) return buf.Bytes(), md.Micalg, nil } diff --git a/lib/crypto/gpg/gpgbin/verify.go b/lib/crypto/gpg/gpgbin/verify.go index be9f26f7..e5930849 100644 --- a/lib/crypto/gpg/gpgbin/verify.go +++ b/lib/crypto/gpg/gpgbin/verify.go @@ -2,6 +2,7 @@ package gpgbin import ( "bytes" + "fmt" "io" "io/ioutil" "os" @@ -19,7 +20,7 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) { if err != nil { return nil, err } - io.Copy(sig, s) + _, _ = io.Copy(sig, s) sig.Close() defer os.Remove(sig.Name()) args = append(args, sig.Name(), "-") @@ -29,11 +30,17 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) { return nil, err } g := newGpg(bytes.NewReader(orig), args) - g.cmd.Run() + err = g.cmd.Run() + if err != nil { + return nil, fmt.Errorf("gpg: failed to run verification: %w", err) + } out := bytes.NewReader(g.stdout.Bytes()) md := new(models.MessageDetails) - parse(out, md) + err = parse(out, md) + if err != nil { + return nil, fmt.Errorf("gpg: failed to parse result: %w", err) + } md.Body = bytes.NewReader(orig) |