diff options
| author | J08nY | 2017-08-18 16:48:46 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-18 16:48:46 +0200 |
| commit | 680ae1be88d22f2eb5d6f16a58acda4e5927ed72 (patch) | |
| tree | 9e2d3c2cc3ddabcfbfba3563a17106629a5c8e0f /src/mailman_pgp/utils/pgp.py | |
| parent | 86c2979281d4d87bc55b5203b064af12ec3795c2 (diff) | |
| download | mailman-pgp-680ae1be88d22f2eb5d6f16a58acda4e5927ed72.tar.gz mailman-pgp-680ae1be88d22f2eb5d6f16a58acda4e5927ed72.tar.zst mailman-pgp-680ae1be88d22f2eb5d6f16a58acda4e5927ed72.zip | |
Diffstat (limited to 'src/mailman_pgp/utils/pgp.py')
| -rw-r--r-- | src/mailman_pgp/utils/pgp.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mailman_pgp/utils/pgp.py b/src/mailman_pgp/utils/pgp.py index be97a75..05721b4 100644 --- a/src/mailman_pgp/utils/pgp.py +++ b/src/mailman_pgp/utils/pgp.py @@ -179,3 +179,48 @@ def key_usable(key, flags_required): if bool(verified): return False return flags_required.issubset(key_flags(key)) + + +@public +def key_merge(privkey, new_key, signer_key): + """ + + :param privkey: + :type privkey: pgpy.PGPKey + :param new_key: + :type new_key: pgpy.PGPKey + """ + if privkey.pubkey.key_material != new_key.key_material: + raise ValueError('You sent a wrong key.') + + uid_map = {} + for uid in privkey.userids: + for uid_other in new_key.userids: + if uid == uid_other: + uid_map[uid] = uid_other + + if len(uid_map) == 0: + raise ValueError('No signed UIDs found.') + + uid_sigs = {} + for uid, uid_other in uid_map.items(): + for sig in uid_other.signatures: + if sig in uid.signatures: + continue + if sig.signer != signer_key.fingerprint.keyid: + continue + # sig is a new signature, not currenctly on uid, ans seems to + # be made by the pgp_address.key + try: + verification = signer_key.verify(uid, sig) + if bool(verification): + uid_sigs.setdefault(uid, []).append(sig) + except PGPError: + pass + + if len(uid_sigs) == 0: + raise ValueError('No new certifications found.') + + for uid, sigs in uid_sigs.items(): + for sig in sigs: + uid |= sig |
