Commit graph

432 commits

Author SHA1 Message Date
pfm
9aa1c3732c Merge pull request 'Adjust cron tests after recent FE decoupling' (#99) from cron-tests into main
Reviewed-on: #99
Reviewed-by: muppeth <muppeth@no-reply@disroot.org>
2022-10-19 19:09:38 +00:00
a82d9f96b3 Fix indentation and some warnings 2022-10-19 21:04:25 +02:00
fe49d985ec Adjust cron tests after recent FE decoupling 2022-10-19 20:54:40 +02:00
pfm
13636bfddd Merge pull request 'Implement Advanced Content Filter' (#97) from daemon into main
Reviewed-on: #97
Reviewed-by: muppeth <muppeth@no-reply@disroot.org>
2022-10-19 18:48:39 +00:00
5f8c94673d Add basic daemon documentation 2022-10-19 18:36:23 +00:00
641253b3ec Make key-loading async, remove unused parameter 2022-10-19 18:36:23 +00:00
9696b7e997 Separate key-cache and key-loader
Extract key-loading code to a dedicated class KeyRing in lacre.keyring module.
KeyCache only keeps a static map of identities, making it safe to use in
asynchronous context (and race condition resistant).
2022-10-19 18:36:23 +00:00
9f3ad49f14 Rename lacre.keycache to lacre.keyring
This will better reflect the fact we're doing more than just caching.
2022-10-19 18:36:23 +00:00
acbb2ab776 Document dependencies
Add requirements.txt file with versions of dependencies known to work well.
2022-10-19 18:36:23 +00:00
2da97a5a9a Reformat code, add doc comments 2022-10-19 18:36:23 +00:00
eb0d5a1326 Reload keyring on filesystem events
Subscribe to FS events from keyring directory using Python Watchdog and when a
modification is observed, reload the key cache.

Since we may receive more than one event about a single modification, keep
directory's last modification to recognise 'false positives'.
2022-10-19 18:36:23 +00:00
386c23f9f8 Document dependencies on the logging module 2022-10-19 18:36:23 +00:00
1db0a09fa5 Log processing time for successful deliveries 2022-10-19 18:36:23 +00:00
a85b7b7a43 Reload key cache only if keyring dir was modified 2022-10-19 18:36:23 +00:00
f5cff3292a Reload key cache periodically
Use [default]cache_refresh_minutes configuration parameter to define periods
between cache reloads.  After this number of minutes cache will be reloaded.
2022-10-19 18:36:23 +00:00
d7e4947afd Add cache validity configuration parameter
Also, log basic information in KeyCache and provide load() and reload()
operations to make daemon's code cleaner.
2022-10-19 18:36:23 +00:00
5f601fa50c Implement a basic KeyCache 2022-10-19 18:36:23 +00:00
07263d5afa Reformat tests 2022-10-19 18:36:23 +00:00
c41df63e42 Reorder tests to avoid interferences 2022-10-19 18:36:23 +00:00
a2eeaeee9d Implement Advanced Filter flow for cleartext and OpenPGP
- Polish implementation of mail operations (lacre/mailop.py).  Add two
strategies: InlineOpenPGPEncrypt and MimeOpenPGPEncrypt, to support two modes
of OpenPGP encryption.

- In delivery_plan, only use those strategies that actually make sense with
the recipients we'd got.

- Add flag_enabled predicate (lacre/config.py) to make configuration checks
easier / simpler.

- Handle TypeError errors in Advanced Filter, indicating a delivery failure
when they appear.

- Add type hints to some of the functions.
2022-10-19 18:36:23 +00:00
ce6a0c5466 Continue refactoring
- Add more encryption strategies.
- Replace tuples (email + key) with dedicated objects.
2022-10-19 18:36:23 +00:00
8963eee47f Reformat GnuPG module 2022-10-19 18:36:23 +00:00
a5bcf2d9b2 Make daemon E2E tests use configured parameters 2022-10-19 18:36:23 +00:00
d01865d21c Refactor into smaller functions and objects 2022-10-19 18:36:23 +00:00
ddcef93abb Fix a bug introduced by refactoring, clean up code
- Fix certificate retrieval.

- Store recipients within MailOperation objects.

- Log more information.

- Fix some warnings.
2022-10-19 18:36:23 +00:00
ce2e55e90c Change indentation from tabs to 4 spaces 2022-10-19 18:36:23 +00:00
0cb656f89d Add more debug logging to _try_direct_key_lookup 2022-10-19 18:36:23 +00:00
603710c41e Continue splitting _sort_gpg_recipients
Extract new functions to match keys using enc_keymap and enc_domain_keymap
configuration sections, another one to look them up directly in GnuPG keyring,
optionally stripping delimiters ("+" followed by a topic).

Add some comments and docstrings.
2022-10-19 18:36:23 +00:00
68e4a452d2 Split _gpg_encrypt into smaller functions 2022-10-19 18:36:23 +00:00
1edef79787 Update documentation to cover daemon tests 2022-10-19 18:36:23 +00:00
414f1d5921 Implement E2E tests for lacre.daemon
- Add a dedicated configuration file for lacre.daemon.

- Implement test/daemon_test.py like test/e2e_test.py, to automate the
following procedure:

    1. Start up lacre.daemon.
    2. For each test case, send test message to the daemon and verify that the
       output received by test/utils/relay.py contains expected pattern.

- Simplify Makefile.

- Fix indentation here and there.
2022-10-19 18:36:23 +00:00
a131cd66d3 Move different parts of Lacre tests to subdirectories
In particular, move:

- test utilities to test/utils;
- unit tests to test/modules.

Also: start implementing the Lacre daemon test (just a stub for now).
2022-10-19 18:36:23 +00:00
4c844384e3 Implement a bare minimum of advanced filtering
- Forward messages without encryption.

- Include a simple test setup in the Makefile.

- Add a test to send a test message to the daemon.
2022-10-19 18:36:23 +00:00
6455c1a280 [daemon] Add configuration, implement no-op filter
- Add a "mailop" module to define mail operations.  Each should inherit from
MailOperation class (which just defines the contract).

- Make lacre.mailgate.delivery_plan always return KeepIntact strategy to have
a daemon that just forwards messages without modifying them.

- Add sample configuration.

- Include daemon configuration in mandatory parameter check.
2022-10-19 18:36:23 +00:00
7849c55d9f Extend the daemon skeleton 2022-10-19 18:36:23 +00:00
29b5b50901 Mailgate: replace tabs with spaces 2022-10-19 18:36:23 +00:00
3f2760ba2d Create skeleton of the Lacre daemon
Also:
- Expose a function to read mail relay configuration.
- Replace tabs with 4 spaces in lacre.config.
2022-10-19 18:36:23 +00:00
8f191cae72 Restore keyring before running E2E tests 2022-10-19 18:36:23 +00:00
b198f0c4f4 Fix logging
First initialise logging, then import lacre.mailgate module.  Otherwise,
module's logging quitely initialises its own root logger that doesn't use
configuration provided by the user.

Also: remove unnecessary "global" keywords.
2022-10-19 18:36:23 +00:00
9e998b54e9 Extract a predicate to classify messages as already encrypted
Also: perform minor cleanup.
2022-10-19 18:36:23 +00:00
4d22ef9406 Merge pull request 'Removing webfrontend as it was migrated to standalone repository' (#98) from uncoupleFE into main
Reviewed-on: #98
2022-10-19 18:31:05 +00:00
156b09fd4e
added execute permission to webgate-cron.py 2022-10-19 09:35:52 +02:00
2ebd090d6c
uncoupled web frontend (lacre-webgate) from gpg-lacre; moved cron.py from frontend to backend dir and changed name (webgate-cron.py); 2022-10-12 16:29:09 +02:00
pfm
002e150805 Merge pull request 'Move core logic from gpg-mailgate.py to lacre.mailgate module' (#91) from 90-core-module into master
Reviewed-on: #91
2022-06-11 19:10:36 +00:00
5ffbbec5f0 Rename sort_recipients to deliver_message, remove unused imports 2022-06-11 21:05:27 +02:00
b627fde510 Move gpg-mailgate.py logic to lacre.mailgate module
gpg-mailgate.py script keeps its role, but only needs to call code defined in
lacre.mailgate.
2022-06-11 21:00:42 +02:00
pfm
8a366f2f17 Merge pull request 'Handle addresses with delimiters' (#89) from 87-handle-delimiters into master
Reviewed-on: #89
2022-06-08 19:32:27 +00:00
881a8d1756 Add GnuPG encryption support for addresses with delimiters
If a user registers their key for address alice@example.com but receives a
message sent to alice+something@example.com, this message should be encrypted
as well.

- Implement delimiter support for GnuPG encryption.

- Add E2E test case for a clear text message delivered to an address with
delimiter.

- Fix minor bug: wrong configuration parameter was retrieved when logging
information about enc_domain_keymap being active.
2022-06-08 21:20:58 +02:00
c86c620668 Extract delimiter support, add unit tests
Also: fix recursive call to get_cert_for_email.
2022-06-07 22:14:32 +02:00
pfm
c4781f2ac8 Merge pull request 'Record execution time and log it' (#86) from 84-measure-time into master
Reviewed-on: #86
2022-06-02 21:44:56 +00:00