Skip to content

Commit d500573

Browse files
authored
Merge pull request #64 from dgarske/keytools
Improvements to the key tools documentation
2 parents 9fc82ac + c473a53 commit d500573

4 files changed

Lines changed: 50 additions & 31 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
# automatically generated keys
4949
*.der
5050
*.pem
51+
*.sig
5152

5253
# automatically generated source files
5354
src/ed25519_pub_key.c
@@ -57,12 +58,13 @@ src/rsa4096_pub_key.c
5758

5859
# keygen binaries
5960
tools/keytools/sign
61+
tools/keytools/sign.exe
6062
tools/keytools/keygen
63+
tools/keytools/keygen.exe
6164

6265
# Vim swap files
6366
.*.swp
6467

65-
6668
# tags etc.
6769
cscope.out
6870
tags

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ factory.bin: $(BOOT_IMG) wolfboot-align.bin $(PRIVATE_KEY)
271271
@echo "\t[SIGN] $(BOOT_IMG)"
272272
$(Q)$(SIGN_TOOL) $(SIGN_OPTIONS) $(BOOT_IMG) $(PRIVATE_KEY) 1
273273
@echo "\t[MERGE] $@"
274-
@cat wolfboot-align.bin test-app/image_v1_signed.bin > $@
274+
$(Q)cat wolfboot-align.bin test-app/image_v1_signed.bin > $@
275275

276276
wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT) FORCE
277277
@echo "\t[LD] $@"

docs/Signing.md

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# wolfBoot Signing
1+
# wolfBoot Key Tools
22

3-
Instructions for setting up Python, wolfCrypt-py module and wolfBoot for firmware signing.
3+
Instructions for setting up Python, wolfCrypt-py module and wolfBoot for firmware signing and key generation.
44

