def send_message_3(client_socket, merchant_SID, client_temporary_cert): print("Sent 3rd message.") NC = random.randint(100000, 10000000000) amount = b"500" PI = socket_functions.concat_messages( b"123456789101", b"11/22", b"123", merchant_SID, amount, crypto_lib.serialize_cert(client_temporary_cert), crypto_lib.int_to_bytes(NC), b"Merchant name") SIG_PI = crypto_lib.sign(PI, private_key_rsa) PM = socket_functions.concat_messages(PI, SIG_PI) encripted_PM = crypto_lib.encrypt_AES(PM, aes_key_PG, aes_iv_PG) PO_message = socket_functions.concat_messages(b"5 morcovi la 10 lei kg", merchant_SID, amount, crypto_lib.int_to_bytes(NC)) SigC = crypto_lib.sign(PO_message, private_key_rsa) PO = socket_functions.concat_messages(PO_message, SigC) encrypted_aes_key_PG = crypto_lib.encrypt_RSA(aes_key_PG, public_key_rsa_pg) encrypted_aes_iv_PG = crypto_lib.encrypt_RSA(aes_iv_PG, public_key_rsa_pg) message_to_send = socket_functions.concat_messages(encripted_PM, PO, encrypted_aes_key_PG, encrypted_aes_iv_PG) message_to_send = crypto_lib.encrypt_AES(message_to_send, aes_key_merchant, aes_iv_merchant) socket_functions.socket_send(client_socket, message_to_send) return NC, amount
def send_message_5(merchant_conn, resp, sid, amount, NC, AES_key_PG_M, AES_IV_PG_M): print("Sent 5th message.") message_to_sign = socket_functions.concat_messages(resp, sid, amount, NC) signature = crypto_lib.sign(message_to_sign, private_key_rsa) message_to_send = socket_functions.concat_messages(resp, sid, signature) message_to_send = crypto_lib.encrypt_AES(message_to_send, AES_key_PG_M, AES_IV_PG_M) socket_functions.socket_send(merchant_conn, message_to_send)
def send_message_2(client_conn, aes_key, aes_iv): print("Sent 2nd message.") SID = generate_SID() # print(crypto_lib.bytes_to_int(SID)) SID_signature = crypto_lib.sign(SID, private_key_rsa) message_to_send = socket_functions.concat_messages(SID, SID_signature) encrypted_message_to_send = crypto_lib.encrypt_AES(message_to_send, aes_key, aes_iv) socket_functions.socket_send(client_conn, encrypted_message_to_send) return SID
def send_message_1(client_socket): print("Sent 1st message.") client_temporary_cert = generate_cert_client() cert_to_send = crypto_lib.serialize_cert(client_temporary_cert) encrypted_cert_to_send = crypto_lib.encrypt_AES(cert_to_send, aes_key_merchant, aes_iv_merchant) encrypted_aes_key = crypto_lib.encrypt_RSA(aes_key_merchant, public_key_rsa_merchant) encrypted_aes_iv = crypto_lib.encrypt_RSA(aes_iv_merchant, public_key_rsa_merchant) message_to_send = socket_functions.concat_messages(encrypted_cert_to_send, encrypted_aes_key, encrypted_aes_iv) socket_functions.socket_send(client_socket, message_to_send) return client_temporary_cert
def send_message_4(pg_socket, PM, SID, amount, client_certificate, aes_key_client_PG_encrypted, aes_iv_client_PG_encrypted): print("Sent 4th message.") sigM = crypto_lib.sign( socket_functions.concat_messages( SID, crypto_lib.serialize_cert(client_certificate), amount), private_key_rsa) message_to_send = socket_functions.concat_messages( PM, sigM, aes_key_client_PG_encrypted, aes_iv_client_PG_encrypted) message_to_send = crypto_lib.encrypt_AES(message_to_send, aes_key_merchant_pg, aes_iv_merchant_pg) encrypted_aes_key_PG = crypto_lib.encrypt_RSA(aes_key_merchant_pg, public_key_rsa_pg) encrypted_aes_iv_PG = crypto_lib.encrypt_RSA(aes_iv_merchant_pg, public_key_rsa_pg) message_to_send = socket_functions.concat_messages(message_to_send, encrypted_aes_key_PG, encrypted_aes_iv_PG) socket_functions.socket_send(pg_socket, message_to_send)
def send_message_6(client_conn, Resp, aes_key_client_merchant, aes_iv_client_merchant): print("Sent 6th message.") message_to_send = crypto_lib.encrypt_AES(Resp, aes_key_client_merchant, aes_iv_client_merchant) socket_functions.socket_send(client_conn, message_to_send)