diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-06-25 09:22:49 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-06-26 12:07:44 +0200 |
commit | 6a10123f4a361ae5c2e712752ea4c95b6724e678 (patch) | |
tree | 6d77c73ab867b494b14dce52a084af258022bba4 /lib/crypto | |
parent | 96db50c4f06bab4ef052b584943d8c7113766a06 (diff) | |
download | aerc-6a10123f4a361ae5c2e712752ea4c95b6724e678.tar.gz |
gpg: don't send messages that failed encryption
Add error handling for messages that were unable to be encrypted.
Previously, messages that failed encryption would be sent with no
content. This patch adds error handling - when encryption fails, the
user is returned to the Review screen and instructed to check the public
keys for their recipients.
Reported-by: Moritz Poldrack <moritz@poldrack.dev>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'lib/crypto')
-rw-r--r-- | lib/crypto/gpg/gpgbin/encrypt.go | 6 | ||||
-rw-r--r-- | lib/crypto/gpg/gpgbin/gpgbin.go | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/crypto/gpg/gpgbin/encrypt.go b/lib/crypto/gpg/gpgbin/encrypt.go index 4cbac37b..e72ba148 100644 --- a/lib/crypto/gpg/gpgbin/encrypt.go +++ b/lib/crypto/gpg/gpgbin/encrypt.go @@ -2,6 +2,7 @@ package gpgbin import ( "bytes" + "fmt" "io" "git.sr.ht/~rjarry/aerc/models" @@ -27,7 +28,10 @@ func Encrypt(r io.Reader, to []string, from string) ([]byte, error) { g.cmd.Run() outRdr := bytes.NewReader(g.stdout.Bytes()) var md models.MessageDetails - 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) diff --git a/lib/crypto/gpg/gpgbin/gpgbin.go b/lib/crypto/gpg/gpgbin/gpgbin.go index bce30970..9f79e972 100644 --- a/lib/crypto/gpg/gpgbin/gpgbin.go +++ b/lib/crypto/gpg/gpgbin/gpgbin.go @@ -228,6 +228,8 @@ func parse(r io.Reader, md *models.MessageDetails) error { md.Micalg = micalgs[micalg] case "NODATA": md.SignatureError = "gpg: no signature packet found" + case "FAILURE": + return fmt.Errorf(strings.TrimPrefix(line, "[GNUPG:] ")) } } md.Body = bytes.NewReader(msgContent) |