def main(): sg.theme("Black") # fmt: off layout = [[sg.Image( filename="", key="camera_image", )], [ sg.Multiline(font="Courier 12", size=(80, 10), key="output_window", autoscroll=True, auto_refresh=True, write_only=True, disabled=True, text_color="black") ]] # fmt: on window = sg.Window("Small demo in playground", layout, location=(800, 400), element_justification="c") SetInterval().initialize(window, 0.1) SetInterval().start() run = True # ---===--- Event LOOP Read and display frames, operate the GUI --- # while True: event, values = window.read(timeout=20) if event == sg.WIN_CLOSED: break elif event == "-SHOW MRZ-": window["camera_image"].update(data=values[event][0]) elif event == "-HIDE MRZ-": window["camera_image"].update(filename="", size=(320, 240)) elif event == "-RAISED EXCEPTION-": print("[!] Problem occured! Restarting...") run = True elif event == "-RESTART-": print("[!] Run completed! Restarting...") run = True elif event == "-PRINT-": window["output_window"].print(values[event]) if run: threading.Thread(target=program_logic, args=(window, ), daemon=True).start() run = False SetInterval().cancel() window.close()
# https://opensource.org/licenses/MIT """X509 certificate related functions""" from datetime import datetime from typing import Dict, Union from OpenSSL.crypto import ( X509, X509Store, X509StoreContext, X509StoreContextError, Error, ) from emrtd_face_access.print_to_sg import SetInterval print = SetInterval().print def is_self_signed(cert: X509) -> bool: """ Checks if a X509 certificate is self signed. """ store = X509Store() store.add_cert(cert) validfrom_time = cert.get_notBefore() validfrom_datetime = datetime.strptime(validfrom_time.decode("utf-8"), "%Y%m%d%H%M%SZ") store.set_time(validfrom_datetime) store_ctx = X509StoreContext(store, cert) try: store_ctx.verify_certificate()
def main_event_loop(): """ Main GUI event loop """ args = parse_arguments() layout = setup_gui(debug_on_gui=not args.no_debug) window = sg.Window( "eMRTD Face Access", layout, return_keyboard_events=True, use_default_focus=False, finalize=True, ) SetInterval().initialize(window, 0.1) SetInterval().start() db = None if args.db: db = TinyDB(args.db) first_run = True run = True everything_ok: bool q: Queue = Queue() q2: Queue = Queue() lock = threading.Lock() lock2 = threading.Lock() while True: if run: everything_ok = True threading.Thread( target=main, args=(window, args, db, q, q2, lock, lock2, first_run), daemon=True ).start() first_run = False run = False event, values = window.read() if event in (sg.WIN_CLOSED, "Exit"): break elif event == "-RUN COMPLETE-": if everything_ok: window["result"].update("ACCESS GRANTED", text_color="green") else: window["result"].update("ACCESS DENIED", text_color="red") run = True try_again(window) reset_gui(window, debug_on_gui=not args.no_debug) elif event == "-RAISED EXCEPTION-": everything_ok = False window["text_instruction"].update( "PROBLEM OCCURED (CHECK LOGS)! Press [Enter] to start over!", text_color="red" ) run = True try_again(window) reset_gui(window, debug_on_gui=not args.no_debug) elif event == "-SHOW CAMERA-": with lock: camera_mode(window, q, q2, lock2, event, values) elif event == "-SHOW MRZ-": window["camera_image"].update(data=values[event][0]) elif event == "-HIDE MRZ-": window["camera_image"].update(filename="", size=(320, 240)) elif event == "-SHOW ID IMAGE-": window["id_image"].update(data=values[event][0]) elif event == "-PROGRESS BAR-": window["progress"].update_bar(values[event][0], values[event][1]) elif (not args.no_debug) and event == "-PRINT-": window["output_window"].print(values[event]) elif ( event in values and isinstance(values[event], list) and isinstance(values[event][0], bool) ): window[values[event][1]].update(values[event][2], text_color=values[event][3]) if not values[event][0]: everything_ok = False SetInterval().cancel() window.close()
import PySimpleGUI as sg from smartcard.Exceptions import CardConnectionException from smartcard.util import toHexString from tinydb import TinyDB, Query from emrtd_face_access.apdu import APDU from emrtd_face_access.card_comms import send, wait_for_card, CardCommunicationError from emrtd_face_access.ocr import capture_mrz from emrtd_face_access.mrz import other_mrz, parse_mrz_text from emrtd_face_access.secure_messaging_object import SMObject from emrtd_face_access.bac import establish_bac_session_keys, SessionKeyEstablishmentError from emrtd_face_access.file_operations import EFReadError, read_data_from_ef, get_dg1_content from emrtd_face_access.byte_operations import nb from emrtd_face_access.print_to_sg import SetInterval print = SetInterval().print def parse_arguments() -> argparse.Namespace: """parse arguments""" parser = argparse.ArgumentParser( description="Build an allowed document database for emrtd_face_access" ) group = parser.add_mutually_exclusive_group(required=False) group.add_argument( "-add", dest="insert", action="store_true", help="(default) Add a card to the database" ) group.add_argument( "-delete", dest="insert", action="store_false", help="Remove a card from the database" )