diff options
| author | J08nY | 2017-08-02 23:40:53 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-02 23:40:53 +0200 |
| commit | 8c08406f9f9b46400ae06e636b4805d19029354c (patch) | |
| tree | 6623e4d2cd30a2a65bdfa1cf0e6c8d434e5e9190 /src/mailman_pgp/utils/pgp.py | |
| parent | 7a4b76f64fc08d667ac48f432a726061998bd81f (diff) | |
| download | mailman-pgp-8c08406f9f9b46400ae06e636b4805d19029354c.tar.gz mailman-pgp-8c08406f9f9b46400ae06e636b4805d19029354c.tar.zst mailman-pgp-8c08406f9f9b46400ae06e636b4805d19029354c.zip | |
Diffstat (limited to 'src/mailman_pgp/utils/pgp.py')
| -rw-r--r-- | src/mailman_pgp/utils/pgp.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/mailman_pgp/utils/pgp.py b/src/mailman_pgp/utils/pgp.py index 416e643..a8f06f2 100644 --- a/src/mailman_pgp/utils/pgp.py +++ b/src/mailman_pgp/utils/pgp.py @@ -81,6 +81,7 @@ def key_from_file(file): @public def revoc_from_blob(blob): """ + Load a key revocation signature from an ASCII-Armored blob. :param blob: :return: @@ -103,27 +104,44 @@ def revoc_from_blob(blob): @public def key_usable(key, flags_required): """ + Check that the `key` has the `flags_required` set of KeyFlags. - :param key: + Checks only non-expired, non-revoked key/subkeys. Validates revocations it + can, so not those made with some other designated revocation key. + + :param key: The key to check. :type key: pgpy.PGPKey - :param flags_required: + :param flags_required: The set of flags required. :type flags_required: set - :return: + :return: Whether the key has the flags_required. :rtype: bool """ if key.is_expired: return False - primary_revocs = (sig for sig in key.self_signatures if - sig.sigtype is SignatureType.KeyRevocation) - for revoc in primary_revocs: + for revoc in key.revocation_signatures: try: verified = key.verify(key, revoc) except PGPError: continue if bool(verified): return False + usage_flags = key.usage_flags() for subkey in key.subkeys.values(): - usage_flags |= subkey.usage_flags() + if subkey.is_expired: + continue + + valid = True + for revoc in subkey.revocation_signatures: + try: + verified = key.verify(subkey, revoc) + except PGPError: + continue + if bool(verified): + valid = False + break + + if valid: + usage_flags |= subkey.usage_flags() return flags_required.issubset(usage_flags) |
