fix(pgp): decrypt bare armored messages - #1716
Open
chiliec wants to merge 1 commit into
Open
Conversation
Server-side encrypted mail (e.g. mailbox.org Encrypted Inbox) delivers the application/octet-stream part as a bare ASCII-armored PGP message. That payload was passed straight to pgpmail.Read, which expects a full MIME entity and failed with 'malformed MIME header line'. Decode the armor and decrypt directly when the payload starts with a PGP MESSAGE block; keep the pgpmail path for complete PGP/MIME entities. Fixes floatpane#1715 Signed-off-by: Vladimir Babin <vovababin@gmail.com>
Member
Benchmark report — no significant changeMetrics worse: 0 · better: 0 (threshold: ±3%). benchstat outputauto-generated by benchmarks.yml |
Author
|
Note on the red |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
decryptPGPMessagenow handles a bare ASCII-armored payload: when the data starts with-----BEGIN PGP MESSAGE-----it decodes the armor and decrypts withopenpgp.ReadMessagedirectly. Complete PGP/MIME entities still go throughpgpmail.Readas before.Adds
fetcher/pgp_test.gocovering both paths (bare armor +multipart/encryptedentity) using a throwaway key generated in the test.Why?
Fixes #1715.
checkPartextracts theapplication/octet-streampart of amultipart/encryptedmessage and passes just that armored block todecryptPGPMessage, which handed it topgpmail.Read.pgpmail.Readexpects a full MIME entity and runstextproto.ReadHeaderfirst, so the armor header line has no colon and decryption aborted withmalformed MIME header line: -----BEGIN PGP MESSAGE-----before the private key was ever used. Server-side encrypted mail (mailbox.org Encrypted Inbox) hits this on every message.Verification (Go 1.26.5,
GOTOOLCHAIN=local):go test ./fetcher/ -run TestDecryptPGP -v— both tests pass.TestDecryptPGPMessageBareArmorfails with the exact reported error (failed to decrypt PGP message: message: malformed MIME header line: -----BEGIN PGP MESSAGE-----);TestDecryptPGPMessageMIMEEntitypasses before and after, so the existing PGP/MIME path is unchanged.go test ./fetcher/— full package green;go vet ./fetcher/,gofmt -l,golangci-lint run ./fetcher/(v2.13.2, repo config) — 0 issues.Not run locally:
./sendertests (needpkg-config/pcsclite for the YubiKey dep on this box) — untouched by this change.