~rjarry/aerc-devel

aerc: gpg: fix signed message encoding v1 APPLIED

Koni Marti: 1
 gpg: fix signed message encoding

 1 files changed, 5 insertions(+), 3 deletions(-)
#1310353 alpine-edge.yml success
#1310354 openbsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/aerc-devel/patches/54675/mbox | git am -3
Learn more about email & git

[PATCH aerc] gpg: fix signed message encoding Export this patch

Fix the content encoding for GPG-signed messages.

To remove the Mime-Version header field for the signed message part, the
raw message is parsed with go-message. go-message.Read(), however,
decodes the message body as well (i.e. from quoted-printable to UTF8
depending on the Content-Transfer-Encoding header). This means that the
msg.Body field now contains the decoded message (it is no longer encoded
as quoted-printable). We never encode the message back to the proper
Content-Transfer-Encoding.

To fix this, use net/mail.ReadMessage() to parse the headers and to not
decode the message body.

To verify the issue, send a signed message with the following text:
"19+1=20!"

The message will be properly signed, but the text is wrong; it shows
"19+1 !"; instead it should read "19+1=3D20!".

Fixes:  5e443bce ("gpg: fix mime-version header position")
References: https://todo.sr.ht/~rjarry/aerc/79
Signed-off-by: Koni Marti <koni.marti@gmail.com>
---
 lib/crypto/gpg/writer.go | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/crypto/gpg/writer.go b/lib/crypto/gpg/writer.go
index caae56bf..c879bc7f 100644
--- a/lib/crypto/gpg/writer.go
+++ b/lib/crypto/gpg/writer.go
@@ -8,6 +8,7 @@ import (
	"fmt"
	"io"
	"mime"
	"net/mail"

	"git.sr.ht/~rjarry/aerc/lib/crypto/gpg/gpgbin"
	"github.com/emersion/go-message"
@@ -51,10 +52,11 @@ func (s *Signer) Write(p []byte) (int, error) {
}

func (s *Signer) Close() (err error) {
	msg, err := message.Read(&s.signedMsg)
	msg, err := mail.ReadMessage(&s.signedMsg)
	if err != nil {
		return err
	}
	header := message.HeaderFromMap(msg.Header)
	// Make sure that MIME-Version is *not* set on the signed part header.
	// It must be set *only* on the top level header.
	//
@@ -64,10 +66,10 @@ func (s *Signer) Close() (err error) {
	//
	// Since the signature is computed on the whole part, including its
	// header, changing the case can cause the signature to become invalid.
	msg.Header.Del("Mime-Version")
	header.Del("Mime-Version")

	var buf bytes.Buffer
	_ = textproto.WriteHeader(&buf, msg.Header.Header)
	_ = textproto.WriteHeader(&buf, header.Header)
	_, _ = io.Copy(&buf, msg.Body)

	sig, micalg, err := gpgbin.Sign(bytes.NewReader(buf.Bytes()), s.from)
-- 
2.45.2
aerc/patches: SUCCESS in 1m58s

[gpg: fix signed message encoding][0] from [Koni Marti][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/54675
[1]: mailto:koni.marti@gmail.com

✓ #1310354 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1310354
✓ #1310353 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1310353
Hi,

works fine for me.

Thanks,

Jens

Tested-by: Jens Grassel <jens@wegtam.com
Koni Marti <koni.marti@gmail.com> wrote: