Example #1
0
def sendResponse(context):
    context['DB'] = PLACEHOLDER
    if checkAuthorization() and checkDuplicate(context) and checkBalance(
            context) and context['response']:
        storeTransaction(
            [context['PM']['Amount']],
            [context['PM']['sid'], context['PM']['NonCPG'], context['PubKC']],
            DB)
    else:
        context['response'] = False
    print(context['response'])

    pg_sig = rsa.sign(
        pickle.dumps([
            context['response'], context['PM']['sid'], context['PM']['Amount'],
            context['PM']['NonCPG']
        ]), context['PrivK'], 'SHA-256')
    response = pickle.dumps([
        context['response'], context['PM']['sid'], context['PM']['Amount'],
        context['PM']['NonCPG']
    ])

    aes_key = os.urandom(16)
    data = aes_ecb_encrypt(pickle.dumps([response, pg_sig]), aes_key)
    aes_key_encryption = rsa.encrypt(aes_key, context['PubKM'])

    print('Sending data')
    print(context['server'].send(pickle.dumps([data, aes_key_encryption])))
Example #2
0
def sendTransactionInfo(context):
    oi_sig = rsa.sign(pickle.dumps(context['OI']), context['PrivK'], 'SHA-256')
    print("Transaction OI sig:", oi_sig)

    info_sig = rsa.sign(pickle.dumps(
        context['PI']), context['PrivK'], 'SHA-256')
    aes_key = os.urandom(16)

    info_encryption = aes_ecb_encrypt(
        pickle.dumps([context['PI'], info_sig]), aes_key)
    aes_key_encryption = rsa.encrypt(aes_key, context['PubKPG'])
    info_prepared = pickle.dumps([aes_key_encryption, info_encryption])

    aes_key = os.urandom(16)
    info = aes_ecb_encrypt(pickle.dumps([info_prepared, oi_sig]), aes_key)

    aes_key_encryption = rsa.encrypt(aes_key, context['PubKM'])
    context['server'].send(pickle.dumps([info, aes_key_encryption]))
Example #3
0
def sendPublicKey(context):
    aes_key = os.urandom(16)

    rsa_key_encryption = pickle.dumps(context['PubKC'])
    rsa_key_encryption = aes_ecb_encrypt(rsa_key_encryption, aes_key)

    aes_key_encryption = rsa.encrypt(aes_key, context['PubKM'])

    message = pickle.dumps([aes_key_encryption, rsa_key_encryption])
    # print('Sending public key', message)
    print(context['server'].send(message))
Example #4
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]))
Example #5
0
def sendTransactionInfoToPG(context):
    data = pickle.dumps(
        [context['OI']['Amount'], context['PubKC'], context['OI']['sid']])
    data_sig = rsa.sign(data, context['PrivK'], 'SHA-256')

    data = pickle.dumps([context['PM'][0], context['PubKC'], data_sig])

    aes_key = os.urandom(16)
    data = aes_ecb_encrypt(data, aes_key)

    aes_key_encryption = rsa.encrypt(aes_key, context['PubKPG'])

    print('Tickle my pickle:', pickle.dumps([data, aes_key_encryption]))
    context['connections'][1].send(pickle.dumps([data, aes_key_encryption]))
Example #6
0
def generateTransactionSid(context):
    sid = os.urandom(16)
    sid_sig = rsa.sign(sid, context['PrivK'], 'SHA-256')

    # store SID
    context['OI']['sid'] = sid

    aes_key = os.urandom(16)
    sid_prepared = aes_ecb_encrypt(pickle.dumps([sid, sid_sig]), aes_key)
    aes_key_encryption = rsa.encrypt(aes_key, context['PubKC'])

    print('Sending data', sid)
    context['connections'][0].send(
        pickle.dumps([aes_key_encryption, sid_prepared]))