def connect_to(host, port):
    # create client public key
    client = Connection(create_keys())

    # create and assign client handler
    proto_handler = tr.socket()
    client.handler = proto_handler

    # connect to server
    tr.connect_to(proto_handler, host, port)

    # receive server public key
    server_key_string = tr.recv(proto_handler).encode('utf-8')
    server_key = get_key_from_string(server_key_string)

    client.partner_key = server_key

    # send to server client's public key
    key_string = client.pub_key.exportKey("PEM").decode('utf-8')
    tr.send(proto_handler, key_string)
    return client
def start_sever(host, port):
    # create public key
    server = Connection(create_keys())

    # create and assign server handler
    server_handler = tr.server_socket(host, port)
    server.handler = server_handler

    # listening for connections
    tr.wait_for_connections(server_handler)

    # send public key
    key_string = server.pub_key.exportKey("PEM").decode('utf-8')
    tr.send(server_handler, key_string)

    # receive client pub key
    client_key_string = tr.recv(server_handler).encode('utf-8')
    client_key = get_key_from_string(client_key_string)
    server.partner_key = client_key

    return server
def send(mess, conn):
    # encript message with received public key
    encripted = encrypt(mess, conn.partner_key)
    # send message encoded
    tr.send(conn.handler, encripted)
Beispiel #4
0
import p1_transfer as pv
import sys

if __name__ == "__main__":
    server_handler = pv.server_socket("0.0.0.0", 1919)

    # listening for connections
    pv.wait_for_connections(server_handler)

    val = 'do the lab'

    pv.send(server_handler, val)
    val = pv.recv(server_handler)
    print(val)

    # val += ' - no, you!'
    # pv.send(server_handler, val)
    # val_new = pv.recv(server_handler)
Beispiel #5
0
import p1_transfer as pv
import sys

if __name__ == "__main__":
    proto_handler = pv.socket()
    pv.connect_to(proto_handler, '0.0.0.0', 1919)

    val = pv.recv(proto_handler)
    val += ' - no, you!'
    pv.send(proto_handler, val)

    # val_new = pv.recv(proto_handler)
    # pv.send(proto_handler, val_new + ' - nope')

    # pv.close(proto_handler)