diff options
| author | J08nY | 2017-06-20 22:29:51 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-20 22:29:51 +0200 |
| commit | 108f8854ec0b8df6f5d042e503fea0a23d679879 (patch) | |
| tree | ab386421d6b11b6b2efdd68e28262a6dfbab8ff0 /src/mailman_pgp/pgp/mime.py | |
| parent | 59ee5f86c65eb77409b0acae71e1b667ed0f1de8 (diff) | |
| download | mailman-pgp-108f8854ec0b8df6f5d042e503fea0a23d679879.tar.gz mailman-pgp-108f8854ec0b8df6f5d042e503fea0a23d679879.tar.zst mailman-pgp-108f8854ec0b8df6f5d042e503fea0a23d679879.zip | |
Diffstat (limited to 'src/mailman_pgp/pgp/mime.py')
| -rw-r--r-- | src/mailman_pgp/pgp/mime.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/mailman_pgp/pgp/mime.py b/src/mailman_pgp/pgp/mime.py index 7a632bf..8b87abe 100644 --- a/src/mailman_pgp/pgp/mime.py +++ b/src/mailman_pgp/pgp/mime.py @@ -19,8 +19,13 @@ from email.message import Message from email.utils import collapse_rfc2231_value +from pgpy import PGPKey, PGPSignature + class PGPMIMEWrapper: + _signed_subtype = 'application/pgp-signature' + _encrypted_subtype = 'application/pgp-encrypted' + def __init__(self, msg: Message): self.msg = msg @@ -41,9 +46,9 @@ class PGPMIMEWrapper: protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol')) content_subtype = self.msg.get_content_subtype() - return second_type == 'application/pgp-signature' and \ - content_subtype == 'signed' and \ - protocol_param == 'application/pgp-signature' + return second_type == PGPMIMEWrapper._signed_subtype and \ + content_subtype == 'signed' and \ + protocol_param == PGPMIMEWrapper._signed_subtype def is_mime_encrypted(self): """ @@ -59,7 +64,23 @@ class PGPMIMEWrapper: protocol_param = collapse_rfc2231_value(self.msg.get_param('protocol')) return 'Version: 1' in first_part and \ - first_type == 'application/pgp-encrypted' and \ + first_type == PGPMIMEWrapper._encrypted_subtype and \ second_type == 'application/octet-stream' and \ content_subtype == 'encrypted' and \ - protocol_param == 'application/pgp-encrypted' + protocol_param == PGPMIMEWrapper._encrypted_subtype + + def verify(self, key: PGPKey): + """ + + :param key: + :return: + """ + clear_text = str(self.msg.get_payload(0)) + sig_text = self.msg.get_payload(1).get_payload() + signature = PGPSignature.from_blob(sig_text) + verification = key.verify(clear_text, + signature) + return signature in [v.signature for v in verification.good_signatures] + + def decrypt(self, key: PGPKey): + pass |
