예제 #1
0
def handle_transferred_data(shared_key):
    middle_socket = Modified_SSL_Handshake.handle_node_connection(
        5433)  # TODO: might need to change port

    transfer_msg = Functions.read_message_with_delimiter(middle_socket)
    decrypted_data = Functions.aes_decrypt(transfer_msg["iv"], shared_key,
                                           transfer_msg["encrypted_data"])
    data_array = pickle.loads(decrypted_data)
    print(data_array)
    return data_array
예제 #2
0
def handle_DH_exchange():
    middle_socket = Modified_SSL_Handshake.handle_node_connection(5433)

    dh_msg = Functions.read_message_with_delimiter(middle_socket)
    online_dh_public = Functions.load_der_public_key(
        dh_msg["dh_public_through"], Modified_SSL_Handshake.default_backend())
    private_dh_key = Modified_SSL_Handshake.gen_priv_dh_send_pub_dh(
        middle_socket, "Offline Node", private_key)
    return Functions.generate_dh_shared_key(
        private_dh_key,
        online_dh_public.public_numbers().y)
예제 #3
0
def handle_dh_connection(private_dh_key):
    middle_socket = Modified_SSL_Handshake.handle_node_connection(
        5432)  # TODO: might need to change port

    dh_msg = Functions.read_message_with_delimiter(middle_socket)
    print("[Online Node] Received: ", dh_msg)
    dh_other_key = Functions.load_der_public_key(
        dh_msg["dh_public_through"], Modified_SSL_Handshake.default_backend())
    shared_dh = Functions.generate_dh_shared_key(
        private_dh_key,
        dh_other_key.public_numbers().y)
    return [shared_dh, middle_socket]
예제 #4
0
def receive_transfer_data():
    online_socket = Modified_SSL_Handshake.handle_node_connection(5432)

    receive_verify_online_n(online_socket)
    data_to_transfer = Functions.read_message_with_delimiter(online_socket)

    send_n(online_socket)
    time.sleep(2)
    send_next_time(online_socket)
    print("[Middle Node] Received data")
    online_socket.close()
    return data_to_transfer
예제 #5
0
def handle_DH_1_online_connection():
    global online_shared_key

    online_socket = Modified_SSL_Handshake.handle_node_connection(5432)
    perform_online_handshake(online_socket)  # TODO check if returns true

    given_dh_value = Functions.read_message_with_delimiter(online_socket)

    # send encrypted n
    send_n(online_socket)
    send_next_time(online_socket)
    online_socket.close()
    return given_dh_value
예제 #6
0
def handle_DH_2_online_connection(node_2_public_dh):
    print("opening online connection...")
    online_socket = Modified_SSL_Handshake.handle_node_connection(5432)

    # receive n-1
    receive_verify_online_n(online_socket)

    # send offline DH
    online_socket.sendall(Functions.wrap_to_send(node_2_public_dh))
    print("[Middle Node] sent DH")

    send_n(online_socket)
    time.sleep(2)
    send_next_time(online_socket)

    online_socket.close()
예제 #7
0
def handle_DH_online_connection():
    online_socket = Modified_SSL_Handshake.handle_node_connection(5432)

    given_dh_value = Functions.read_message_with_delimiter(online_socket)
    online_socket.close()
    return given_dh_value