Skip to content

Add RSA/ECC key loading, backup restore, backup passphrase, and firmware loading#86

Open
0c-coder wants to merge 2 commits intotrustcrypto:masterfrom
0c-coder:feature/rsa-load-and-restore
Open

Add RSA/ECC key loading, backup restore, backup passphrase, and firmware loading#86
0c-coder wants to merge 2 commits intotrustcrypto:masterfrom
0c-coder:feature/rsa-load-and-restore

Conversation

@0c-coder
Copy link

@0c-coder 0c-coder commented Mar 21, 2026

Summary

Port four features from the OnlyKey-App (JavaScript) to python-onlykey:

  • loadkey — Parse OpenPGP armored private keys (RSA 1024-4096, Ed25519, NIST P-256, secp256k1, Curve25519), extract key material (p/q for RSA, scalar s for ECC), and load onto the OnlyKey device. Supports auto-slot assignment (slot 99) matching the OnlyKey App behavior where signing and decryption subkeys are assigned to slots automatically.
  • restore — Parse OnlyKey backup files (base64-encoded with SHA256 hash verification), and send restore data to the device in 57-byte chunks using the OKRESTORE (0xF1) protocol message. Verifies backup file integrity before sending.
  • backuppassphrase — Set the backup encryption passphrase by computing its SHA256 hash and storing as a backup decryption key on slot 131 with type 161 (backup + decryption flags).
  • loadfirmware — Parse signed firmware files, transition the device from config mode to bootloader, and send firmware blocks in 57-byte chunks via the OKFWUPDATE (0xF4) protocol message with per-block signature verification and acknowledgment.

All four features are available as both CLI commands and interactive mode commands.

Usage

# Load a PGP key (auto-assign signing/decryption slots)
onlykey-cli loadkey mykey.asc

# Load to a specific slot with features
onlykey-cli loadkey mykey.asc RSA1 d

# Restore from backup
onlykey-cli restore onlykey-backup-2024-01-01T12-00.txt

# Set backup passphrase
onlykey-cli backuppassphrase

# Load firmware
onlykey-cli loadfirmware firmware-signed.txt

Test plan

  • Verify loadkey with RSA 2048/4096 PGP keys
  • Verify loadkey with Ed25519 PGP keys
  • Verify loadkey auto-slot assignment (slot 99)
  • Verify restore parses and verifies backup file SHA256 hash
  • Verify restore sends correct 57-byte chunks via OKRESTORE
  • Verify backuppassphrase rejects passphrases under 25 chars
  • Verify loadfirmware parses signed firmware file format
  • Verify loadfirmware transitions device to bootloader mode
  • Verify loadfirmware sends blocks with NEXT BLOCK acknowledgment
  • Verify all commands work in both CLI and interactive mode

T and others added 2 commits March 17, 2026 15:34
…ssphrase

Port three features from the OnlyKey-App (JavaScript) to python-onlykey:

1. loadkey - Parse OpenPGP armored private keys (RSA 1024-4096, Ed25519,
   NIST P-256, secp256k1, Curve25519), extract key material (p/q for RSA,
   scalar s for ECC), and load onto the OnlyKey device. Supports auto-slot
   assignment (slot 99) matching the OnlyKey App behavior where signing and
   decryption subkeys are assigned to slots automatically.

2. restore - Parse OnlyKey backup files (base64-encoded with SHA256 hash
   verification), and send restore data to the device in 57-byte chunks
   using the OKRESTORE (0xF1) protocol message. Verifies backup file
   integrity before sending.

3. backuppassphrase - Set the backup encryption passphrase by computing
   its SHA256 hash and storing as a backup decryption key on slot 131
   with type 161 (backup + decryption flags).

All three features are available as both CLI commands (onlykey-cli loadkey,
onlykey-cli restore, onlykey-cli backuppassphrase) and interactive mode
commands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port the firmware update feature from the OnlyKey-App to python-onlykey:

- Add OKFWUPDATE (0xF4) message type to Message enum
- Parse signed firmware files (-----BEGIN SIGNED FIRMWARE----- format)
- Transition device from config mode to bootloader via initial dummy packet
- Send firmware blocks in 57-byte chunks with per-chunk acknowledgment
- Wait for NEXT BLOCK between blocks and SUCCESSFULLY LOADED FW on completion
- Handle device reconnection after bootloader reboot
- Add loadfirmware CLI command with safety confirmation prompt
- Works in both command-line and interactive modes

Usage: onlykey-cli loadfirmware <firmware_file>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@0c-coder 0c-coder changed the title Add RSA/ECC key loading from PGP, backup restore, and backup passphrase Add RSA/ECC key loading, backup restore, backup passphrase, and firmware loading Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant