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
if database.has_option(drawee, transac_id): return True else: return False if __name__ == "__main__": bank_prk_fname = os.path.join(tools.DIR_BANK, tools.FILE_PUB_KEY) seller_puk_sing_fname = os.path.join(tools.DIR_BANK, tools.DIR_SELLER, tools.FILE_PUB_SIGN) seller_puk = tools.decode_public_key(seller_puk_sing_fname, bank_prk_fname, tools.ROLE_BANK) seller_puk = RSA(int(seller_puk[tools.SCT_K_KEY][tools.OPT_K_N]), e=int(seller_puk[tools.SCT_K_KEY][tools.OPT_K_E])) # Read the seller's signature from stdin and retreive the cheque's # signature generated by the drawee try: seller_sign = tools.read_stdin() except ParsingError: print(tools.SELLER_SIGN_ERROR, file=sys.stderr) exit(1) drawee_sign = decode_sign(seller_sign[tools.ROLE_SELLER][tools.OPT_S_SIGN], seller_puk)