Commit graph

499 commits

Author SHA1 Message Date
5f5b374f84 Unify send_msg, add more type hints 2023-05-08 22:17:02 +02:00
67e6df17fb Move success flag before 'try' 2023-05-08 22:17:02 +02:00
0da169ae61 Log exceptions from failover delivery 2023-05-08 22:17:02 +02:00
f4e21217c2 [simple-filter] Retry delivery recoding text parts 2023-05-08 22:17:02 +02:00
1f1fe1dadb Add lots of log messages 2023-05-08 22:17:02 +02:00
8a42f3fea1 Improve error-handling for simple filter and test relay 2023-05-08 22:17:02 +02:00
8def4b40dc Correct sample message in contract tests 2023-05-08 22:17:02 +02:00
e595e8baf4 Fix contract tests 2023-05-08 22:17:02 +02:00
a5f79c1ae7 Wrap recipient lists
Instead of passing pairs of lists (emails and keys) separately, implement a
class RecipientList to wrap such pair of lists.
2023-05-08 22:17:02 +02:00
c5e788b2a0 Add more contract tests for email module 2023-05-08 22:17:02 +02:00
12b7c3394d Make test relay slightly cleaner 2023-05-08 22:17:02 +02:00
b2bd6a9926 Encapsulate recipient lists
Implement RecipientList class with:
- recipient (email) list,
- key (identity) list.

Cover with basic unit test.
2023-05-08 22:17:02 +02:00
86a3e0031b Adjust gpg-mailgate.py script to use SMTPUTF8 policy 2023-05-08 22:17:02 +02:00
54ee9d9875 Add minor E2E test improvements 2023-05-08 22:17:02 +02:00
603a88489e Polish the code 2023-05-08 22:17:02 +02:00
ffd5f08ad9 Make PGP message recognition more thorough 2023-05-08 22:17:02 +02:00
d342f206de Handle messages as EmailMessage
In the daemon, specify policy as SMTPUTF8.  That sets the deafult message type
to EmailMessage.

EmailMessage class is richer, including support for Content Managers, giving
it the capability to properly handle textual data and its encodings.

Also: add another contract test.
2023-05-08 22:17:02 +02:00
ace2ce6b06 Add more email-parsing contract tests 2023-05-08 22:17:01 +02:00
509aac6de3 Improve command-generation, logging and readability 2023-05-08 22:17:01 +02:00
ea8b246538 Clean up PGP/MIME flow
- Use MIMEPart instead of Message when encrypting in PGP/MIME mode.

- Wrap text/plain messages in MIMEPart, instead of manipulating payloads
  manually.

- Add a test for wrapping.
2023-05-08 22:17:01 +02:00
765637fd3a Fix logging initialisation by fixing import order 2023-05-08 22:17:01 +02:00
1a3ce89ce5 Always encrypt decoded payload 2023-05-08 22:17:01 +02:00
3c8b792203 Fix line-discarding bug 2023-05-08 22:17:01 +02:00
56101b86c0 Clean up the code after refactor
- Clean up PGP/MIME flow by using API instead of explicit/manual generation of
  headers.
- Fix E2E test configuration for PGP/MIME case.
- Add first lacre.core unit tests.
- Add another Contract Test.
2023-05-08 22:17:01 +02:00
27b07e672d Rework PGP/MIME flow 2023-05-08 22:17:01 +02:00
5e408259c0 Start using Content Manager
Also:
- Pass text to Popen in GnuPG (used to be bytes).
- Make is_payload_pgp_inline type-agnostic (str / bytes).
2023-05-08 22:17:01 +02:00
d2ed4a9cee Make test reports more readable 2023-05-08 22:17:01 +02:00
94e22caf8e When encryption fails, revert to cleartext delivery
When GnuPG refuses to encrypt a message (e.g. when key has expired), record
information about the failure and send to logs, then deliver cleartext.  This
way we won't bounce email that could be delivered without encryption.

Also: add more E2E tests.
2023-05-08 22:16:41 +02:00
1cdca1d06d Log up to 2,5kB of message headers 2023-05-08 22:14:24 +02:00
3c1544e423 [daemon] Parse Envelope.original_content 2023-05-08 22:14:24 +02:00
ffffa6a364 Correct sample message file name 2023-05-08 22:14:24 +02:00
b242edf098 Add a more sophisticated UTF-8 test case
Add a new test message to verify Lacre's behaviour when processing
UTF-8 messages with text in two different scripts (latin-based and cyrillic).

