1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
""""""
from pathlib import Path
import gpgmime
from mailman.config import config as mailman_config
from mailman.utilities.string import expand
from public import public
from mailman_pgp.config import config
GPG_CONFIG_PATHS = ['homedir', 'keyring', 'secring', 'binary']
KEYPAIR_CONFIG_VARIABLES = ['key_type', 'key_length',
'subkey_type', 'subkey_length']
KEYPAIR_CONFIG_DEFAULTS = {
'key_usage': 'auth,sign,cert',
'subkey_usage': 'enc'
}
@public
class GPG(gpgmime.GPG):
def __init__(self):
# Get all the [keypairs] config variables.
self.keypair_config = dict(
(k, config.get('keypairs', k)) for k in KEYPAIR_CONFIG_VARIABLES)
self.keypair_config.update(KEYPAIR_CONFIG_DEFAULTS)
# Get and expand all [gpg] config paths against Mailman's directories.
self.gpg_config = dict(
(k, expand(config.get('gpg', k), None, mailman_config.paths))
for k in GPG_CONFIG_PATHS)
# Ensure that the homedir path is a directory before passing it to GPG.
# If it's actually a file this raises FileExistsError.
homedir_path = Path(self.gpg_config['homedir'])
homedir_path.mkdir(parents=True, exist_ok=True)
super().__init__(**self.gpg_config)
|