5-
Note: There is a pure C signing tool available as well. See [C Signing Tool](#c-signing-tool) below.
5+
Note: There is a pure C version of the key tool available as well. See [C Key Tools](#c-key-tools) below.
66

77
## Install Python3
88

@@ -39,48 +39,65 @@ make config
3939
make
4040
```
4141

42-
## Signing Firmware
42+
## C Key Tools
4343

44-
1. Load the private key to use for signing into “./rsa4096.der”
45-
2. `python3 ./tools/keytools/sign.py --rsa4096 --sha3 test-app/image.bin rsa4096.der 1`
44+
A standalone C version of the keygen tools is available in: `./tools/keytools`.
4645

47-
Note: The last argument is the “version” number.
46+
These can be built in `tools/keytools` using `make` or from the wolfBoot root using `make keytools`.
4847

49-
## Signing Firmware with External Private Key (HSM)
48+
If the C version of the key tools exists they will be used by wolfBoot (the default is the Python scripts).
49+
50+
### Windows Visual Studio
5051

51-
I've tested this with separate signature and the correct public key, the two files are identical either if I do one step signing:
52+
Use the `wolfBootSignTool.vcxproj` Visual Studio project to build the `sign.exe` and `keygen.exe` tools for use on Windows.
5253

53-
```sh
54-
# Create file with Public Key
55-
openssl rsa -inform DER -outform DER -in rsa4096.der -out rsa4096_pub.der -pubout
5654

57-
# Generate Hash to Sign
58-
python3 ./tools/keytools/sign.py --rsa4096 --sha-only --sha3 test-app/image.bin rsa4096_pub.der 1
55+
## Command Line Usage
5956

60-
# Example for signing
61-
openssl rsautl -sign -keyform der -inkey rsa4096.der -in test-app/image_v1_digest.bin > test-app/image_v1.sig
57+
```sh
58+
./tools/keytools/keygen [--ed25519 | --ecc256 | --rsa2048 | --rsa4096 ] pub_key_file.c
59+
```
6260

63-
# Generate final signed binary
64-
python3 ./tools/keytools/sign.py --rsa4096 --sha3 --manual-sign test-app/image.bin rsa4096_pub.der 1 test-app/image_v1.sig
61+
```sh
62+
./tools/keytools/sign [--ed25519 | --ecc256 | --rsa2048 | --rsa4096 ] [--sha256 | --sha3] [--wolfboot-update] image key.der fw_version
63+
- or - ./tools/keytools/sign [--sha256 | --sha3] [--sha-only] [--wolfboot-update] image pub_key.der fw_version
64+
- or - ./tools/keytools/sign [--ed25519 | --ecc256 | --rsa2048 | --rsa4096 ] [--sha256 | --sha3] [--manual-sign] image pub_key.der fw_version signature.sig
6565
```
6666

67-
## C Signing Tool
67+
## Signing Firmware
6868

69-
A standalone C version of the signing tool is available here: `./tools/keytools/sign.c`. Build using `make keytools`
69+
1. Load the private key to use for signing into `./rsa2048.der`, `./rsa4096.der` or `./ed25519.der`.
70+
2. Run the signing tool with asymmetric algorithm, hash algorithm, file to sign, key and version.
7071

7172
```sh
72-
./tools/keytools/sign --rsa4096 --sha3 test-app/image.bin rsa4096.der 1
73+
./tools/keytools/sign --rsa2048 --sha256 test-app/image.bin rsa2048.der 1
74+
# OR
75+
python3 ./tools/keytools/sign.py --rsa2048 --sha256 test-app/image.bin rsa2048.der 1
7376
```
7477

75-
### Windows Visual Studio
78+
Note: The last argument is the “version” number.
7679

77-
Use the `wolfBootSignTool.vcxproj` Visual Studio project to build the `sign.exe` tool for use on Windows.
80+
## Signing Firmware with External Private Key (HSM)
7881

82+
Steps for manually signing firmware using an external key source.
7983

80-
## Command Line Usage
84+
```sh
85+
# Create file with Public Key
86+
openssl rsa -inform DER -outform DER -in rsa2048.der -out rsa2048_pub.der -pubout
8187

82-
```
83-
./tools/keytools/sign [--ed25519 | --ecc256 | --rsa2048 | --rsa4096 ] [--sha256 | --sha3] [--wolfboot-update] image key.der fw_version
84-
- or - ./tools/keytools/sign [--sha256 | --sha3] [--sha-only] [--wolfboot-update] image pub_key.der fw_version
85-
- or - ./tools/keytools/sign [--ed25519 | --ecc256 | --rsa2048 | --rsa4096 ] [--sha256 | --sha3] [--manual-sign] image pub_key.der fw_version signature.sig
88+
# Generate Hash to Sign
89+
./tools/keytools/sign --rsa2048 --sha-only --sha256 test-app/image.bin rsa2048_pub.der 1
90+
# OR
91+
python3 ./tools/keytools/sign.py --rsa2048 --sha-only --sha256 test-app/image.bin rsa4096_pub.der 1
92+
93+
# Sign hash Example (here is where you would use an HSM)
94+
openssl rsautl -sign -keyform der -inkey rsa2048.der -in test-app/image_v1_digest.bin > test-app/image_v1.sig
95+
96+
# Generate final signed binary
97+
./tools/keytools/sign --rsa2048 --sha256 --manual-sign test-app/image.bin rsa2048_pub.der 1 test-app/image_v1.sig
98+
# OR
99+
python3 ./tools/keytools/sign.py --rsa2048 --sha256 --manual-sign test-app/image.bin rsa4096_pub.der 1 test-app/image_v1.sig
100+
101+
# Combine into factory image
102+
cat wolfboot-align.bin test-app/image_v1_signed.bin > factory.bin
86103
```

tools/keytools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Signing Tool
1+
# Key Tools for signing and key generation
22

33
See documentation [here](../../docs/Signing.md).

0 commit comments

Comments
 (0)