diff options
| author | J08nY | 2017-06-18 02:08:19 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-18 02:08:19 +0200 |
| commit | b8767a634966b2c4ea9b2c8a71174ca49e3c2f2f (patch) | |
| tree | ab55c0fc3f44342e7161245c015061ca306b593c /src/mailman_pgp/pgp | |
| parent | aa407033bdb43cf09b1eeff2aa06a80a78ee00d7 (diff) | |
| download | mailman-pgp-b8767a634966b2c4ea9b2c8a71174ca49e3c2f2f.tar.gz mailman-pgp-b8767a634966b2c4ea9b2c8a71174ca49e3c2f2f.tar.zst mailman-pgp-b8767a634966b2c4ea9b2c8a71174ca49e3c2f2f.zip | |
Add list key generation.
Diffstat (limited to 'src/mailman_pgp/pgp')
| -rw-r--r-- | src/mailman_pgp/pgp/__init__.py | 22 | ||||
| -rw-r--r-- | src/mailman_pgp/pgp/keygen.py | 29 |
2 files changed, 47 insertions, 4 deletions
diff --git a/src/mailman_pgp/pgp/__init__.py b/src/mailman_pgp/pgp/__init__.py index c96d1b0..ec31b2d 100644 --- a/src/mailman_pgp/pgp/__init__.py +++ b/src/mailman_pgp/pgp/__init__.py @@ -1,5 +1,7 @@ """""" +from pathlib import Path + import gpgmime from mailman.config import config as mailman_config from mailman.utilities.string import expand @@ -8,15 +10,27 @@ 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'] @public class GPG(gpgmime.GPG): def __init__(self): - self.list_key_size = config.getint('keypairs', 'size') - self.list_key_type = config.get('keypairs', 'type') + # Get all the [keypairs] config variables. + self.keypair_config = dict( + (k, config.get('keypairs', k)) for k in KEYPAIR_CONFIG_VARIABLES) + self.keypair_config['key_usage'] = 'auth,sign,cert' + self.keypair_config['subkey_usage'] = 'enc' - gpg_config = dict( + # 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) - super().__init__(**gpg_config) + + # 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) diff --git a/src/mailman_pgp/pgp/keygen.py b/src/mailman_pgp/pgp/keygen.py new file mode 100644 index 0000000..b15dbf6 --- /dev/null +++ b/src/mailman_pgp/pgp/keygen.py @@ -0,0 +1,29 @@ +"""""" + +import threading + +from mailman_pgp.config import config + + +class KeyGenerator(threading.Thread): + def __init__(self, name, email, comment=None): + super().__init__(daemon=True) + self._name = name + self._comment = comment + self._email = email + self.key_fingerprint = None + + def run(self): + default_config = config.gpg.keypair_config + key_config = dict(default_config) + key_config.update(dict(name_real=self._name, + name_email=self._email)) + if self._comment is not None: + key_config['name_comment'] = self._comment + key_input = config.gpg.gen_key_input(**key_config) + key = config.gpg.gen_key(key_input) + self.key_fingerprint = key.fingerprint + + @property + def has_key(self): + return self.key_fingerprint is not None |
