Nitrokey 3 Firmware

repository·main·Indexed 18 days ago

https://github.com/nitrokey/nitrokey-3-firmware

Rust-based firmware for Nitrokey 3 USB security keys, built using the Trussed firmware framework in collaboration with SoloKeys. Includes documentation for building from source, flashing via mboot or lpc55-host, and debugging for lpc55 and nRF52/NK3AM hardware. Covers the Dispatch routing mechanism for backends and extensions, device configuration via the Config struct (FIDO, Opcard, PIV), and the Apps container for managing APDU and CTAP/HID command routing.

Tokens
27.8K
Snippets
99
Records
137
Agent score
44%

What's inside nitrokey-3-firmware

  1. Access Nitrokey 3 Test Certificates

    main

    The utils/test-certificates directory contains test certificates and keys used for simulating or testing Nitrokey 3 applications. These are categorized by their purpose (Root CA, FIDO, or Firmware signing) and provided in multiple formats (DER, PEM, and Trussed-compatible).

    Certificate Categories

    • Root CA: The Nitrokey 3 root CA (root).
    • FIDO Authenticator: Intermediate CA and End Entity (EE) certificates for the fido-authenticator application (fido).
    • LPC55 Firmware: Firmware signature keys for the LPC55 platform (firmware-lpc55), including one EE certificate signed by a root certificate and three standalone EE certificates.
    • NRF52 Firmware: Firmware signature keys for the NRF52 platform (firmware-nrf52).
  2. How fido-authenticator uses storage

    main

    The fido-authenticator application relies on the internal filesystem for its operational state and security credentials:

    • State, KEK, and Resident Keys: All stored on the internal filesystem.
    • Provisioning Data: The FIDO2 attestation key and certificate are stored on the internal filesystem during provisioning.
    • KEK Generation: The Key Encryption Key (KEK) is generated upon first use.

    Critical Note: There must be sufficient free space on the internal filesystem to generate the KEK. If space is insufficient, the application cannot be used.

  3. Understand Nitrokey 3 storage types and sizes

    main

    Nitrokey 3 utilizes three distinct storage types:

    1. Internal Storage: Uses on-chip flash memory. The available size depends on the hardware variant:
      • lpc55: 42 KiB
      • nrf52: 80 KiB
    2. External Storage: Uses a separate flash chip. While the chip capacity is 2 MiB, only 1920 KiB is available for littlefs2 usage, as the final 128 KiB is reserved for future use cases.
    3. Volatile Storage: Uses RAM.
  4. Build Nitrokey 3 firmware from source

    main

    To build the Nitrokey 3 firmware, ensure you have the following dependencies installed on your development system:

    • Rust: The current stable release must include the thumbv8m.main-none-eabi target and the llvm-tools-preview component.
    • Clang: Must be installed with development headers.
    • flip-link: A linker wrapper for stack overflow protection.
    • cargo-binutils: A collection of utilities for working with Rust binaries.
  5. Perform a full deployment of nRF52 / NK3AM

    main

    To execute a complete deployment cycle (building all components, flashing the bootloader, flashing the provisioner, provisioning keys, flashing the firmware, and running the full deployment sequence), follow these steps:

    1. Build all artifacts: make build
    2. Flash bootloader: make flash-bootloader
    3. Flash provisioner: make flash-provisioner
    4. Provision keys: make provision-keys
    5. Flash firmware: make flash-firmware
    6. Run full deploy: make full-deploy
    make build
    make flash-bootloader
    make flash-provisioner
    make provision-keys
    make flash-firmware
    make full-deploy
  6. Run SSH authentication tests

    main

    The SSH tests suite validates the interaction between a FIDO2 device and an OpenSSH server. It performs the following tasks:

    • Runs a preconfigured OpenSSH server based on Debian via Docker.
    • Generates FIDO2 device-based OpenSSH keys for multiple algorithms (ed25519-sk, ecdsa-sk) and storage types (resident and non-resident).
    • Executes connection tests using the generated FIDO2 device.

    Use the following Makefile commands to manage the test lifecycle.

    # Build the test environment
    make build
    
    # Run the SSH authentication tests
    make test
    
    # Clean up: remove generated keys and built images
    make clean
  7. View RTT (print) debugging outputs

    main

    To view real-time RTT (Real Time Transfer) logs, follow these steps in separate terminal windows:

    1. Flash the device using the nrf-builder: make -C ../nrf-builder flash-develop.
    2. In the first terminal, connect to the debugger: make ocd.
    3. In a second terminal, view the RTT outputs: make rtt.
    # Terminal 1: Flash and connect
    make -C ../nrf-builder flash-develop
    make ocd
    
    # Terminal 2: Show outputs
    make rtt