aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/pgp/__init__.py
diff options
context:
space:
mode:
authorJ08nY2017-06-19 21:43:25 +0200
committerJ08nY2017-06-19 21:43:25 +0200
commit6c875100ea39233ca53e615bd7d3be8e86b4928c (patch)
tree41a1e3f09f87bb9e09ec9f45c7eaea6ffd882df3 /src/mailman_pgp/pgp/__init__.py
parentbb3929f368076e5a27779361fc1853290c7f42a9 (diff)
downloadmailman-pgp-6c875100ea39233ca53e615bd7d3be8e86b4928c.tar.gz
mailman-pgp-6c875100ea39233ca53e615bd7d3be8e86b4928c.tar.zst
mailman-pgp-6c875100ea39233ca53e615bd7d3be8e86b4928c.zip
Diffstat (limited to 'src/mailman_pgp/pgp/__init__.py')
-rw-r--r--src/mailman_pgp/pgp/__init__.py27
1 files changed, 19 insertions, 8 deletions
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):