forked from Disroot/gpg-lacre
Compare commits
2 commits
main
...
post-test-
Author | SHA1 | Date | |
---|---|---|---|
Piotr F. Mieszkowski | 95069c06a7 | ||
Piotr F. Mieszkowski | 91969dbfbb |
|
@ -83,6 +83,11 @@ config = /etc/gpg-lacre-logging.conf
|
||||||
host = 127.0.0.1
|
host = 127.0.0.1
|
||||||
port = 10025
|
port = 10025
|
||||||
|
|
||||||
|
# Maximum size (in bytes) of message body, i.e. data provided after DATA
|
||||||
|
# message. Following value comes from aiosmtpd module's default for this
|
||||||
|
# setting.
|
||||||
|
max_data_bytes = 33554432
|
||||||
|
|
||||||
[relay]
|
[relay]
|
||||||
# the relay settings to use for Postfix
|
# the relay settings to use for Postfix
|
||||||
# gpg-mailgate will submit email to this relay after it is done processing
|
# gpg-mailgate will submit email to this relay after it is done processing
|
||||||
|
|
|
@ -47,17 +47,22 @@ class MailEncryptionProxy:
|
||||||
except TypeError as te:
|
except TypeError as te:
|
||||||
LOG.exception("Got exception while processing", exc_info=te)
|
LOG.exception("Got exception while processing", exc_info=te)
|
||||||
return RESULT_ERROR
|
return RESULT_ERROR
|
||||||
|
except:
|
||||||
|
LOG.exception('Unexpected exception caught, bouncing message')
|
||||||
|
return RESULT_ERROR
|
||||||
|
|
||||||
ellapsed = (time.process_time() - start) * 1000
|
ellapsed = (time.process_time() - start) * 1000
|
||||||
LOG.info(f'Message delivered in {ellapsed:.2f} ms')
|
LOG.info(f'Message delivered in {ellapsed:.2f} ms')
|
||||||
return RESULT_OK
|
return RESULT_OK
|
||||||
|
|
||||||
|
|
||||||
def _init_controller(keys: kcache.KeyRing, tout: float = 5):
|
def _init_controller(keys: kcache.KeyRing, max_body_bytes=None, tout: float = 5):
|
||||||
proxy = MailEncryptionProxy(keys)
|
proxy = MailEncryptionProxy(keys)
|
||||||
host, port = conf.daemon_params()
|
host, port = conf.daemon_params()
|
||||||
LOG.info(f"Initialising a mail Controller at {host}:{port}")
|
LOG.info(f"Initialising a mail Controller at {host}:{port}")
|
||||||
return Controller(proxy, hostname=host, port=port, ready_timeout=tout)
|
return Controller(proxy, hostname=host, port=port,
|
||||||
|
ready_timeout=tout,
|
||||||
|
data_size_limit=max_body_bytes)
|
||||||
|
|
||||||
|
|
||||||
def _init_reloader(keyring_dir: str, reloader) -> kcache.KeyringModificationListener:
|
def _init_reloader(keyring_dir: str, reloader) -> kcache.KeyringModificationListener:
|
||||||
|
@ -88,8 +93,12 @@ def _main():
|
||||||
_validate_config()
|
_validate_config()
|
||||||
|
|
||||||
keyring_path = conf.get_item('gpg', 'keyhome')
|
keyring_path = conf.get_item('gpg', 'keyhome')
|
||||||
keyring = kcache.KeyRing(keyring_path)
|
max_data_bytes = int(conf.get_item('daemon', 'max_data_bytes', 2**25))
|
||||||
controller = _init_controller(keyring)
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
keyring = kcache.KeyRing(keyring_path, loop)
|
||||||
|
controller = _init_controller(keyring, max_data_bytes)
|
||||||
reloader = _init_reloader(keyring_path, keyring)
|
reloader = _init_reloader(keyring_path, keyring)
|
||||||
|
|
||||||
LOG.info(f'Watching keyring directory {keyring_path}...')
|
LOG.info(f'Watching keyring directory {keyring_path}...')
|
||||||
|
@ -99,7 +108,7 @@ def _main():
|
||||||
controller.start()
|
controller.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
asyncio.run(_sleep())
|
loop.run_until_complete(_sleep())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
LOG.info("Finishing...")
|
LOG.info("Finishing...")
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -9,7 +9,7 @@ import lacre.config as conf
|
||||||
import logging
|
import logging
|
||||||
from os import stat
|
from os import stat
|
||||||
from watchdog.events import FileSystemEventHandler, FileSystemEvent
|
from watchdog.events import FileSystemEventHandler, FileSystemEvent
|
||||||
from asyncio import Semaphore, run
|
from asyncio import Semaphore, create_task, get_event_loop
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
import GnuPG
|
import GnuPG
|
||||||
|
@ -73,12 +73,13 @@ class KeyRing:
|
||||||
fingerprint=>email maps.
|
fingerprint=>email maps.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path: str):
|
def __init__(self, path: str, loop=None):
|
||||||
"""Initialise the adapter."""
|
"""Initialise the adapter."""
|
||||||
self._path = path
|
self._path = path
|
||||||
self._keys = self._load_and_sanitize()
|
self._keys = self._load_and_sanitize()
|
||||||
self._sema = Semaphore()
|
self._sema = Semaphore()
|
||||||
self._last_mod = None
|
self._last_mod = None
|
||||||
|
self._loop = loop or get_event_loop()
|
||||||
|
|
||||||
def _load_and_sanitize(self):
|
def _load_and_sanitize(self):
|
||||||
keys = self._load_keyring_from(self._path)
|
keys = self._load_keyring_from(self._path)
|
||||||
|
@ -96,7 +97,8 @@ class KeyRing:
|
||||||
def load(self):
|
def load(self):
|
||||||
"""Load keyring, replacing any previous contents of the cache."""
|
"""Load keyring, replacing any previous contents of the cache."""
|
||||||
LOG.debug('Reloading keys...')
|
LOG.debug('Reloading keys...')
|
||||||
run(self._load())
|
tsk = create_task(self._load(), 'LoadTask')
|
||||||
|
self._loop.run_until_complete(tsk)
|
||||||
|
|
||||||
async def _load(self):
|
async def _load(self):
|
||||||
last_mod = self._read_mod_time()
|
last_mod = self._read_mod_time()
|
||||||
|
|
Loading…
Reference in a new issue