Esempio n. 1
0
    def command(self):
        key_files = self.data.get(
            "key_file", []) + [a for a in self.args if not '://' in a]
        key_urls = self.data.get("key_url",
                                 []) + [a for a in self.args if '://' in a]
        key_data = []
        key_data.extend(self.data.get("key_data", []))
        for key_file in key_files:
            with open(key_file) as file:
                key_data.append(file.read())
        for key_url in key_urls:
            with ConnBroker.context(need=[ConnBroker.OUTGOING_HTTP]):
                uo = urllib2.urlopen(key_url)
            key_data.append(uo.read())

        rv = self._gnupg().import_keys('\n'.join(key_data))

        # Previous crypto evaluations may now be out of date, so we
        # clear the cache so users can see results right away.
        ClearParseCache(pgpmime=True)

        # Update the VCards!
        PGPKeysImportAsVCards(self.session,
                              arg=([i['fingerprint'] for i in rv['updated']] +
                                   [i['fingerprint']
                                    for i in rv['imported']])).run()

        return self._success(_("Imported %d keys") % len(key_data), rv)
Esempio n. 2
0
    def command(self):
        session, config, idx = self.session, self.session.config, self._idx()
        args = list(self.args)
        if args and args[-1][0] == "#":
            attid = args.pop()
        else:
            attid = self.data.get("att", 'application/pgp-keys')
        args.extend(["=%s" % x for x in self.data.get("mid", [])])
        eids = self._choose_messages(args)
        if len(eids) < 0:
            return self._error("No messages selected", None)
        elif len(eids) > 1:
            return self._error("One message at a time, please", None)

        email = Email(idx, list(eids)[0])
        fn, attr = email.extract_attachment(session, attid, mode='inline')
        if attr and attr["data"]:
            res = self._gnupg().import_keys(attr["data"])

            # Previous crypto evaluations may now be out of date, so we
            # clear the cache so users can see results right away.
            ClearParseCache(pgpmime=True)

            return self._success("Imported key", res)

        return self._error("No results found", None)
Esempio n. 3
0
    def command(self):
        key_files = self.data.get(
            "key_file", []) + [a for a in self.args if not '://' in a]
        key_urls = self.data.get("key_url",
                                 []) + [a for a in self.args if '://' in a]
        key_data = []
        key_data.extend(self.data.get("key_data", []))
        for key_file in key_files:
            with open(key_file) as file:
                key_data.append(file.read())
        for key_url in key_urls:
            with ConnBroker.context(need=[ConnBroker.OUTGOING_HTTP]):
                uo = urllib2.urlopen(key_url)
            key_data.append(uo.read())

        rv = self._gnupg().import_keys('\n'.join(key_data))

        # Previous crypto evaluations may now be out of date, so we
        # clear the cache so users can see results right away.
        ClearParseCache(pgpmime=True)

        # FIXME: Start a keychain rescan, hopefully targetted on the keys
        #        we just added.

        return self._success(_("Imported %d keys") % len(key_data), rv)
Esempio n. 4
0
    def command(self):
        if self.session.config.sys.lockdown:
            return self._error(_('In lockdown, doing nothing.'))

        signingkey = None
        keyid = None
        args = list(self.args)
        try:
            keyid = args.pop(0)
        except:
            keyid = self.data.get("keyid", None)
        try:
            signingkey = args.pop(0)
        except:
            signingkey = self.data.get("signingkey", None)

        print keyid
        if not keyid:
            return self._error("You must supply a keyid", None)
        rv = self._gnupg().sign_key(keyid, signingkey)

        # Previous crypto evaluations may now be out of date, so we
        # clear the cache so users can see results right away.
        ClearParseCache(pgpmime=True)

        return rv
Esempio n. 5
0
    def command(self):
        args = list(self.args)
        if args:
            address, fprints, origins = args[0], args[1].split(','), args[2:]
        else:
            address = self.data.get('address', [''])[0]
            fprints = self.data.get('fingerprints', [])
            origins = self.data.get('origins', [])
        assert (address or fprints or origins)

        result = lookup_crypto_keys(self.session,
                                    address,
                                    get=[f.strip() for f in fprints],
                                    origins=origins,
                                    event=self.event)
        if len(result) > 0:
            # Update the VCards!
            PGPKeysImportAsVCards(self.session,
                                  arg=[k['fingerprint']
                                       for k in result]).run()
            # Previous crypto evaluations may now be out of date, so we
            # clear the cache so users can see results right away.
            ClearParseCache(pgpmime=True)

        return self._success(
            _n('Imported %d encryption key', 'Imported %d encryption keys',
               len(result)) % len(result),
            result=result)
