aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/gpg
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/gpg')
-rw-r--r--lib/crypto/gpg/gpgbin/encrypt.go9
-rw-r--r--lib/crypto/gpg/gpgbin/gpgbin.go12
-rw-r--r--lib/crypto/gpg/gpgbin/keys.go5
-rw-r--r--lib/crypto/gpg/gpgbin/sign.go9
-rw-r--r--lib/crypto/gpg/gpgbin/verify.go13
-rw-r--r--lib/crypto/gpg/reader.go8
-rw-r--r--lib/crypto/gpg/writer.go19
7 files changed, 54 insertions, 21 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)
diff --git a/lib/crypto/gpg/reader.go b/lib/crypto/gpg/reader.go
index bf977ed4..40da82f8 100644
--- a/lib/crypto/gpg/reader.go
+++ b/lib/crypto/gpg/reader.go
@@ -38,7 +38,7 @@ func NewReader(h textproto.Header, body io.Reader) (*Reader, error) {
}
var headerBuf bytes.Buffer
- textproto.WriteHeader(&headerBuf, h)
+ _ = textproto.WriteHeader(&headerBuf, h)
return &Reader{
Header: h,
@@ -123,7 +123,7 @@ func newEncryptedReader(h textproto.Header, mr *textproto.MultipartReader) (*Rea
}
var headerBuf bytes.Buffer
- textproto.WriteHeader(&headerBuf, cleartextHeader)
+ _ = textproto.WriteHeader(&headerBuf, cleartextHeader)
md.Body = io.MultiReader(&headerBuf, cleartext)
return &Reader{
@@ -139,11 +139,11 @@ func newSignedReader(h textproto.Header, mr *textproto.MultipartReader, micalg s
return nil, fmt.Errorf("gpgmail: failed to read signed part in multipart/signed message: %v", err)
}
var headerBuf bytes.Buffer
- textproto.WriteHeader(&headerBuf, p.Header)
+ _ = textproto.WriteHeader(&headerBuf, p.Header)
var msg bytes.Buffer
headerRdr := bytes.NewReader(headerBuf.Bytes())
fullMsg := io.MultiReader(headerRdr, p)
- io.Copy(&msg, fullMsg)
+ _, _ = io.Copy(&msg, fullMsg)
sig, err := mr.NextPart()
if err != nil {
diff --git a/lib/crypto/gpg/writer.go b/lib/crypto/gpg/writer.go
index 96d083e8..0648ec24 100644
--- a/lib/crypto/gpg/writer.go
+++ b/lib/crypto/gpg/writer.go
@@ -30,7 +30,10 @@ func (es *EncrypterSigner) Close() (err error) {
if err != nil {
return err
}
- es.encryptedWriter.Write(enc)
+ _, err = es.encryptedWriter.Write(enc)
+ if err != nil {
+ return fmt.Errorf("gpg: failed to write encrypted writer: %w", err)
+ }
return nil
}
@@ -65,8 +68,8 @@ func (s *Signer) Close() (err error) {
}
boundary := s.mw.Boundary()
fmt.Fprintf(s.w, "--%s\r\n", boundary)
- s.w.Write(s.signedMsg.Bytes())
- s.w.Write([]byte("\r\n"))
+ _, _ = s.w.Write(s.signedMsg.Bytes())
+ _, _ = s.w.Write([]byte("\r\n"))
var signedHeader textproto.Header
signedHeader.Set("Content-Type", "application/pgp-signature; name=\"signature.asc\"")
@@ -100,7 +103,10 @@ func Encrypt(w io.Writer, h textproto.Header, rcpts []string, from string) (io.W
mw := textproto.NewMultipartWriter(w)
if forceBoundary != "" {
- mw.SetBoundary(forceBoundary)
+ err := mw.SetBoundary(forceBoundary)
+ if err != nil {
+ return nil, fmt.Errorf("gpg: failed to set boundary: %w", err)
+ }
}
params := map[string]string{
@@ -154,7 +160,10 @@ func Sign(w io.Writer, h textproto.Header, from string) (io.WriteCloser, error)
mw := textproto.NewMultipartWriter(w)
if forceBoundary != "" {
- mw.SetBoundary(forceBoundary)
+ err := mw.SetBoundary(forceBoundary)
+ if err != nil {
+ return nil, fmt.Errorf("gpg: failed to set boundary: %w", err)
+ }
}
var msg bytes.Buffer