Also: log Content-Transfer-Encoding when logging headers is enabled.
2023-05-08 22:14:24 +02:00
b94123e83e Use SMTPUTF8 policy, add more debug logging 2023-05-08 22:14:24 +02:00
4da4019321 Log message defects and optionally some non-PII headers 2023-05-08 22:14:24 +02:00
b6bd36a460 Use bytes instead of str to hold message bodies
smtplib.SMTP expects ASCII-only message bodies when message body is provided
as a 'str'.  If we pass a 'bytes', we need to choose encoding earlier and we
do this by calling 'as_bytes' on messages with SMTP policy, which takes care
of formatting the body properly.

As a result, ISO-8859-x messages are converted to Quoted Printable and UTF-8
messages are Base64-encoded.

Testing this behaviour is tricky, because we use the same SMTP client to send
test data.  For this reason, test code has become a bit ugly, but it does
exactly what we need.
2023-05-08 22:14:24 +02:00
0fac54a29a Add UTF-8 and ISO-8859-2 test cases, make tests more reliable 2023-05-08 22:14:24 +02:00
037a527c44 Add a test case with non-ASCII message content 2023-05-08 22:14:24 +02:00
5eb687f0cd Add config parameter to set DATA size limit
Expose a new parameter: [daemon]max_data_bytes, to limit Lacre's memory
usage and allow processing of messages larger than 32MB (which is the
default limit).
2023-05-08 22:14:24 +02:00
f6bf86c533 Re-use the same Event Loop for each coroutine
Function asyncio.run creates a new event loop each time it's called and
executes coroutine in that new loop.  However, we want all our coroutines to
be executed from the same event loop, so we acquire a loop when lacre.daemon
starts and then use it to execute them later.

See: Disroot/gpg-lacre#109
2023-05-08 22:14:24 +02:00
pfm
609a81adcd Merge pull request 'Remove documentation and sample config for decryption' (#121) from doc-updates into main
Reviewed-on: #121
2023-03-11 11:33:44 +00:00
37335de329 Remove documentation and sample config for decryption
We no longer support decrypting emails, so:

- Remove parameters from exmaple configuration file.
- Remove relevant section from installation instructions (INSTALL.md).
2023-03-11 12:30:24 +01:00
pfm
7389dc8fde Merge pull request 'Add missing test case for add_key and delete_key' (#116) from wiktor/gpg-lacre:add-test-for-add-delete-key into main
Reviewed-on: #116
Reviewed-by: pfm <pfm@no-reply@disroot.org>
2023-02-16 18:04:17 +00:00
46bb125684
Add missing test case for add_key and delete_key 2022-12-23 13:49:43 +01:00
pfm
2215886850 Merge pull request 'Add basic unit tests for GnuPG module' (#114) from gnupg-tests into main
Reviewed-on: #114
2022-12-14 20:29:01 +00:00
588b447e69 Add basic unit tests for GnuPG module
- Cover basic GnuPG functionality with tests (confirm_key, public_keys).
- Add a test public key file.
- Fix resource leak by closing streams opened by Popen.
2022-12-14 21:09:46 +01:00
pfm
5c3fecfb85 Merge pull request 'Formatting corrections and whitespace character fixes' (#112) from Onnayaku/gpg-lacre:doc-fixes into main
Reviewed-on: #112
Reviewed-by: pfm <pfm@no-reply@disroot.org>
2022-12-14 19:32:40 +00:00
c7c49977c9
Change 'Indented code blocks' to 'Fenced code blocks' in adv-filt.md 2022-11-01 23:53:37 +01:00
2c6adfe335
Minor formatting corrections and whitespace character fixes in adv-filt.md testing.md INSTALL.md and README.md 2022-11-01 21:35:48 +01:00
pfm
9f1c4db49d Merge pull request 'doc-updates' (#108) from doc-updates into main
Reviewed-on: #108
2022-10-26 17:21:41 +00:00
86b0cd335e Replace UTF-8 non-breaking space with a plain space 2022-10-26 19:20:47 +02:00