Пример #1
0
def handle_inline_pgp(gpg, body, attachments):
    # attachments might contain public key
    attachments = [crypto.decrypt_attachment(gpg, attachment) for attachment in attachments]
    crypto.import_public_keys_from_attachments(gpg, attachments)

    encryption_status, signature_status, reason = crypto.check_encryption_and_signature(gpg, body)
    return encryption_status, signature_status, reason
Пример #2
0
def handle_multipart_encrypted(gpg, body):
    encryption_status, signature_status, reason = crypto.check_encryption_and_signature(gpg, body)

    if encryption_status != crypto.Encryption.correct:
        return encryption_status, signature_status, reason

    # parse the decrypted data into body and attachments
    result = gpg.decrypt(body)
    _, _, body, attachments = parse_message(result.data)

    # attachments might contain public key
    attachments = [crypto.decrypt_attachment(gpg, attachment) for attachment in attachments]
    crypto.import_public_keys_from_attachments(gpg, attachments)

    return encryption_status, signature_status, reason
Пример #3
0
def handle_multipart_signed(gpg, body, attachments):
    # there should be only one "attachment" which contains the signature
    signature = attachments[0]
    signature_status, reason = crypto.verify_external_sig(gpg, body, signature.encode())

    if signature_status != crypto.Signature.correct:
        return crypto.Encryption.missing, signature_status, reason

    # the multipart/signed contains another multipart body, split that one into actual body and attachments
    _, _, body, attachments = parse_message(body)

    # attachments might contain public key
    attachments = [crypto.decrypt_attachment(gpg, attachment) for attachment in attachments]
    crypto.import_public_keys_from_attachments(gpg, attachments)

    return crypto.Encryption.missing, signature_status, reason