Пример #1
0
    def get_vcards(self):
        if not self.config.active:
            return []

        gnupg = GnuPG()
        keys = gnupg.list_keys()
        results = []
        vcards = {}
        for key in keys.values():
            vcls = [VCardLine(name="KEY",
                              value=self.VCL_KEY_FMT % key)]
            card = None
            emails = []
            for uid in key["uids"]:
                if "email" in uid and uid["email"]:
                    vcls.append(VCardLine(name="email", value=uid["email"]))
                    card = card or vcards.get(uid['email'])
                    emails.append(uid["email"])
                if "name" in uid and uid["name"]:
                    name = uid["name"]
                    vcls.append(VCardLine(name="fn", value=name))
            if card and emails:
                card.add(*vcls)
            elif emails:
                # This is us taking care to only create one card for each
                # set of e-mail addresses.
                card = SimpleVCard(*vcls)
                for email in emails:
                    vcards[email] = card
                results.append(card)

        return results
Пример #2
0
    def get_vcards(self):
        if not self.config.active:
            return []

        gnupg = GnuPG()
        keys = gnupg.list_keys()
        results = []
        vcards = {}
        for key_id, key in keys.iteritems():
            vcls = [VCardLine(name='KEY', value=self.VCL_KEY_FMT % key_id)]
            card = None
            emails = []
            for uid in key.get('uids', []):
                if uid.get('email'):
                    vcls.append(VCardLine(name='email', value=uid['email']))
                    card = card or vcards.get(uid['email'])
                    emails.append(uid['email'])
                if uid.get('name'):
                    name = uid['name']
                    vcls.append(VCardLine(name='fn', value=name))
            if card and emails:
                card.add(*vcls)
            elif emails:
                # This is us taking care to only create one card for each
                # set of e-mail addresses.
                card = MailpileVCard(*vcls)
                for email in emails:
                    vcards[email] = card
                results.append(card)

        return results
Пример #3
0
    def get_vcards(self):
        if not self.config.active:
            return []

        gnupg = GnuPG()
        keys = gnupg.list_keys()
        results = []
        vcards = {}
        for key in keys.values():
            vcls = [VCardLine(name="KEY", value=self.VCL_KEY_FMT % key)]
            card = None
            emails = []
            for uid in key["uids"]:
                if "email" in uid and uid["email"]:
                    vcls.append(VCardLine(name="email", value=uid["email"]))
                    card = card or vcards.get(uid['email'])
                    emails.append(uid["email"])
                if "name" in uid and uid["name"]:
                    name = uid["name"]
                    vcls.append(VCardLine(name="fn", value=name))
            if card and emails:
                card.add(*vcls)
            elif emails:
                # This is us taking care to only create one card for each
                # set of e-mail addresses.
                card = SimpleVCard(*vcls)
                for email in emails:
                    vcards[email] = card
                results.append(card)

        return results
Пример #4
0
    def get_vcards(self):
        if not self.config.active:
            return []

        gnupg = GnuPG()
        keys = gnupg.list_keys()
        results = []
        vcards = {}
        for key_id, key in keys.iteritems():
            vcls = [VCardLine(name='KEY', value=self.VCL_KEY_FMT % key_id)]
            card = None
            emails = []
            for uid in key.get('uids', []):
                if uid.get('email'):
                    vcls.append(VCardLine(name='email', value=uid['email']))
                    card = card or vcards.get(uid['email'])
                    emails.append(uid['email'])
                if uid.get('name'):
                    name = uid['name']
                    vcls.append(VCardLine(name='fn', value=name))
            if card and emails:
                card.add(*vcls)
            elif emails:
                # This is us taking care to only create one card for each
                # set of e-mail addresses.
                card = SimpleVCard(*vcls)
                for email in emails:
                    vcards[email] = card
                results.append(card)

        return results
Пример #5
0
def lookup_crypto_keys(session, address):
    x = {}
    scores = []
    for handler in KEY_LOOKUP_HANDLERS:
        h = handler(session)
        r, s = h.lookup(address)
        for key, value in r.iteritems():
            if key in x:
                x[key].update(value)
            else:
                x[key] = value
                x[key]["origin"] = []
            x[key]["origin"].append(h.NAME)
        scores.append(s)

    for scoreset in scores:
        for key, value in scoreset.iteritems():
            if key not in x:
                continue
            if "score" not in x[key]:
                x[key]["score"] = 0
            x[key]["score"] += value

    g = GnuPG()
    known_keys_list = g.list_keys()
    for key in x.keys():
        x[key]["fingerprint"] = key
        x[key]["score"] += crypto_keys_scorer(known_keys_list, key)

    x = [i for i in x.values()]
    x.sort(key=lambda k: -k["score"])
    return x
