Commit Graph

48 Commits

Author SHA1 Message Date
Piotr F. Mieszkowski ad3a54fcd7 Rename GPG-Mailgate to Lacre
Update naming in documentation and the source code.
2024-01-06 14:34:54 +01:00
Piotr F. Mieszkowski 5c327b166a webgate-cron: Log more information, including exceptions 2023-12-19 18:21:00 +01:00
Piotr F. Mieszkowski fe2c0cbf76 Fix unprintable exception issue 2023-12-09 20:57:09 +01:00
Piotr F. Mieszkowski 75c48282b0 Rework encryption exception handling
Also: remove misleading comment about message.defects.
2023-12-09 20:38:46 +01:00
Piotr F. Mieszkowski fc08813bdc Improve unencryptable message logs 2023-12-09 19:48:20 +01:00
Piotr F. Mieszkowski 0fe5e6b3dc Make GnuPG.public_keys docstring more complete 2023-11-26 18:29:43 +01:00
Piotr F. Mieszkowski 72217e38ea GnuPG module: make key-listing more thorough
- Flush key-collecting structures each time a new public key entry is found.
  This will avoid adding sub-keys and overwriting main keys with them.

- Use parseaddr from email.utils to parse emails (and drop realname part).

- Record logs produced during unit tests.

- Fix a small bug in test code.

Also: add basic information about available test identities to testing
documentation.
2023-11-25 01:08:15 +01:00
Piotr F. Mieszkowski 4fbae908d6 Don't require less-than and greater-than around the email
Keys don't have to be surrounded with less-than and greater-than characters,
so this code could mishandle valid keys.
2023-11-19 22:45:08 +01:00
Piotr F. Mieszkowski 9bbc86bc53 Extract parts of cron script to modules
Introduce new Python modules:

- lacre.notify -- to send notifications from the cron script;

- lacre.dbschema -- to keep database schema definition as code (SQLAlchemy);

- lacre.repositories -- to define key and identity repositories with high
  level APIs that we can then use elsewhere.

Also:

- rework GnuPG.add_key to return fingerprint so we can use it in the cron
  script;

- rename cron-job's logger name, replacing dash with an underscore as logging
  module doesn't like dashes.
2023-11-12 19:56:45 +01:00
Piotr F. Mieszkowski 624a335a41 GnuPG: clean up and collect more diagnostic info
- Use regular expressions instead of finding particular characters in gnupg
  output to decide whether confirmation line was found.

- Use tempfile.mkdtemp to create secure temporary directories.

- Record information about the key considered by GnuPG. When missing in
  exception, it means no key was found.
2023-09-21 20:21:01 +02:00
Piotr F. Mieszkowski 5a5b6c27a4 Fix tests after rebase 2023-05-08 22:32:19 +02:00
Piotr F. Mieszkowski 509aac6de3 Improve command-generation, logging and readability 2023-05-08 22:17:01 +02:00
Piotr F. Mieszkowski 27b07e672d Rework PGP/MIME flow 2023-05-08 22:17:01 +02:00
Piotr F. Mieszkowski 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
Piotr F. Mieszkowski 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
Piotr F. Mieszkowski 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
Piotr F. Mieszkowski 8963eee47f Reformat GnuPG module 2022-10-19 18:36:23 +00:00
Piotr F. Mieszkowski 3bcc1151e5 Add E2E case: a user with a key and PGP/MIME configured
- Add a new test input message for a new test identity, test scenario
  configuration and a test key.

- While retrieving message payload, determine charset based on the
  Content-Type header.  When missing, default to UTF-8.

- Use more comprehensible variables names.

- Adjust logging levels.
2022-05-30 00:49:40 +02:00
Piotr F. Mieszkowski 55fa0d0601 [GnuPG.confirm_key] Convert email to bytes() before comparison 2022-05-06 19:14:52 +02:00
Piotr F. Mieszkowski 71afd6ed05 [GnuPG.confirm_key] Set 700 mode for temp. key home 2022-04-26 18:42:48 +02:00
Piotr F. Mieszkowski 454b519c70 Use bytes in confirm_key's line operations 2022-04-19 21:22:34 +02:00
Piotr F. Mieszkowski f472f4ac22 Use isinstance() instead of type() 2022-04-19 21:16:40 +02:00
Piotr F. Mieszkowski fdadc89c31 Use bytes in GnuPG.confirm_key too 2022-04-19 20:49:49 +02:00
Piotr F. Mieszkowski 5a34249090 Fix minor cron.py issues
Related to #63: TypeError: memoryview: a bytes-like object is required, not
'str'.

