예제 #1
0
def test_encryptor_encrypt_decrypt():
	params = SphinxParams()
	group = params.group
	encryptor = Encryptor(group)
	msg = hexlify(str(11).encode())
	session_name = os.urandom(16)
	## Alice
	pk, sk = encryptor.keyGenerate('test')
	## Bob
	public_key_expon, iv, ciphertext, tag = encryptor.encrypt_aes_gcm(msg, pk[2], session_name)
	## Alice
	msg_decrypted = encryptor.decrypt_aes_gcm(
		(public_key_expon, iv, ciphertext, tag), 
		sk.x)
	assert(msg_decrypted == msg)
예제 #2
0
def loopix_mixes():
    sec_params = SphinxParams(header_len=1024)

    dbManager.create_mixnodes_table('Mixnodes')
    mixes = []
    pubs_mixes = []
    for i in range(3):
        mix = LoopixMixNode(sec_params, 'Mix%d' % (i + 1), 9999 - i,
                            '1.2.3.%d' % i, i)
        mix.transport = proto_helpers.FakeDatagramTransport()
        mix.config_params = mix.config_params._replace(DATABASE_NAME='test.db')
        mixes.append(mix)
        dbManager.insert_row_into_table('Mixnodes', [
            None, mix.name, mix.port, mix.host,
            sqlite3.Binary(petlib.pack.encode(mix.pubk)), mix.group
        ])
    pubs_mixes = [Mix(m.name, m.port, m.host, m.pubk, m.group) for m in mixes]
    return mixes, pubs_mixes
예제 #3
0
def loopix_providers():
    sec_params = SphinxParams(header_len=1024)

    dbManager.create_providers_table('Providers')
    providers = []
    pubs_providers = []
    for i in range(3):
        p = LoopixProvider(sec_params, 'Provider%d' % (i + 1), 9995 - i,
                           '1.2.%d.4' % i)
        p.transport = proto_helpers.FakeDatagramTransport()
        p.config_params = p.config_params._replace(DATABASE_NAME='test.db')
        providers.append(p)
        dbManager.insert_row_into_table('Providers', [
            None, p.name, p.port, p.host,
            sqlite3.Binary(petlib.pack.encode(p.pubk))
        ])
    pubs_providers = [
        Provider(p.name, p.port, p.host, p.pubk) for p in providers
    ]
    return providers, pubs_providers
예제 #4
0
def loopix_clients(pubs_providers, pubs_mixes):

    sec_params = SphinxParams(header_len=1024)

    dbManager.create_users_table('Users')
    clients = []
    pubs_clients = []
    for i in range(3):
        provider = pubs_providers[i]
        c = LoopixClient(sec_params, 'Client%d' % (i + 1), 9993 - i,
                         '1.%d.3.4' % i, provider.name)
        c.register_mixes(pubs_mixes)
        c.transport = proto_helpers.FakeDatagramTransport()
        c.config_params = c.config_params._replace(DATABASE_NAME='test.db')
        c.provider = dbManager.select_provider_by_name(provider.name)
        clients.append(c)
        dbManager.insert_row_into_table('Users', [
            None, c.name, c.port, c.host,
            sqlite3.Binary(petlib.pack.encode(c.pubk)), c.provider.name
        ])
    pubs_clients = [
        User(c.name, c.port, c.host, c.pubk, c.provider) for c in clients
    ]
    return clients, pubs_clients
예제 #5
0
            node_name = os.path.basename(root)
            full_path = os.path.join(root, filename)
            _, name, port, host, group, _ = readPacked(full_path)
            nodes[get_addr(host, port)] = name

    for root, dirnames, filenames in os.walk(path):
        # Find all publicMixnode.bin files and extract provider info
        for filename in fnmatch.filter(filenames, 'publicProvider.bin'):
            node_name = os.path.basename(root)
            full_path = os.path.join(root, filename)
            _, name, port, host, _ = readPacked(full_path)
            nodes[get_addr(host, port)] = name
    return (keys, providers, nodes)


packer = SphinxPacker((SphinxParams(header_len=1024), None))


