A robust command-line utility for signing and verifying firmware binaries using the Ed25519 cryptographic algorithm. Designed for integrity verification in embedded systems and secure boot processes.
- Key Pair Generation: Securely generate Ed25519 signing (private) and public key pairs. Includes checks to prevent accidental overwrites of existing keys.
- Firmware Signing: Create Ed25519 signatures for binary firmware files.
- Signature Verification: Validate firmware binaries against their corresponding signatures and public keys.
- Flexible Path Handling: Supports explicit path specification for firmware, keys, and signatures, along with intelligent defaults.
- Dedicated Test Mode: Provides a specialized mode for managing and executing test scenarios within a structured directory layout.
To build and install ed25519-firmware-signer, you'll need the Rust programming language and its package manager, Cargo.
-
Clone the repository:
git clone https://github.com/your-username/ed25519-firmware-signer.git cd ed25519-firmware-signer -
Build the project:
cargo build --release
The compiled executable will be located at
target/release/binsign. -
Adding to PATH (Linux): For system-wide access, you can move the
binsignexecutable to a directory already included in your system'sPATH, such as/usr/local/bin.sudo mv target/release/binsign /usr/local/bin/
After moving, you should be able to run
binsignfrom any directory in your terminal. You can test this by typingbinsign --help.
binsign is a command-line tool with distinct operations (key generation, signing, verification) and arguments.
binsign [OPERATION_OPTIONS] [TEST_MODE_COMMAND]--gen-keys,-g: Generate a new Ed25519 key pair.--sign,-s: Sign a firmware binary.--verify,-v: Verify a firmware signature.
Unless explicitly specified with --path, --key, --keypath, or --signature_path, binsign looks for or saves files in the current working directory. If test mode is active, these defaults are relative to the specified test subdirectory.
- Private Key:
signing_key.bin - Public Key:
public_key.bin - Firmware Binary (in Test Mode):
test.bin(only in test mode, otherwise--pathis required). - Signature:
firmware.sig
Generates a new signing_key.bin (private) and public_key.bin in the base directory.
- Behavior:
- If no key files exist, new ones are generated normally.
- If only
signing_key.binexists (andpublic_key.binis missing),public_key.binwill be regenerated from the existing private key. - If both
signing_key.binandpublic_key.binexist, the tool will warn you and ask for confirmation before overwriting them, as old keys cannot be retrieved.
Example:
# Generate keys in the current directory
binsign -g
# Generate keys within 'test/test0' (requires test_mode feature)
# The 't' is an alias for 'test' subcommand.
cargo run --features test_mode -- -g t test0Signs a firmware binary using a private key and outputs a signature file.
- Firmware Binary:
- In normal mode, use
--path <firmware_binary_path>to specify the firmware to sign. - In test mode, if
--pathis omitted, it defaults totest.binwithin the test subdirectory.
- In normal mode, use
- Private Key:
- Use
--key <private_key_path>for a specific key. - If omitted, it defaults to
signing_key.binin the base directory. Ifsigning_key.bindoes not exist, a new key pair will be generated automatically before signing.
- Use
- Output Signature: By default, the signature is saved to
firmware.sigin the base directory.
Examples:
# Sign 'my_firmware.bin' in the current directory
# Requires 'signing_key.bin' to exist in the current directory or be automatically generated.
binsign -s --path my_firmware.bin
# Sign 'test.bin' within 'test/test0' using keys in that directory (requires test_mode feature)
# Assumes 'test/test0/test.bin' and 'test/test0/signing_key.bin' exist or will be generated.
cargo run --features test_mode -- -s t test0Verifies a firmware binary against its signature and a public key.
- Firmware Binary:
- In normal mode, use
--path <firmware_binary_path>. - In test mode, if
--pathis omitted, it defaults totest.binwithin the test subdirectory.
- In normal mode, use
- Signature:
- Use
--signature_path <signature_file_path>. - In test mode, if omitted, it defaults to
firmware.sigwithin the test subdirectory.
- Use
- Public Key:
- Use
--keypath <public_key_path>for a specific key. - If omitted, it defaults to
public_key.binin the base directory.
- Use
Examples:
# Verify 'my_firmware.bin' with 'firmware.sig' and 'public_key.bin' in the current directory
binsign -v --path my_firmware.bin --signature_path firmware.sig
# Verify 'test.bin' within 'test/test0' (requires test_mode feature)
# Assumes 'test/test0/test.bin', 'test/test0/firmware.sig', and 'test/test0/public_key.bin' exist.
cargo run --features test_mode -- -v t test0The test_mode feature (enabled during compilation via cargo run --features test_mode or cargo build --features test_mode) provides a convenient way to manage test scenarios. It sets the base directory for all file operations (keys, firmware, signatures) to test/<folder_name>.
- Activation: Activated by adding
test <folder_name>or its aliast <folder_name>after your main operation flag (-g,-s,-v). - Default Binary Name: When in test mode and signing (
-s) or verifying (-v), if--pathis omitted,binsignwill default to usingtest.bininside the specified test folder. - Implicit Key/Signature Paths: Key files (
signing_key.bin,public_key.bin) and signature files (firmware.sig) are also sought/saved within the specifiedtest/<folder_name>directory.
Example Usage (as shown above):
# Generate keys in test/my_project_test_case/
cargo run --features test_mode -- -g t my_project_test_case
# Sign the default 'test.bin' in test/my_project_test_case/
cargo run --features test_mode -- -s t my_project_test_case
# Verify the default files in test/my_project_test_case/
cargo run --features test_mode -- -v t my_project_test_case- Key Pair Integrity: Always ensure your private keys are stored securely. Compromise of a private key allows for unauthorized firmware signing.
- Public Key Distribution: The public key can be safely distributed with your firmware or embedded in devices to facilitate verification.
- Key Overwrite Warning: The
--gen-keysoperation now includes a confirmation prompt if existing keys are detected, preventing accidental loss of active keys.
Contributions are welcome! Please feel free to open issues or submit pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.