def check_invoice(signed_invoice): """Check if the configparser instance is a signed invoice. If not exit.""" seller_sign_key = os.path.join(os.path.join(tools.DIR_SELLER, tools.FILE_PUB_SIGN)) bank_pukf = os.path.join(tools.DIR_BANK, tools.FILE_PUB_KEY) pub_cp = tools.decode_public_key(seller_sign_key, bank_pukf, tools.ROLE_BANK) tools.check_config(pub_cp, tools.STRCT_PUB_KEY) pub_k = RSA(int(pub_cp[tools.SCT_K_KEY][tools.OPT_K_N]), e=int(pub_cp[tools.SCT_K_KEY][tools.OPT_K_E])) check = pub_k.check_signature(signed_invoice[tools.ROLE_SELLER][tools.OPT_S_SIGN]) tmp = open(tools.TMP_FILE, 'w') tmp.write(check) tmp.close() invoice_cp = ConfigParser() invoice_cp.read(tools.TMP_FILE) os.remove(tools.TMP_FILE) tools.check_config(invoice_cp, tools.STRCT_INVOICE) return invoice_cp
drawee_sign = decode_sign(seller_sign[tools.ROLE_SELLER][tools.OPT_S_SIGN], seller_puk) # Decode the cheque drawee = drawee_sign.sections()[0] drawee_puk_sing_fname = os.path.join(tools.DIR_CUSTOMERS, drawee, tools.FILE_PUB_SIGN) drawee_puk = tools.decode_public_key(drawee_puk_sing_fname, bank_prk_fname, tools.ROLE_BANK) drawee_puk = RSA(int(drawee_puk[tools.SCT_K_KEY][tools.OPT_K_N]), e=int(drawee_puk[tools.SCT_K_KEY][tools.OPT_K_E])) cheque = decode_sign(drawee_sign[drawee][tools.OPT_S_SIGN], drawee_puk) tools.check_config(cheque, tools.STRCT_CHEQUE) if check_pay_in(cheque): # the check are already pay in print(ALREADY_PAY_IN) exit(1) else: try: cashed_cheque(cheque) except KeyError: print(CUSTOMER_NOT_FOUND.format(drawee), file=sys.stderr) print(PAY_IN)