def decrypt_packet(packet, initial_key, keys):
    """Decrypts packet with initial_key, and continues decrypting with keys"""
    data = packet.data.data.data
    key = initial_key
    decoded_packet = petlib.pack.decode(data)
    # Some of the packets sent are unencrypted SUBSCRIBE and PULL messages
    if decoded_packet[0] in ['SUBSCRIBE', 'PULL']:
        return decoded_packet[0], None
    routing_flag = Relay_flag
    while routing_flag != Dest_flag:
        try:
            # Decrypt sphinx packets
            tag, routing, new_header, new_body = packer.decrypt_sphinx_packet(
예제 #6
0
from loopix_mixnode import LoopixMixNode
from twisted.internet import reactor
from twisted.application import service, internet

import petlib.pack
from binascii import hexlify
import os.path
from sphinxmix.SphinxParams import SphinxParams

if not (os.path.exists("secretMixnode.prv")
        and os.path.exists("publicMixnode.bin")):
    raise Exception("Key parameter files not found")

secret = petlib.pack.decode(file("secretMixnode.prv", "rb").read())
sec_params = SphinxParams(header_len=1024, body_len=57800)
try:
    data = file("publicMixnode.bin", "rb").read()
    _, name, port, host, group, _ = petlib.pack.decode(data)

    mix = LoopixMixNode(sec_params,
                        name,
                        port,
                        host,
                        group,
                        privk=secret,
                        pubk=None)
    reactor.listenUDP(port, mix)
    reactor.run()
    udp_server = internet.UDPServer(port, mix)
    application = service.Application("Mixnode")
예제 #7
0
파일: run_all.py 프로젝트: evantsik/loopix
from loopix_mixnode import LoopixMixNode
from twisted.internet import reactor
from twisted.application import service, internet
import petlib.pack
from sphinxmix.SphinxParams import SphinxParams

name = str(sys.argv[1])
i = int(sys.argv[2])
body = 57800
#recieving only 8192, lets fix it
body = 57865
packet_size = 59000
if name == 'client':
    secret = petlib.pack.decode(
        file("../example/secretClient%d.prv" % i, "rb").read())
    sec_params = SphinxParams(header_len=1024, body_len=body)
    try:
        data = file("../example/publicClient%d.bin" % i, "rb").read()
        _, name, port, host, _, prvinfo = petlib.pack.decode(data)

        client = LoopixClient(sec_params,
                              name,
                              port,
                              host,
                              provider_id=prvinfo,
                              privk=secret)
        udp_server = internet.UDPServer(port, client)
        application = service.Application("Client")
        udp_server.setServiceParent(application)
        reactor.listenUDP(port, client, maxPacketSize=59000)
        reactor.run()
예제 #8
0
def test_generate_random_delay():
    sec_params = SphinxParams(header_len=1024)
    client = env.clients[0]
    packer = SphinxPacker((sec_params, client.config_params))
    delay = packer.generate_random_delay(0.0)
    assert delay == 0.0
예제 #9
0
sys.path += [current_path]

from loopix_provider import LoopixProvider
from twisted.internet import reactor
from twisted.application import service, internet
import petlib.pack
from sphinxmix.SphinxParams import SphinxParams

if not (os.path.exists("secretProvider.prv")
        and os.path.exists("publicProvider.bin")):
    raise Exception("Key parameter files not found")

secret = petlib.pack.decode(file("secretProvider.prv", "rb").read())
_, name, port, host, _ = petlib.pack.decode(
    file("publicProvider.bin", "rb").read())
sec_params = SphinxParams(header_len=1024)

try:
    provider = LoopixProvider(sec_params,
                              name,
                              port,
                              host,
                              privk=secret,
                              pubk=None)
    # reactor.listenUDP(port, provider)
    # reactor.run()
    udp_server = internet.UDPServer(port, provider)
    application = service.Application("Provider")
    udp_server.setServiceParent(application)

except Exception, e:
예제 #10
0
파일: make test.py 프로젝트: momerm/sphinx
# Make a test case.
# The test case is a json file containing private keys of nodes and a
# sphinx packet routed through those nodes.

from sphinxmix.SphinxParams import SphinxParams
from sphinxmix.SphinxClient import *
import json

r = 5
params = SphinxParams()

nodes_routing = []
node_priv_keys = []
node_pub_keys = []

for i in range(r):
    nid = b"node" + bytes(str(i))
    x = params.group.gensecret()
    y = params.group.expon(params.group.g, [x])

    nodes_routing.append(Nenc(nid))
    node_priv_keys.append(x)
    node_pub_keys.append(y)

header, delta = create_forward_message(params, nodes_routing, node_pub_keys,
                                       b"bob", b"this is a test")
bin_message = pack_message(params, (header, delta))

# Save private keys and binary message to file
testcase = {}
testcase['keys'] = map(lambda x: list(bytearray(x.binary())), node_priv_keys)
예제 #11
0
def getGlobalSphinxParams():
    return SphinxParams(header_len=1024, body_len=1024 * 100)