Esempio n. 6
0
    def command(self):
        keyid = self.data.get("keyid", self.args)
        res = []
        for key in keyid:
            res.append(self._gnupg().recv_key(key))

        # Previous crypto evaluations may now be out of date, so we
        # clear the cache so users can see results right away.
        ClearParseCache(pgpmime=True)

        return res
Esempio n. 7
0
    def command(self):
        if self.session.config.sys.lockdown:
            return self._error(_('In lockdown, doing nothing.'))

        keyid = self.data.get("keyid", self.args)
        res = []
        for key in keyid:
            res.append(self._gnupg().recv_key(key))

        # Previous crypto evaluations may now be out of date, so we
        # clear the cache so users can see results right away.
        ClearParseCache(pgpmime=True)

        return res
Esempio n. 8
0
    def command(self):
        key_data = ""
        if len(self.args) != 0:
            key_file = self.data.get("key_file", self.args[0])
            with open(key_file) as file:
                key_data = file.read()
        if "key_data" in self.data:
            key_data = self.data.get("key_data")
        elif "key_file" in self.data:
            pass
        rv = self._gnupg().import_keys(key_data)

        # Previous crypto evaluations may now be out of date, so we
        # clear the cache so users can see results right away.
        ClearParseCache(pgpmime=True)

        return rv
Esempio n. 9
0
    def command(self):
        emails = set(list(self.args)) | set(self.data.get('email', []))
        assert (emails)

        idx = self._idx()
        gnupg = self._gnupg(dry_run=True)
        missing, old, status = [], {}, {}

        for email in emails:
            vc = self.session.config.vcards.get_vcard(email)
            fp = vc.pgp_key if vc else None
            if vc and fp:
                if self._key_can_encrypt(gnupg, fp):
                    old[email] = fp
                    status[email] = 'Key is already on our key-chain'
                else:
                    # FIXME: Should we remove the bad key from the vcard?
                    # FIXME: Should we blacklist the bad key?
                    missing.append(email)
                    status[email] = 'Obsolete key is on our key-chain'
            else:
                missing.append(email)
                status[email] = 'We have no key for this person'

        should_import = {}
        for email in missing:
            if self._uses_crypto(idx, email):
                keys = lookup_crypto_keys(self.session,
                                          email,
                                          origins=self.TOFU_ORIGINS,
                                          strict_email_match=True,
                                          event=self.event)
                for keyinfo in (keys or []):
                    if self._seen_enough_signatures(idx, email, keyinfo):
                        should_import[email] = keyinfo['fingerprint']
                        break
                if keys and 'email' not in should_import:
                    status[email] = 'Found keys, but none in active use'
            else:
                status[email] = 'Have not seen enough PGP messages'

        imported = {}
        for email, fingerprint in should_import.iteritems():
            keys = lookup_crypto_keys(self.session,
                                      email,
                                      get=[fingerprint],
                                      origins=self.TOFU_ORIGINS,
                                      strict_email_match=True,
                                      event=self.event)
            if keys:
                imported[email] = keys
                status[email] = 'Imported key!'
            else:
                status[email] = 'Failed to import key'

        for email in imported:
            if email in missing:
                missing.remove(email)

        if len(imported) > 0:
            # Update the VCards!
            fingerprints = []
            for keys in imported.values():
                fingerprints.extend([k['fingerprint'] for k in keys])
            PGPKeysImportAsVCards(self.session, arg=fingerprints).run()
            # Previous crypto evaluations may now be out of date, so we
            # clear the cache so users can see results right away.
            ClearParseCache(pgpmime=True)

        # i18n note: Not translating things here, since messages are not
        #            generally use-facing and we want to reduce load on our
        #            translators.
        return self._success('Evaluated key TOFU',
                             result={
                                 'missing_keys': missing,
                                 'imported_keys': imported,
                                 'status': status,
                                 'on_keychain': old
                             })