Пример #1
0
    def TransformOutgoing(self, sender, rcpts, msg, **kwargs):
        matched = False
        keydata = mutual = sender_keyid = key_binary = None

        gnupg = GnuPG(self.config, event=GetThreadEvent())
        profile = self._get_sender_profile(sender, kwargs)
        vcard = profile['vcard']
        if vcard is not None:
            crypto_format = vcard.crypto_format
            sender_keyid = vcard.pgp_key
            if sender_keyid and 'autocrypt' in crypto_format:
                key_binary = gnupg.get_minimal_key(key_id=sender_keyid,
                                                   user_id=sender)

            if key_binary:
                mutual = 'E' in crypto_format.split('+')[0].split(':')[-1]
                msg["Autocrypt"] = make_autocrypt_header(
                    sender, key_binary, prefer_encrypt_mutual=mutual)

                if 'encrypt' in msg.get('Encryption', '').lower():
                    gossip_list = []
                    for rcpt in rcpts:
                        # FIXME: Check if any of the recipients are in the BCC
                        #        header; omit their keys if so?
                        try:
                            # This *should* always succeed: if we are encrypting,
                            # then the key we encrypt to should already be in
                            # the keychain.
                            if '#' in rcpt:
                                rcpt, rcpt_keyid = rcpt.split('#')
                            else:
                                # This happens when composing in the CLI.
                                rcpt_keyid = rcpt
                            if (rcpt != sender) and rcpt_keyid:
                                kb = gnupg.get_minimal_key(key_id=rcpt_keyid,
                                                           user_id=rcpt)
                                if kb:
                                    gossip_list.append(
                                        make_autocrypt_header(
                                            rcpt,
                                            kb,
                                            prefix='Autocrypt-Gossip'))
                        except (ValueError, IndexError):
                            pass
                    if len(gossip_list) > 1:
                        # No point gossiping peoples keys back to them alone.
                        for hdr in gossip_list:
                            msg.add_header('Autocrypt-Gossip', hdr)

                matched = True

        return sender, rcpts, msg, matched, True
Пример #2
0
    def TransformOutgoing(self, sender, rcpts, msg, **kwargs):
        matched = False
        keydata = mutual = sender_keyid = key_binary = None

        gnupg = GnuPG(self.config, event=GetThreadEvent())
        profile = self._get_sender_profile(sender, kwargs)
        vcard = profile['vcard']
        if vcard is not None:
            crypto_format = vcard.crypto_format
            sender_keyid = vcard.pgp_key
            if sender_keyid and 'autocrypt' in crypto_format:
                key_binary = gnupg.get_minimal_key(key_id=sender_keyid,
                                                   user_id=sender)

            if key_binary:
                mutual = 'E' in crypto_format.split('+')[0].split(':')[-1]
                msg["Autocrypt"] = make_autocrypt_header(
                    sender, key_binary, prefer_encrypt_mutual=mutual)

                if 'encrypt' in msg.get('Encryption', '').lower():
                    gossip_list = []
                    for rcpt in rcpts:
                        # FIXME: Check if any of the recipients are in the BCC
                        #        header; omit their keys if so?
                        try:
                            # This *should* always succeed: if we are encrypting,
                            # then the key we encrypt to should already be in
                            # the keychain.
                            if '#' in rcpt:
                                rcpt, rcpt_keyid = rcpt.split('#')
                            else:
                                # This happens when composing in the CLI.
                                rcpt_keyid = rcpt
                            if (rcpt != sender) and rcpt_keyid:
                                kb = gnupg.get_minimal_key(key_id=rcpt_keyid,
                                                           user_id=rcpt)
                                if kb:
                                    gossip_list.append(make_autocrypt_header(
                                        rcpt, kb, prefix='Autocrypt-Gossip'))
                        except (ValueError, IndexError):
                            pass
                    if len(gossip_list) > 1:
                        # No point gossiping peoples keys back to them alone.
                        for hdr in gossip_list:
                            msg.add_header('Autocrypt-Gossip', hdr)

                matched = True

        return sender, rcpts, msg, matched, True