Пример #6
0
def lookup_crypto_keys(session, address, event=None, allowremote=True):
    def _calc_scores(x, scores):
        for key in x.keys():
            x[key]["score"] = 0

        for scoreset in scores:
            for key, value in scoreset.iteritems():
                if key not in x:
                    continue
                if "score" not in x[key]:
                    x[key]["score"] = 0
                x[key]["score"] += value
        return x

    x = {}
    scores = []
    lastresult = {}

    for handler in KEY_LOOKUP_HANDLERS:
        h = handler(session)
        if not allowremote and not h.LOCAL:
            continue

        if event:
            m = _calc_scores(x, scores)
            m = [i for i in m.values()]
            m.sort(key=lambda k: -k["score"])
            event.private_data = {"result": m, "runningsearch": h.NAME}
            session.config.event_log.log_event(event)

        r, s = h.lookup(address)
        for key, value in r.iteritems():
            if key in x:
                x[key].update(value)
            else:
                x[key] = value
                x[key]["origin"] = []
            x[key]["origin"].append(h.NAME)
        scores.append(s)

    x = _calc_scores(x, scores)

    g = GnuPG()
    known_keys_list = g.list_keys()
    for key in x.keys():
        x[key]["fingerprint"] = key
        x[key]["score"] += crypto_keys_scorer(known_keys_list, key)

    x = [i for i in x.values()]
    x.sort(key=lambda k: -k["score"])
    if event:
        event.private_data = {"result": x, "runningsearch": None}
        session.config.event_log.log_event(event)
    return x
Пример #7
0
def lookup_crypto_keys(session, address, event=None, allowremote=True):
    def _calc_scores(x, scores):
        for key in x.keys():
            x[key]["score"] = 0

        for scoreset in scores:
            for key, value in scoreset.iteritems():
                if key not in x:
                    continue
                if "score" not in x[key]:
                    x[key]["score"] = 0
                x[key]["score"] += value
        return x

    x = {}
    scores = []
    lastresult = {}

    for handler in KEY_LOOKUP_HANDLERS:
        h = handler(session)
        if not allowremote and not h.LOCAL:
            continue

        if event:
            m = _calc_scores(x, scores)
            m = [i for i in m.values()]
            m.sort(key=lambda k: -k["score"])
            event.private_data = {"result": m, "runningsearch": h.NAME}
            session.config.event_log.log_event(event)

        r, s = h.lookup(address)
        for key, value in r.iteritems():
            if key in x:
                x[key].update(value)
            else:
                x[key] = value
                x[key]["origin"] = []
            x[key]["origin"].append(h.NAME)
        scores.append(s)

    x = _calc_scores(x, scores)

    g = GnuPG()
    known_keys_list = g.list_keys()
    for key in x.keys():
        x[key]["fingerprint"] = key
        x[key]["score"] += crypto_keys_scorer(known_keys_list, key)

    x = [i for i in x.values()]
    x.sort(key=lambda k: -k["score"])
    if event:
        event.private_data = {"result": x, "runningsearch": None}
        session.config.event_log.log_event(event)
    return x
Пример #8
0
def scorer_trust(key):
    global known_keys_list
    score = 0
    if known_keys_list == None:
        g = GnuPG()
        known_keys_list = g.list_keys()

    if key in known_keys_list:
        if "e" in known_keys_list[key]["validity"]:
            score += -100
        elif "r" in known_keys_list[key]["validity"]:
            score += -10000
        elif "d" in known_keys_list[key]["validity"]:
            score += -10000
        elif ("f" in known_keys_list[key]["validity"] 
           or "u" in known_keys_list[key]["validity"]):
            score += 50
        else:
            score += 10

    return score
Пример #9
0
    def get_vcards(self):
        if not self.config.active:
            return []

        gnupg = GnuPG(self.session.config)
        keys = gnupg.list_keys()

        results = []
        vcards = {}
        for key_id, key in keys.iteritems():
            if (key.get("disabled") or key.get("revoked")
                    or not key["capabilities_map"].get("encrypt")
                    or not key["capabilities_map"].get("sign")):
                continue
            vcls = [VCardLine(name='KEY', value=self.VCL_KEY_FMT % key_id)]
            card = None
            emails = []
            for uid in key.get('uids', []):
                if uid.get('email'):
                    vcls.append(VCardLine(name='email', value=uid['email']))
                    card = card or vcards.get(uid['email'])
                    emails.append(uid['email'])
                if uid.get('name'):
                    name = uid['name']
                    vcls.append(VCardLine(name='fn', value=name))
            if card and emails:
                card.add(*vcls)
            elif emails:
                # This is us taking care to only create one card for each
                # set of e-mail addresses.
                card = MailpileVCard(*vcls)
                for email in emails:
                    vcards[email] = card
                results.append(card)

        return results