diff options
| -rw-r--r-- | src/mailman_pgp/config/__init__.py | 1 | ||||
| -rw-r--r-- | src/mailman_pgp/pgp/__init__.py | 27 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/mailman_pgp/config/__init__.py b/src/mailman_pgp/config/__init__.py index 93b33d0..282d1ee 100644 --- a/src/mailman_pgp/config/__init__.py +++ b/src/mailman_pgp/config/__init__.py @@ -11,7 +11,6 @@ from public.public import public class Config(ConfigParser): def __init__(self): super().__init__() - self.keyrings = {} def load(self, name): self.name = name diff --git a/src/mailman_pgp/pgp/__init__.py b/src/mailman_pgp/pgp/__init__.py index e1627e1..bca8847 100644 --- a/src/mailman_pgp/pgp/__init__.py +++ b/src/mailman_pgp/pgp/__init__.py @@ -1,7 +1,8 @@ """""" -from os import listdir, makedirs -from os.path import isfile +from glob import glob +from os import makedirs +from os.path import join from mailman.config import config as mailman_config from mailman.utilities.string import expand @@ -14,7 +15,10 @@ from mailman_pgp.config import config KEYDIR_CONFIG_PATHS = ['list_keydir', 'user_keydir', 'archive_keydir'] KEYPAIR_CONFIG_VARIABLES = ['key_type', 'key_length', 'subkey_type', 'subkey_length'] + +# The main key needs to support signing. KEYPAIR_KEY_TYPE_VALID = ['RSA', 'DSA', 'ECDSA'] +# The subkey needs to support encryption. KEYPAIR_SUBKEY_TYPE_VALID = ['RSA', 'ECDH'] KEYPAIR_TYPE_MAP = { 'RSA': PubKeyAlgorithm.RSAEncryptOrSign, @@ -31,22 +35,30 @@ class PGP: self._validate_config() def _load_config(self): + """ + Load [keypairs] and [keydirs] config sections. Expand paths in them. + """ # Get all the [keypairs] config variables. self.keypair_config = dict( (k, config.get('keypairs', k)) for k in KEYPAIR_CONFIG_VARIABLES) - # Get and expand all [keydirs] config paths against Mailman's directories. + # Get and expand all [keydirs] config paths against Mailman's paths. self.keydir_config = dict( (k, expand(config.get('keydirs', k), None, mailman_config.paths)) for k in KEYDIR_CONFIG_PATHS) def _validate_config(self): - # Validate keypair config + """ + Validate [keypairs] and [keydirs] config sections. And create + keydirs if necessary. + """ + # Validate keypair config. key_type = self.keypair_config['key_type'].upper() if key_type not in KEYPAIR_KEY_TYPE_VALID: raise ValueError('Invalid key_type. {}'.format(key_type)) self.keypair_config['key_type'] = KEYPAIR_TYPE_MAP[key_type] - self.keypair_config['key_length'] = int(self.keypair_config['key_length']) + self.keypair_config['key_length'] = int( + self.keypair_config['key_length']) subkey_type = self.keypair_config['subkey_type'].upper() if subkey_type not in KEYPAIR_SUBKEY_TYPE_VALID: @@ -61,9 +73,8 @@ class PGP: makedirs(keydir, exist_ok=True) def _keyring(self, keydir): - keyfiles = [f for f in listdir(self.keydir_config[keydir]) - if isfile(f)] - return PGPKeyring(*keyfiles) + directory = self.keydir_config[keydir] + return PGPKeyring(*glob(join(directory, '*.asc'))) @property def list_keyring(self): |
