Exemplo n.º 1
0
def deposit(arguments):
    """
    Verify that the check has been signed by an authorised person
    Verify that the content of the check has not been altered
    Verify that the check has not been already cashed
    Store the check in the db
    """
    with open(arguments[0], "r") as file_:
        signed_check = unserialize(file_.readline())

    client_key = Key.import_key_from_path(arguments[1])
    bank_key = Key.import_key_from_path(arguments[2])
    # the signature of the check
    check_signature = signed_check["signature"]
    # the check encoded in base64
    base64_check = signed_check["base64_check"]
    # the check as a string
    dic_check = unserialize(base64_check)
    # the customer's signature (the one used to sign the check)
    customer_signature = dic_check["signature_customer_public_key"]
    data_signed_by_customer = create_data_to_sign(base64_check)
    # if the customer is part of the bank, the signature present in the check should be OK
    # check that the check has not already been cashed-in/altered in some way
    if verify_signature_check(client_key, check_signature, data_signed_by_customer):

        if verify_check_first(dic_check):
            print("This check has been cashed in")
            store_check(base64_check)
            exit(0)
        else:
            print("This check has already been cashed-in")
            exit(1)
    else:
        print("This check has been altered and connot be cashed in")
        exit(1)
Exemplo n.º 2
0
def verify_transaction(arguments, bank_pubkey="bank.pubkey", customer_pubkey="customer.pubkey"):
    """
    Checks that the customer's key is valid
    Import le check et le transform en dic
    Import la transaction d'origine et la transforme en dic
    Verifie que les informations dans le cheque sont les même qu'il a envoyé
    Si OK
        Verifie que la signature est valide
        Si OK : renvoie 0 sur la sortie standard
        Sinon : renvoie 1
    """
    if check_key(arguments[3], bank_pubkey, customer_pubkey) is False:
        print("The client has not got an account with the bank")
        exit(1)
    
    with open(arguments[0]) as file_:
        original_transaction = unserialize(file_.readline())
    with open(arguments[1]) as file_:
        signed_check = unserialize(file_.readline())
    
    #this is the check that the customer has signed
    signed_transaction = unserialize(signed_check["base64_check"])
    signature = signed_check["signature"]     
    client_key = Key.import_key_from_path(arguments[2]) 
    data_signed_by_customer = create_data_to_sign(signed_check["base64_check"])

# if the two checks match, we just have to check that the signature is ok.
    if signed_transaction == original_transaction:
        if client_key.verify(data_signed_by_customer, signature):
            exit(0)
        else:
            print("The signature does not appear to have been made by the client. Could there be Charly in the middle ? Better being safe than sorry... exiting")
            exit(1)
    else:
        print("the check the customer has signed is not the same as the one the merchant signed. Exiting")
        exit(1)