|
1 | | -# wolfBoot Signing |
| 1 | +# wolfBoot Key Tools |
2 | 2 |
|
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. |
4 | 4 |
|
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. |
6 | 6 |
|
7 | 7 | ## Install Python3 |
8 | 8 |
|
@@ -39,48 +39,65 @@ make config |
39 | 39 | make |
40 | 40 | ``` |
41 | 41 |
|
42 | | -## Signing Firmware |
| 42 | +## C Key Tools |
43 | 43 |
|
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`. |
46 | 45 |
|
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`. |
48 | 47 |
|
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 |
50 | 51 |
|
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. |
52 | 53 |
|
53 | | -```sh |
54 | | -# Create file with Public Key |
55 | | -openssl rsa -inform DER -outform DER -in rsa4096.der -out rsa4096_pub.der -pubout |
56 | 54 |
|
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 |
59 | 56 |
|
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 | +``` |
62 | 60 |
|
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 |
65 | 65 | ``` |
66 | 66 |
|
67 | | -## C Signing Tool |
| 67 | +## Signing Firmware |
68 | 68 |
|
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. |
70 | 71 |
|
71 | 72 | ```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 |
73 | 76 | ``` |
74 | 77 |
|
75 | | -### Windows Visual Studio |
| 78 | +Note: The last argument is the “version” number. |
76 | 79 |
|
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) |
78 | 81 |
|
| 82 | +Steps for manually signing firmware using an external key source. |
79 | 83 |
|
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 |
81 | 87 |
|
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 |
86 | 103 | ``` |
0 commit comments