Пример #1
0
def get_body_and_meta(consensus):
    consensus_text = consensus["text"]
    unpacked_text = canonical.from_unicode_canonical(consensus_text)
    body = unpacked_text.get("body", {})
    canonical_body = canonical.to_canonical(body)
    meta = unpacked_text.get("meta", {})
    return canonical_body, meta
Пример #2
0
def mixnet_url_process(mixnet_url):
    catalog_url, endpoint_id = split_mixnet_url(mixnet_url)
    cfg.set_value("CATALOG_URL", catalog_url)
    client.register_catalog_url(catalog_url)
    print endpoint_id
    endpoint = client.endpoint_info(endpoint_id)
    if endpoint["status"] != "OPEN":
        abort("Endpoint is not open.")
    if endpoint["endpoint_type"] != "SPHINXMIX_GATEWAY":
        abort("Not a SPHINXMIX_GATEWAY.")

    peer_id = endpoint["peer_id"]
    cfg.set_value("PEER_ID", peer_id)
    peer = client.peer_info(peer_id)

    assert peer["crypto_backend"] == TYPE
    backend = common.BACKENDS[TYPE]
    client.register_backend(backend)
    cfg.set_value("CRYPTO_BACKEND", backend)
    crypto_params = canonical.from_unicode_canonical(peer["crypto_params"])
    cfg.set_value("CRYPTO_PARAMS", crypto_params)

    description = {"gateway": endpoint,
                   "mixnet_peer": peer}
    cfg.set_value("MIXNET_DESCRIPTION", description)
Пример #3
0
def verify(mixnet_data, signature, public, params):
    signature = canonical.from_unicode_canonical(signature)
    crypto = signature['crypto']
    modulus = crypto['modulus']
    generator = crypto['generator']
    order = crypto['order']

    if modulus != params.modulus or \
       generator != params.generator or order != params.order:
        raise ValueError("cryptographic parameters mismatch")

    element = core.element_from_texts_hash(
        modulus, generator, order, mixnet_data)
    if element != signature['e']:
        return False, None

    if public is None:
        public_int = signature['public']
        public = utils.int_to_unicode(public_int)
    else:
        public_int = utils.unicode_to_int(public)

    key_id = get_key_id_from_key_data(public)
    valid = bool(core.verify_element_signature(
        signature, modulus, generator, order, public_int))
    return valid, key_id
Пример #4
0
def verify(mixnet_data, signature, params):
    signature = canonical.from_unicode_canonical(signature)
    digest = sha256(mixnet_data).digest()
    sig = tuple(map(bn_decode, (signature["r"], signature["s"])))
    ver_key = mk_EcPt(signature["public"], params)
    valid = ecdsa.do_ecdsa_verify(params.group.G, ver_key, sig, digest)
    key_id = get_key_id_from_key_data(ver_key)
    return valid, key_id
Пример #5
0
 def contribution_accept(self, negotiation_id, contribution_id):
     data = {"id": contribution_id, "negotiation": negotiation_id}
     r = self.clients.contributions.retrieve(contribution_id, params=data)
     contrib = r.json()["data"]
     realtext = canonical.from_unicode_canonical(contrib["text"])
     body = realtext["body"]
     r = self.run_contribution(negotiation_id, body, True)
     d = r.json()["data"]
     return d
Пример #6
0
def check_close_negotiation(negotiation):
    latests = negotiation.get_latest_contributions()
    text_set = set(c.text for c in latests)
    if len(text_set) == 1:
        text = text_set.pop()
        unpacked_text = canonical.from_unicode_canonical(text)
        meta = unpacked_text.get("meta", {})
        accept = meta.get("accept", False)
        if accept:
            _close_negotiation(negotiation, latests)
Пример #7
0
def process_sk_mix(endpoint, messages, params):
    endpoint_params = canonical.from_unicode_canonical(
        endpoint["endpoint_params"])
    election_public = utils.unicode_to_int(
        endpoint_params["election_public"])

    message_texts = [m["text"] for m in messages]
    recipient = get_unique_recipient(messages)
    mixed_messages, proof = mix(message_texts, params, election_public)
    return utils.with_recipient(mixed_messages, recipient), proof
Пример #8
0
def handle_consensus(expected_body, part, consensus_id):
    consensus = retrieve_consensus(consensus_id)
    signings = consensus["signings"]
    body, meta = get_body_and_meta(consensus)
    if part is not None:
        body = canonical.from_unicode_canonical(body)
        assert isinstance(body, list)
        body = body[part]
        body = canonical.to_canonical(body)

    check_bodies_equal(expected_body, body)
    check_accepted(meta)
    check_all_signed(signings, meta)
    return signings
Пример #9
0
def join_crypto_params_set(contrib):
    text = get_contribution_text(contrib)
    crypto_params = text["body"]["data"]["crypto_params"]
    crypto_params = canonical.from_unicode_canonical(crypto_params)
    default = "accept"
    response = ui.ask_value(
        "response", "Proposed crypto params: '%s'; "
        "'accept' or 'abort'? (default: '%s')" % (crypto_params, default))
    if not response:
        response = default
    if response == "accept":
        return crypto_params
    elif response == "abort":
        abort()
Пример #10
0
    def take_action(self, parsed_args):
        vargs = vars(parsed_args)
        negotiation_id = vargs["negotiation_id"]
        client = mk_panoramix_client(cfg)
        contribs = filter_data_only(client.contribution_list(negotiation_id))
        listing = []

        for contrib in contribs:
            realtext = canonical.from_unicode_canonical(contrib["text"])
            listing.append({
                "body": realtext["body"],
                "meta": realtext["meta"],
                "id": contrib["id"],
                "signer_key_id": contrib["signer_key_id"],
            })
        return from_list_of_dict(listing)
Пример #11
0
 def write_to_file(self, message, filename):
     text = canonical.from_unicode_canonical(message["text"])
     with open(filename, "a") as f:
         f.write("%s\n\0" % utils.unicode_to_locale(text))
     return (message["id"], "file", filename)
Пример #12
0
def decode_message(message):
    return canonical.from_unicode_canonical(message)
Пример #13
0
def init_client():
    panoramix_client = client.PanoramixClient()
    catalog_url = cfg.get("CATALOG_URL")
    panoramix_client.register_catalog_url(catalog_url)
    backend = cfg.get("CRYPTO_BACKEND")
    panoramix_client.register_backend(backend)
    panoramix_client.register_crypto_client(cfg)
    mixnet_description = cfg.get("MIXNET_DESCRIPTION")
    panoramix_client.register_mixnet(mixnet_description)
    return panoramix_client


panoramix_client = init_client()

while True:
    outbox = panoramix_client.box_list(endpoint_id, client.OUTBOX)
    if outbox:
        print "Found outbox, checking..."
        outbox_messages = [(from_unicode_canonical(msg['text']),
                            msg['recipient']) for msg in outbox]
        if messages == outbox_messages:
            raise AssertionError("messages not shuffled")
        if messages != sorted(outbox_messages):
            raise AssertionError("messages do not match")
        print "Outbox verified!"
        break
    else:
        print "Outbox not ready yet..."
        time.sleep(3)
Пример #14
0
def get_contribution_text(contribution):
    return canonical.from_unicode_canonical(contribution["text"])
Пример #15
0
def get_negotiation_text(negotiation):
    return canonical.from_unicode_canonical(negotiation["text"])