Ejemplo n.º 1
0
    def test_sign_small_string(self):
        """
        Test that we only accept a client with a signature from the bank
        """
        bankKey = Key.import_key_from_path("./cryptobank/test/functionalTests/keys/bank.key")
        bankKeyFalse = Key.import_key_from_path("./cryptobank/test/functionalTests/keys/bankFalse.key")
        signature = import_key("./cryptobank/test/functionalTests/keys/customer.signedkey")
        signature_false = import_key("./cryptobank/test/functionalTests/keys/customerFalse.signedkey")
        with open("./cryptobank/test/functionalTests/keys/customer.pubkey", "r") as file_:
            customer_key = file_.read()
        

        self.assertTrue(bankKey.verify(customer_key, signature))
        self.assertFalse(bankKey.verify(customer_key, signature_false))
Ejemplo n.º 2
0
def check_key(signed_key, bank_pubkey="bank.pubkey", customer_pubkey="customer.pubkey"):

    """
    Will check that the key passed as a parameter is correct
        - loads the bank's public key
        - opens the signature
        - opens the client's public key
        - checks the key again the signature
    """
    bank_key  = Key.import_key_from_path(bank_pubkey)
    signature = import_key(signed_key)
    with open(customer_pubkey, "r") as file_:
       customer_key = file_.read()
    if bank_key.verify(customer_key, signature):
        return True
    else:
        return False