コード例 #1
0
 async def main(self):
     buttons = [
         (1, "Wipe the device storage"),
         (2, "Configure QR code scanner"),
         (3, "Scan something"),
         (4, "Test smartcard"),
     ]
     while True:
         res = await self.gui.menu(buttons,
                     title="Factory test, version %s" % get_version(),
                     note="This firmware is used to test electrical connections between the discovery board and other components.\nIt can also erase the content of the internal storage\n(factory reset).")
         if res == 1:
             conf = await self.gui.prompt("Wipe the device?",
                     "This will delete everything from internal storage.")
             if conf:
                 await self.wipe()
         elif res == 2:
             if self.qr is None:
                 self.qr = QRHost(self.rampath+"/qr")
                 self.qr.init()
                 self.qr.start(self)
             if self.qr.is_configured:
                 await self.gui.alert("Success!", "QR code scanner is configured")
             else:
                 await self.gui.alert("Fail...", "Something went wrong. Maybe reboot and try again...")
         elif res == 3:
             if self.qr is None:
                 self.qr = QRHost(self.rampath+"/qr")
                 self.qr.init()
                 self.qr.start(self)
             await self.qr.enable()
             s = await self.qr.get_data()
             if s:
                 data = s.read().decode()
                 await self.gui.alert("Here's what we scanned:", data)
         else:
             conn = get_connection()
             if not conn.isCardInserted():
                 await self.gui.alert("Card is not present!",
                     "Smartcard is not inserted")
             else:
                 try:
                     conn.connect(conn.T1_protocol)
                 except:
                     pass
                 try:
                     app = MemoryCardApplet(conn)
                     app.open_secure_channel()
                     print(app.get_pin_status())
                     if app.is_pin_set:
                         await self.gui.alert("Smartcard works!", "Pin is set")
                     else:
                         await self.gui.alert("Smartcard works!", "Pin is not set")
                 except Exception as e:
                     await self.gui.alert("Something went wrong...",
                         "We got an exception: %r" % e)
         await asyncio.sleep_ms(30)
コード例 #2
0
def main(apps=None, network='test'):
    # create virtual file system /sdram
    # for temp untrusted data storage
    rampath = platform.mount_sdram()
    # define hosts - USB, QR, SDCard
    # each hosts gets it's own RAM folder for data
    hosts = [
        QRHost(rampath + "/qr"),
        USBHost(rampath + "/usb"),
        # SDHost(rampath+"/sd"), # not implemented yet
    ]
    # define GUI
    gui = SpecterGUI()

    # folder where keystore will store it's data
    keystore_path = platform.fpath("/flash/keystore")
    # define KeyStore
    keystore = FlashKeyStore(keystore_path)

    # loading apps
    if apps is None:
        apps = load_apps()

    # make Specter instance
    settings_path = platform.fpath("/flash")
    specter = Specter(gui=gui,
                      keystore=keystore,
                      hosts=hosts,
                      apps=apps,
                      settings_path=settings_path,
                      network=network)
    specter.start()
コード例 #3
0
ファイル: main.py プロジェクト: stepansnigirev/specter-diy
def main(apps=None, network="main", keystore_cls=None):
    """
    apps: list of apps to load
    network: default network to operate
    keystores: list of KeyStore classes that can be used
    """
    # create virtual file system /sdram
    # for temp untrusted data storage
    rampath = platform.mount_sdram()
    # define hosts - USB, QR, SDCard
    # each hosts gets it's own RAM folder for data
    Host.SETTINGS_DIR = platform.fpath("/qspi/hosts")
    hosts = [
        USBHost(rampath + "/usb"),
        QRHost(rampath + "/qr"),
        SDHost(rampath + "/sd"),
    ]
    # temp storage in RAM for host commands processing
    BaseApp.TEMPDIR = rampath + "/tmp"

    # define GUI
    if not platform.simulator:
        gui = SpecterGUI()
    else:
        # this GUI can simulate user actions for automated testing
        from gui.tcp_gui import TCPGUI
        gui = TCPGUI()

    # inject the folder where keystore stores it's data
    KeyStore.path = platform.fpath("/flash/keystore")
    # detect keystore to use
    if keystore_cls is not None:
        keystores = [keystore_cls]
    else:
        keystores = [
            MemoryCard,
            SDKeyStore,
        ]

    # loading apps
    if apps is None:
        apps = load_apps()

    # make Specter instance
    settings_path = platform.fpath("/flash")
    specter = Specter(
        gui=gui,
        keystores=keystores,
        hosts=hosts,
        apps=apps,
        settings_path=settings_path,
        network=network,
    )
    specter.start()
コード例 #4
0
ファイル: main.py プロジェクト: holgern/specter-diy
def main(apps=None, network="test", keystore_cls=None):
    """
    apps: list of apps to load
    network: default network to operate
    keystores: list of KeyStore classes that can be used
    """
    # create virtual file system /sdram
    # for temp untrusted data storage
    rampath = platform.mount_sdram()
    # define hosts - USB, QR, SDCard
    # each hosts gets it's own RAM folder for data
    hosts = [
        QRHost(rampath + "/qr"),
        USBHost(rampath + "/usb"),
        # SDHost(rampath+"/sd"), # not implemented yet
    ]
    # define GUI
    gui = SpecterGUI()

    # inject the folder where keystore stores it's data
    KeyStore.path = platform.fpath("/flash/keystore")
    # detect keystore to use
    if keystore_cls is not None:
        keystores = [keystore_cls]
    else:
        keystores = [
            SDKeyStore,
            # uncomment this if you want to
            # enable smartcard support:
            # MemoryCard,
        ]

    # loading apps
    if apps is None:
        apps = load_apps()

    # make Specter instance
    settings_path = platform.fpath("/flash")
    specter = Specter(
        gui=gui,
        keystores=keystores,
        hosts=hosts,
        apps=apps,
        settings_path=settings_path,
        network=network,
    )
    specter.start()
