Exemplo n.º 1
0
    def test_process_incoming_calls_hook(self, account_maker):
        sender = account_maker()
        rec1, rec2 = account_maker(), account_maker()

        # make sure sender has all keys
        sender.process_incoming(gen_ac_mail_msg(rec1, sender))
        sender.process_incoming(gen_ac_mail_msg(rec2, sender))

        # send an encrypted mail from sender to both recipients
        gossip_msg = gen_ac_mail_msg(sender, [rec1, rec2])
        enc_msg = sender.encrypt_mime(gossip_msg,
                                      [rec1.addr, rec2.addr]).enc_msg

        l = []

        class Plugin:
            @hookimpl
            def process_incoming_gossip(self, addr2pagh, account_key, dec_msg):
                l.append((addr2pagh, account_key, dec_msg))

        rec1.plugin_manager.register(Plugin())
        rec1.process_incoming(enc_msg)
        assert len(l) == 1
        addr2pagh, account_key, dec_msg = l[0]
        assert account_key == rec1.ownstate.keyhandle
        assert dec_msg["Message-Id"] == gossip_msg["Message-Id"]
        assert rec1.addr in addr2pagh
        assert rec2.addr in addr2pagh

        assert addr2pagh[rec1.addr].keydata == get_own_pubkey(rec1)
        assert addr2pagh[rec2.addr].keydata == get_own_pubkey(rec2)
Exemplo n.º 2
0
    def test_process_outgoing_calls_hook(self, account_maker):
        sender = account_maker()
        rec1, rec2 = account_maker(), account_maker()

        # make sure sender has all keys
        sender.process_incoming(gen_ac_mail_msg(rec1, sender))
        sender.process_incoming(gen_ac_mail_msg(rec2, sender))
        gossip_msg = gen_ac_mail_msg(sender, [rec1, rec2])

        l = []

        class Plugin:
            @hookimpl
            def process_before_encryption(self, sender_addr, sender_keyhandle,
                                          recipient2keydata, payload_msg,
                                          _account):
                l.append((
                    sender_addr,
                    sender_keyhandle,
                    recipient2keydata,
                    payload_msg,
                    _account,
                ))
                payload_msg["My-Plugin-Header"] = "My own header"

        sender.plugin_manager.register(Plugin())

        # send an encrypted mail from sender to both recipients
        enc_msg = sender.encrypt_mime(gossip_msg,
                                      [rec1._fulladdr, rec2.addr]).enc_msg

        assert len(l) == 1
        sender_addr, sender_keyhandle = l[0][:2]
        recipient2keydata, payload_msg, _account = l[0][2:]
        assert _account == sender
        assert sender_keyhandle == sender.ownstate.keyhandle
        assert sender_addr == sender.addr
        assert len(recipient2keydata) == 2
        assert recipient2keydata[rec1.addr] == get_own_pubkey(rec1)
        assert recipient2keydata[rec2.addr] == get_own_pubkey(rec2)
        assert enc_msg["Message-Id"] == gossip_msg["Message-Id"]
        rec1.process_incoming(enc_msg)
        dec_msg = rec1.decrypt_mime(enc_msg).dec_msg
        assert dec_msg["My-Plugin-Header"] == "My own header"
Exemplo n.º 3
0
def send_encrypted_mail(sender, recipients):
    """Send an encrypted mail from sender to recipients
       Decrypt and process it.
       Returns the result of processing the Autocrypt header
       and the decryption result.
    """
    if isinstance(recipients, Account):
        recipients = [recipients]
    msg = gen_ac_mail_msg(sender, recipients, payload="hello ä umlaut", charset="utf8")
    enc_msg = sender.encrypt_mime(msg, [r.addr for r in recipients]).enc_msg
    for rec in recipients:
        processed = rec.process_incoming(enc_msg)
        decrypted = rec.decrypt_mime(enc_msg)
    return processed, decrypted
Exemplo n.º 4
0
def send_encrypted_mail(sender, recipients):
    """Send an encrypted mail from sender to recipients
       upload the new cc blocks,
       Decrypt and process it.
       Returns the result of processing the Autocrypt header
       and the decryption result.
    """
    if isinstance(recipients, Account):
        recipients = [recipients]
    msg = gen_ac_mail_msg(sender, recipients, payload="hello", charset="utf8")
    enc_msg = sender.encrypt_mime(msg, [r.addr for r in recipients]).enc_msg
    get_cc_account(sender).upload()
    for rec in recipients:
        pah = rec.process_incoming(enc_msg).pah
        dec_msg = rec.decrypt_mime(enc_msg).dec_msg
    return pah, dec_msg
Exemplo n.º 5
0
def send_mail(acc1, acc2):
    msg = gen_ac_mail_msg(acc1, acc2)
    acc2.process_incoming(msg)
    return msg