How to use the bitbox02.Bootloader function in bitbox02

To help you get started, we’ve selected a few bitbox02 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digitalbitbox / bitbox02-firmware / py / load_firmware.py View on Github external
def _try_usart_bootloader_connection(
    serial_port: usart.SerialPort, bootloader_device: devices.DeviceInfo
) -> UsartBootloaderProbeResult:
    """
    Probes the connection to a BitBoxBase bootloader
    over the specified UART port.
    """
    transport = usart.U2FUsart(serial_port)
    try:
        bootloader_attempt = Bootloader(transport, bootloader_device)
        bootloader_attempt.versions()
        success = UsartBootloaderProbeResult.SUCCESS
    except usart.U2FUsartErrorResponse as err:
        if err.error_code != usart.U2FUsartErrorResponse.ENDPOINT_UNAVAILABLE:
            raise
        success = UsartBootloaderProbeResult.NOT_AVAILABLE
    except usart.U2FUsartTimeoutError:
        success = UsartBootloaderProbeResult.TIMEOUT
    finally:
        bootloader_attempt.close()
    return success
github digitalbitbox / bitbox02-firmware / py / send_message.py View on Github external
attestation_check_callback=attestation_check,
        )
        if debug:
            print("Device Info:")
            pprint.pprint(base_dev)
        return SendMessageBitBoxBase(base_dev, debug).run()
    except usart.U2FUsartErrorResponse as err:
        if err.error_code != usart.U2FUsartErrorResponse.ENDPOINT_UNAVAILABLE:
            raise
    except usart.U2FUsartTimeoutError:
        print("Timed out. Maybe the device is not connected?", file=sys.stderr)
        return 1

    print("BitBox unavailable. Starting bootloader connection.")
    transport = usart.U2FUsart(serial_port)
    bootloader = bitbox02.Bootloader(transport, bootloader_device)
    return SendMessageBootloader(bootloader).run()
github digitalbitbox / bitbox02-firmware / py / send_message.py View on Github external
except devices.TooManyFoundException:
        print("Multiple bitboxes detected. Only one supported")
        return 1
    except devices.NoneFoundException:
        try:
            bootloader = devices.get_any_bitbox02_bootloader()
        except devices.TooManyFoundException:
            print("Multiple bitbox bootloaders detected. Only one supported")
            return 1
        except devices.NoneFoundException:
            print("Neither bitbox nor bootloader found.")
            return 1
        else:
            hid_device = hid.device()
            hid_device.open_path(bootloader["path"])
            bootloader_connection = bitbox02.Bootloader(u2fhid.U2FHid(hid_device), bootloader)
            boot_app = SendMessageBootloader(bootloader_connection)
            return boot_app.run()
    else:

        def show_pairing(code: str) -> bool:
            print("Please compare and confirm the pairing code on your BitBox02:")
            print(code)
            return True

        def attestation_check(result: bool) -> None:
            if result:
                print("Device attestation PASSED")
            else:
                print("Device attestation FAILED")

        hid_device = hid.device()
github digitalbitbox / bitbox02-firmware / py / load_firmware.py View on Github external
)
    parser.add_argument("firmware", nargs=1, help="Firmware to flash.")
    args = parser.parse_args()

    if not args.debug and ".signed.bin" not in args.firmware[0]:
        eprint("Expecting firmware to end with '.signed.bin'")
        return 1

    if args.usart is not None:
        serial_port = usart.SerialPort(args.usart, 115200, timeout=3)
        bootloader_device = _find_and_open_usart_bitbox(serial_port)
        transport: TransportLayer = usart.U2FUsart(serial_port)
        bootloader = Bootloader(transport, bootloader_device)
    else:
        bootloader_device, transport = _find_and_open_usb_bitbox02()
    bootloader = Bootloader(transport, bootloader_device)

    with open(args.firmware[0], "rb") as file:
        firmware = file.read()

    def progress(perc: float) -> None:
        sys.stdout.write(f"{perc*100:.02f}%\r")

    if bootloader.erased():
        print("device contains NO firmware")
    else:
        print("firmware version: %d\nsigning pubkeys version: %d" % bootloader.versions())
        firmware_hash, signing_keydata_hash = bootloader.get_hashes()
        print("firmware hash:", firmware_hash.hex())
        print("signing keydata hash:", signing_keydata_hash.hex())

    if args.debug:
github digitalbitbox / bitbox02-firmware / py / load_firmware.py View on Github external
"--usart",
        action="store",
        help="Flash firmware using U2F-over-UART (BitBoxBase), with the specified serial port.",
    )
    parser.add_argument("firmware", nargs=1, help="Firmware to flash.")
    args = parser.parse_args()

    if not args.debug and ".signed.bin" not in args.firmware[0]:
        eprint("Expecting firmware to end with '.signed.bin'")
        return 1

    if args.usart is not None:
        serial_port = usart.SerialPort(args.usart, 115200, timeout=3)
        bootloader_device = _find_and_open_usart_bitbox(serial_port)
        transport: TransportLayer = usart.U2FUsart(serial_port)
        bootloader = Bootloader(transport, bootloader_device)
    else:
        bootloader_device, transport = _find_and_open_usb_bitbox02()
    bootloader = Bootloader(transport, bootloader_device)

    with open(args.firmware[0], "rb") as file:
        firmware = file.read()

    def progress(perc: float) -> None:
        sys.stdout.write(f"{perc*100:.02f}%\r")

    if bootloader.erased():
        print("device contains NO firmware")
    else:
        print("firmware version: %d\nsigning pubkeys version: %d" % bootloader.versions())
        firmware_hash, signing_keydata_hash = bootloader.get_hashes()
        print("firmware hash:", firmware_hash.hex())