コード例 #5
0
class HardwareTest:
    def __init__(self):
        self.rampath = mount_sdram()
        self.gui = SpecterGUI()
        Screen.COLORS["none"] = lv.color_hex(0xeeeeee)
        Screen.network = "none"
        self.qr = None

    def start(self):
        self.gui.start(dark=False)
        asyncio.run(self.main())

    async def main(self):
        buttons = [
            (1, "Wipe the device storage"),
            (2, "Configure QR code scanner"),
            (3, "Scan something"),
            (4, "Test smartcard"),
        ]
        while True:
            res = await self.gui.menu(buttons,
                        title="Factory test, version %s" % get_version(),
                        note="This firmware is used to test electrical connections between the discovery board and other components.\nIt can also erase the content of the internal storage\n(factory reset).")
            if res == 1:
                conf = await self.gui.prompt("Wipe the device?",
                        "This will delete everything from internal storage.")
                if conf:
                    await self.wipe()
            elif res == 2:
                if self.qr is None:
                    self.qr = QRHost(self.rampath+"/qr")
                    self.qr.init()
                    self.qr.start(self)
                if self.qr.is_configured:
                    await self.gui.alert("Success!", "QR code scanner is configured")
                else:
                    await self.gui.alert("Fail...", "Something went wrong. Maybe reboot and try again...")
            elif res == 3:
                if self.qr is None:
                    self.qr = QRHost(self.rampath+"/qr")
                    self.qr.init()
                    self.qr.start(self)
                await self.qr.enable()
                s = await self.qr.get_data()
                if s:
                    data = s.read().decode()
                    await self.gui.alert("Here's what we scanned:", data)
            else:
                conn = get_connection()
                if not conn.isCardInserted():
                    await self.gui.alert("Card is not present!",
                        "Smartcard is not inserted")
                else:
                    try:
                        conn.connect(conn.T1_protocol)
                    except:
                        pass
                    try:
                        app = MemoryCardApplet(conn)
                        app.open_secure_channel()
                        print(app.get_pin_status())
                        if app.is_pin_set:
                            await self.gui.alert("Smartcard works!", "Pin is set")
                        else:
                            await self.gui.alert("Smartcard works!", "Pin is not set")
                    except Exception as e:
                        await self.gui.alert("Something went wrong...",
                            "We got an exception: %r" % e)
            await asyncio.sleep_ms(30)

    async def host_exception_handler(self, e):
        pass

    async def wipe(self):
        try:
            delete_recursively(fpath("/flash"))
            delete_recursively(fpath("/qspi"))
            await self.gui.alert("Success!", "All the content is deleted.")
        except Exception as e:
            await self.gui.alert("Fail!", "Something bad happened:\n"+str(e))
コード例 #6
0
 async def main(self):
     buttons = [
         (1, "Wipe the device storage"),
         (2, "Configure QR code scanner"),
         (3, "Scan something"),
         (4, "Test smartcard"),
     ]
     while True:
         res = await self.gui.menu(
             buttons,
             title="Factory test",
             note=
             "This firmware is used to test electrical connections between the discovery board and other components.\nIt can also erase the content of the internal storage\n(factory reset)."
         )
         if res == 1:
             conf = await self.gui.prompt(
                 "Wipe the device?",
                 "This will delete everything from internal storage.")
             if conf:
                 await self.wipe()
         elif res == 2:
             if self.qr is None:
                 self.qr = QRHost(self.rampath + "/qr")
                 self.qr.init()
                 self.qr.start(self)
             if self.qr.is_configured:
                 await self.gui.alert("Success!",
                                      "QR code scanner is configured")
             else:
                 await self.gui.alert(
                     "Fail...",
                     "Something went wrong. Maybe reboot and try again...")
         elif res == 3:
             if self.qr is None:
                 self.qr = QRHost(self.rampath + "/qr")
                 self.qr.init()
                 self.qr.start(self)
             await self.qr.enable()
             s = await self.qr.get_data()
             if s:
                 data = s.read().decode()
                 await self.gui.alert("Here's what we scanned:", data)
         else:
             conn = get_connection()
             if not conn.isCardInserted():
                 await self.gui.alert("Card is not present!",
                                      "Smartcard is not inserted")
             else:
                 try:
                     conn.connect(conn.T1_protocol)
                 except:
                     pass
                 try:
                     res = conn.transmit(
                         b"\x00\xA4\x04\x00\x06\xB0\x0B\x51\x11\xCB\x01")
                     if len(res) > 0:
                         await self.gui.alert(
                             "Smartcard works!",
                             "We got something from the card!")
                     else:
                         await self.gui.alert(
                             "Fail...",
                             "We didn't get any data from the card :(")
                 except Exception as e:
                     await self.gui.alert("Something went wrong...",
                                          "We got an exception:" + str(e))
         await asyncio.sleep_ms(30)