Exemplo n.º 1
0
def loop(id):
    while True:
        curr_round = requests.get("http://localhost:5001/current_round").text
        message = input(f"ID:{id} Round:{curr_round} Message $> ")

        cpacket = CPacket()

        # conversant
        if int(id) == 0:
            payload = pl.Payload(address1, address2,
                                 message.ljust(512).encode())
        elif int(id) == 1:
            payload = pl.Payload(address2, address1,
                                 message.ljust(512).encode())

        cpacket.payload = pl.export_payload(payload)

        with open("server_keys.json") as f:
            keys = [k.encode() for k in json.loads(f.read())]

        cpacket.client_prep_up(keys)

        requests.post(f"http://localhost:5001/submission/{id}",
                      data=cpacket.send_out())

        # busy wait

        response = requests.get(f"http://localhost:5001/deaddrop/{id}")

        while response.status_code != HTTPStatus.OK:
            time.sleep(2)
            print("waiting for server")
            response = requests.get(f"http://localhost:5001/deaddrop/{id}")

        cpacket.client_prep_down(response.content)

        print(
            f"[{time.strftime('%a %H:%M:%S')}] {cpacket.send_out().decode().strip()}"
        )
Exemplo n.º 2
0
#! /usr/bin/env python3
# test/test_payload.py

import sys, os

sys.path.append(os.path.abspath('../Kudu'))

from lib import payload as pl

# local changes
pl.ADDRESS_SIZE = 3
pl.MESSAGE_SIZE = 10

pay = pl.Payload("foo".encode(), "bar".encode(), "saltywater".encode())
print(pay)

expor = pl.export_payload(pay)
print(expor)

impor = pl.import_payload(expor)
print(impor)


Exemplo n.º 3
0
S_COUNT = 3

# get some text dumps
with open("test/blackbird.txt", "rb") as f:
    address1, address2, body1, body2 = [
        f.read(x) for x in (pl.ADDRESS_SIZE, pl.ADDRESS_SIZE, pl.MESSAGE_SIZE,
                            pl.MESSAGE_SIZE)
    ]

# construct client packets
cpackets = [CPacket() for _ in range(C_COUNT)]
# print("a1", len(address1))
# print("a2", len(address2))
# print("b1", len(body1))

cpackets[0].payload = pl.export_payload(pl.Payload(address1, address2, body2))
cpackets[1].payload = pl.export_payload(pl.Payload(address2, address1, body1))

with open("server_keys.json") as f:
    keys = [k.encode() for k in json.loads(f.read())]

cpackets[0].client_prep_up(keys)
cpackets[1].client_prep_up(keys)

# serv.collect_request(b"0", cpackets[0].send_out())

requests.post('http://localhost:5001/submission/0',
              data=cpackets[0].send_out())
requests.post('http://localhost:5001/submission/1',
              data=cpackets[1].send_out())
Exemplo n.º 4
0
from lib import easy_crypto as ec
import lib.payload as pl

from client.packet import Packet as CPacket
from server.server import Server

C_COUNT = 2
S_COUNT = 3

# fix these values to ease interactions
pl.ADDRESS_SIZE = 3
pl.MESSAGE_SIZE = 10

# construct client packets
cpackets = [CPacket() for _ in range(C_COUNT)]
cpackets[0].payload = pl.export_payload(
    pl.Payload("foo".encode(), "bar".encode(), "saltywater".encode()))
cpackets[1].payload = pl.export_payload(
    pl.Payload("bar".encode(), "foo".encode(), "smeltysalt".encode()))

# run server which will generate key
serv = Server(client_count=C_COUNT, server_count=S_COUNT)

with open("server_keys.json") as f:
    keys = [k.encode() for k in json.loads(f.read())]

cpackets[0].client_prep_up(keys)
cpackets[1].client_prep_up(keys)

print(f"prior to collects round:{serv.current_round} state:{serv.mode}")

serv.collect_request(b"0", cpackets[0].send_out())
Exemplo n.º 5
0
def message_loop():
    url = f"http://localhost:{server_port}/current_round"
    curr_round = int(requests.get(url).text)

    while True:
        message = None
        while not message:  # prompt until valid message
            clear_send = input(f"ID:{self_id} Round:{curr_round} Message $> ")
            try:
                if clear_send:
                    message = pl.construct_message(clear_send, partner_rsa_key)
                else:
                    message = pl.construct_noise(partner_rsa_key)
            except (TypeError, ValueError, UnicodeEncodeError) as e:
                print("Message invalid:", e)

        packet = Packet()

        send_addr = ec.generate_deaddrop_id(shared_secret, self_id, partner_id,
                                            curr_round)  # drop
        recv_addr = ec.generate_deaddrop_id(shared_secret, partner_id, self_id,
                                            curr_round)  # collect

        # conversant
        payload = pl.Payload(send_addr, recv_addr, message)

        packet.payload = pl.export_payload(payload)

        packet.client_prep_up(server_keys)

        # send out message
        url = f"http://localhost:{server_port}/submission/{self_id}"
        response = requests.post(url, data=packet.send_out())
        while response.status_code != HTTPStatus.ACCEPTED:
            time.sleep(4)
            print("waiting for server: send")
            response = requests.post(url, data=packet.send_out())

        # wait on response
        url = f"http://localhost:{server_port}/deaddrop/{self_id}"
        response = requests.get(url)
        while response.status_code != HTTPStatus.OK:
            time.sleep(4)
            print("waiting for server: return")
            response = requests.get(url)

        packet.client_prep_down(response.content)

        try:
            noise, message_recieved = pl.deconstruct_message(
                packet.send_out(), ec.export_rsa_private(key_rsa))

        except (TypeError, ValueError, UnicodeDecodeError) as e:
            print(f"[{time.strftime('%a %H:%M:%S')}]",
                  f"{{Error Message Invalid: {e}}}")
        else:
            if noise:
                print(f"[{time.strftime('%a %H:%M:%S')}]", "{No Message}")
            else:
                print(f"[{time.strftime('%a %H:%M:%S')}]", message_recieved,
                      f"{{{len(message_recieved)}}}")

        curr_round += 1