Exemplo n.º 1
0
def main(order_desc, amount):
    # initiate context and generate keys
    context = generate_context(order_desc, amount)
    generate_keys(context)

    # customer connection
    customer_conn, customer_addr = customer_connection()
    context['connections'].append(customer_conn)
    customer_conn.send(pickle.dumps(context['PubKM']))

    # payment gateway connection
    pg_conn, pg_addr = pg_connection()
    context['connections'].append(pg_conn)
    pg_conn.send(pickle.dumps(context['PubKM']))

    context['PubKPG'] = pickle.loads(receive_data(pg_conn))
    customer_conn.send(pickle.dumps(context['PubKPG']))
    print("PubKPG:", context['PubKPG'])
    print("Context:", context)

    # steps
    receiveCustomerPublicKey(context)
    generateTransactionSid(context)
    receiveTransactionInfo(context)
    sendTransactionInfoToPG(context)
    sendResponseFromPG(context)

    # close connections
    for conn in context['connections']:
        conn.close()
Exemplo n.º 2
0
def verifyPGResponse(context):
    response = receive_data(context['server'])
    data, aes_key_encryption = pickle.loads(response)

    aes_key = rsa.decrypt(aes_key_encryption, context['PrivK'])
    data, sig = aes_ecb_decrypt(data, aes_key)

    verify = rsa.verify(data, sig, context['PubKPG'])
    print("Decrypted response:", pickle.loads(data))
Exemplo n.º 3
0
def main(order_desc, amount):
    context = generate_context(order_desc, amount)
    generate_keys(context)

    context['server'] = server_connection()
    context['PubKM'] = pickle.loads(receive_data(context['server']))
    context['PubKPG'] = pickle.loads(receive_data(context['server']))

    print(context)
    time.sleep(1)

    # steps
    sendPublicKey(context)
    getTransactionSid(context)
    sendTransactionInfo(context)
    verifyPGResponse(context)

    # clean up
    context['server'].close()
Exemplo n.º 4
0
def receiveTransactionInfo(context):
    response = receive_data(context['connections'][0])
    data = pickle.loads(response)
    print(data)

    aes_key = rsa.decrypt(data[1], context['PrivK'])
    context['PM'] = aes_ecb_decrypt(data[0], aes_key)
    print(context['PM'])
    hash_to_check = rsa.verify(pickle.dumps(
        context['OI']), context['PM'][1], context['PubKC'])
Exemplo n.º 5
0
def sendResponseFromPG(context):
    response = receive_data(context['connections'][1])
    data, aes_key_encryption = pickle.loads(response)

    aes_key = rsa.decrypt(aes_key_encryption, context['PrivK'])
    response = aes_ecb_decrypt(data, aes_key)

    aes_key = os.urandom(16)
    data = aes_ecb_encrypt(pickle.dumps(response), aes_key)
    aes_key_encryption = rsa.encrypt(aes_key, context['PubKC'])
    context['connections'][0].send(pickle.dumps([data, aes_key_encryption]))
Exemplo n.º 6
0
def receiveCustomerPublicKey(context):
    response = receive_data(context['connections'][0])
    print('Public key received')
    # response = context['connections'][0].recv(1000)
    data = pickle.loads(response)

    aes_key = rsa.decrypt(data[0], context['PrivK'])
    PubKC = aes_ecb_decrypt(data[1], aes_key)

    # store customer's public key
    context['PubKC'] = PubKC
Exemplo n.º 7
0
def getTransactionSid(context):
    response = receive_data(context['server'])
    [aes_key_encryption, sid] = pickle.loads(response)

    aes_key = rsa.decrypt(aes_key_encryption, context['PrivK'])
    message_block = aes_ecb_decrypt(sid, aes_key)

    sid, digital_sig = message_block[0], message_block[1]
    print('Verifying RSA:', rsa.verify(sid, digital_sig, context['PubKM']))

    # store sid
    context['PI']['sid'] = sid
    context['OI']['sid'] = sid
Exemplo n.º 8
0
def main():
    context = {}
    generate_keys(context)

    context['server'] = server_connection()
    context['PubKM'] = pickle.loads(receive_data(context['server']))
    context['server'].send(pickle.dumps(context['PubKPG']))

    print('PubKM:', context['PubKM'])

    # steps
    receiveTransaction(context)
    sendResponse(context)

    context['server'].close()
Exemplo n.º 9
0
def receiveTransaction(context):
    response = receive_data(context['server'])
    data = pickle.loads(response)

    print(data)

    aes_key_encryption = data[1]
    aes_key = rsa.decrypt(aes_key_encryption, context['PrivK'])

    data = aes_ecb_decrypt(data[0], aes_key)
    context['PM'], context['PubKC'], merchant_sig = data
    context['PM'] = pickle.loads(context['PM'])
    context['Kcpg'] = rsa.decrypt(context['PM'][0], context['PrivK'])

    PM = aes_ecb_decrypt(context['PM'][1], context['Kcpg'])
    OI = pickle.dumps([PM[0]['Amount'], context['PubKC'], PM[0]['sid']])

    verify = rsa.verify(OI, merchant_sig, context['PubKM'])
    verify = rsa.verify(pickle.dumps(PM[0]), PM[1], context['PubKC'])

    context['response'] = checksum(verify)
    context['PM'] = PM[0]