예제 #1
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)
예제 #2
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]
예제 #3
0
def perform_online_handshake(online_node_socket, address):
    global online_shared_key
    [successful_handshake, computed_shared_key] = Modified_SSL_Handshake.server_ssl_handshake(online_node_socket,
                                                                                              "Middle Node",
                                                                                              private_key)
    online_shared_key = computed_shared_key
    return successful_handshake
예제 #4
0
def initial_middle_connection_send_dh():
    global n
    global middle_shared_key

    middle_socket = Modified_SSL_Handshake.connect_to_node(5432)
    [successful_handshake, shared_k
     ] = Modified_SSL_Handshake.client_ssl_handshake(middle_socket,
                                                     "Online Node",
                                                     private_key)
    print("[Online Node] Sending DH portion")
    private_dh = Modified_SSL_Handshake.gen_priv_dh_send_pub_dh(
        middle_socket, "Online Node", private_key)
    middle_shared_key = shared_k

    receive_n(middle_socket)
    receive_next_time(middle_socket)
    return private_dh
예제 #5
0
def perform_offline_handshake(online_node_socket):
    global offline_shared_key
    [successful_handshake, shared_k
     ] = Modified_SSL_Handshake.client_ssl_handshake(online_node_socket,
                                                     "Middle Node",
                                                     private_key)
    offline_shared_key = shared_k
    return successful_handshake
예제 #6
0
def initiate_DH_offline_connection(node_1_public_dh):
    offline_socket = Modified_SSL_Handshake.connect_to_node(5433)

    # send online DH
    offline_socket.sendall(Functions.wrap_to_send(node_1_public_dh))

    node_3_dh = Functions.read_message_with_delimiter(offline_socket)
    offline_socket.close()
    return node_3_dh
예제 #7
0
def initiate_DH_online_connection(node_2_public_dh):
    online_socket = Modified_SSL_Handshake.connect_to_node(5432)

    # send offline DH
    online_socket.sendall(Functions.wrap_to_send(node_2_public_dh))

    # Receive transfer data
    data_to_transfer = Functions.read_message_with_delimiter(online_socket)
    online_socket.close()
    return data_to_transfer
예제 #8
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
예제 #9
0
def second_dh_connection(private_dh_key):
    print("connecting to middle node...")
    middle_socket = Modified_SSL_Handshake.connect_to_node(
        5432)  # TODO: might need to change port

    # send authorization n
    send_n(middle_socket)

    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)

    receive_n(middle_socket)
    receive_next_time(middle_socket)
    middle_socket.close()
    return shared_dh
예제 #10
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
예제 #11
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
예제 #12
0
def send_data_transfer(shared_key, data):
    middle_socket = Modified_SSL_Handshake.connect_to_node(5432)
    send_n(middle_socket)

    # encrypt Data
    [iv, encrypted_data] = Functions.aes_encrypt(shared_key, data)
    encrypted_data = {"iv": iv, "encrypted_data": encrypted_data}

    # Send Data
    print("[Online Node] Sending: ", encrypted_data)
    middle_socket.sendall(Functions.wrap_to_send(encrypted_data))
    receive_n(middle_socket)
    receive_next_time(middle_socket)
    middle_socket.close()
예제 #13
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()
예제 #14
0
def transfer_data(data):
    offline_socket = Modified_SSL_Handshake.connect_to_node(5433)
    offline_socket.send(Functions.wrap_to_send(data))
    offline_socket.close()
예제 #15
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
예제 #16
0
def initial_middle_connection_send_dh():
    middle_socket = Modified_SSL_Handshake.connect_to_node(5432)
    private_dh = Modified_SSL_Handshake.gen_priv_dh_send_pub_dh(
        middle_socket, "Online Node", private_key)
    return private_dh