#### If it's fine, the bank with cash the check and add #### #### the line to the right file #### ################################################################### from fileUtils import FileUtils from RSAtools import RSAtools import os.path import sys fileutils = FileUtils() rsatools = RSAtools() #Making sure the arguments and the files are there clientkey_file = open(sys.argv[2], 'r') merchantkey_file = open(sys.argv[3], 'r') #Getting client's key and merchant's original key clientkey_original = fileutils.recupKey(sys.argv[2]) merchant_key_original = fileutils.recupKey(sys.argv[3]) #Getting client's key ciphered by the bank and bank's private key clientkeybanqueciphered = [] clientkeybanqueciphered.append(fileutils.readKey(sys.argv[1],2)) clientkeybanqueciphered.append(fileutils.readKey(sys.argv[1],3)) bank_publickey = fileutils.recupKey('banquePk') #Deciphering the client's key clientkey_deciphered = [rsatools.decryptblock(bank_publickey, clientkeybanqueciphered[0]), rsatools.decryptblock(bank_publickey, clientkeybanqueciphered[1])] #Verification if( clientkey_deciphered != clientkey_original): print("La clé du client dans le chèque n'est pas la même que celle fournie !\n")
clientpk = open('clientPk','w') clientpk.write(str(rsaClient [0])+' '+str(rsaClient [1])) clientpk.close() clientsk = open('clientSk','w') clientsk.write(str(rsaClient [0])+' '+str(rsaClient [2])) clientsk.close() commercantpk = open('commercantPk','w') commercantpk.write(str(rsaCommercant [0])+' '+str(rsaCommercant [1])) commercantpk.close() commercantsk = open('commercantSk','w') commercantsk.write(str(rsaCommercant [0])+' '+str(rsaCommercant [2])) commercantsk.close() banquepk = open('banquePk','w') banquepk.write(str(rsaBanque [0])+' '+str(rsaBanque [1])) banquepk.close() banquesk = open('banqueSk','w') banquesk.write(str(rsaBanque [0])+' '+ str(rsaBanque [2])) banquesk.close() print([rsaClient [0],rsaClient[1]]) # Cryptage de la clé publique du client par la clé secrete de la banque # Test des fonctions de cryptage et decryptage par bloc clientpkencode = rsa.cryptblock(fileUtil.recupKey('banqueSk'), rsaClient [0]) clientpkdecode = rsa.decryptblock(fileUtil.recupKey('banquePk'), clientpkencode) clientpkencode2 = rsa.cryptblock(fileUtil.recupKey('banqueSk'), rsaClient [1]) clientpkdecode2 = rsa.decryptblock(fileUtil.recupKey('banquePk'), clientpkencode2) fileUtil.writeContent(fileUtil.formatKey(clientpkencode) + '\n' + fileUtil.formatKey(clientpkencode2), "clientPkEncode") print ([clientpkdecode,clientpkdecode2])
if( len(sys.argv) < 4 ): print("You need to put all of the arguments (invoice file, signed check and client's Pk)") sys.exit() # file opening try: invoice_file = open(sys.argv[1], 'r') signedcheck_file = open(sys.argv[2], 'r') except (OSError, IOError) as error: print("Error reading file : ", error) sys.exit() fileutils = FileUtils() rsatools = RSAtools() #Getting the infos from the files clepub_client = fileutils.recupKey(sys.argv[3]) facture = Facture(sys.argv[1]) clepub_merchant_original = fileutils.recupKey("commercantPk") bankPk = fileutils.recupKey("banquePk") merchantkeyclientciphered = [] clientkeybanqueciphered = [] merchantkeyclientciphered.append( fileutils.readKey(sys.argv[2],0)) merchantkeyclientciphered.append( fileutils.readKey(sys.argv[2],1)) clientkeybanqueciphered.append(fileutils.readKey(sys.argv[2],2)) clientkeybanqueciphered.append(fileutils.readKey(sys.argv[2],3)) uid_ciphered = fileutils.readKey(sys.argv[2],4)