- Allow GnuPG.add_key accept either 'str' or 'bytes'.
- Import MIMEText from email.mime.text.
2022-04-10 19:03:18 +02:00
Piotr F. Mieszkowski 67a938c049 GnuPG.add_key: Use build_command 2022-01-25 20:32:17 +01:00
Piotr F. Mieszkowski 1e7d33c1df Handle bytes properly
Fix bytes sequences handling after auto-migration.
2022-01-10 18:21:53 +01:00
Piotr F. Mieszkowski 5f02223ec7 Perform automatic migration to Python 3.x
Use lib2to3 automatic migration tool provided by Python 2.x to convert
codebase to new idioms.

Command line:

find . -type f -name '*.py' \
    -exec python2.7 -m lib2to3 \
    -f all -f idioms -f buffer -f set_literal -f ws_comma -w \
    '{}' '+'
2022-01-10 18:21:20 +01:00
Piotr F. Mieszkowski 2cf60dec40 Add unit tests for GnuPG command-line generator
Extract a function to calculate GPG commands to be executed and cover it with
unit tests.
2022-01-09 21:37:14 +01:00
Piotr F. Mieszkowski f1a799d864 Adjust E2E tests to work with all scenarios
Since it's not so easy to encrypt a message exactly the same way twice, we
only verify if the message has been encrypted or not.

Introduce minor changes to the library itself, because it doesn't work very
well with modern GnuPG.

Also, include GnuPG directory (pointed at by --homedir option).
2022-01-06 16:34:47 +01:00
fkrone 2c0e342e5e Support for decrypting PGP encrypted mails. However, it has some drawbacks and might cause some security issues. So before using it please read carefully through the installation instructions. 2015-05-25 20:24:37 +02:00
fkrone 3cefd27163 Revert "Bugfix for commit before:"
This reverts commit 99a1108338.
2015-02-14 19:02:14 +01:00
fkrone 99a1108338 Bugfix for commit before:
Make check for keys in keymap case insensitive
2015-02-14 16:03:30 +01:00
fkrone e2ef883ec2 Merged change:
584eee18dc
( Added check that config file keymap fingerprint exists in actual GPG keyring. Decline encryption if mismatch. )
2015-02-14 16:01:58 +01:00
fkrone 63435c72c5 Merged change:
779e712a5d
( Changed GPGEncryptor.encrypt() to also give PGP return code. Write rc to logfile in encrypt_payload(). )
2015-02-14 15:22:29 +01:00
fkrone 0b503fa616 Fixing critical bug: looking up email addresses for PGP encryption in keychain was done case sensitive 2015-01-31 19:14:21 +01:00
fkrone 64db1a6bc0 Adding a key on a non-English system does not fail any longer 2015-01-04 17:54:44 +01:00
perennate 9ac151f438 Merge https://github.com/ajgon/gpg-mailgate
Conflicts:
	INSTALL
	README.md
	gpg-mailgate.conf.sample
	gpg-mailgate.py
2013-11-03 10:38:04 -05:00
perennate 4aa366dea5 Fix bug causing messages to have extra characters or failing to encode properly. 2013-11-03 15:13:03 +01:00
Colin Moller d468766f8a Patch GnuPG library to trust keys we've already got to avoid having to manually add them 2013-11-03 15:11:21 +01:00
Taylor Hornby ffaee4c577 Correctly encode 'keyhome' into a gpg command. 2013-10-08 17:00:55 -06:00
perennate fbe2f1bba1 Update license to GNU GPL v3. 2013-10-02 14:27:28 -04:00
perennate e01e505374 Release under GNU Lesser General Public License. 2013-09-27 22:21:55 -04:00
perennate 98b4e341cf Initial commit for gpg-mailgate-web addition. 2013-09-26 19:40:27 -04:00
perennate c04db9c35f Fix bug causing messages to have extra characters or failing to encode properly. 2013-09-16 19:38:31 +02:00
Colin Moller e7bd005430 Patch GnuPG library to trust keys we've already got to avoid having to manually add them 2013-09-16 19:24:25 +02:00
Igor Rzegocki d6aaa9f243 Fixed #1
GnuPG2.x listed keys are now properly interpreted.
2013-09-06 21:59:31 +02:00
Igor Rzegocki 078381c2dd Removed stdin.write and stdout.read from GnuPG and replaced it with subprocess.communicate, to avoid deadlocks when larger messages are passed in 2013-04-17 20:23:48 +02:00
mcmaster 782cda3639 GPG Mailgate 0.1 2010-01-20 15:53:25 -05:00