|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +set -e |
| 4 | + |
3 | 5 | function usage { |
4 | 6 | echo "Usage: ${0} <version/dir> <key_label> [--serialport PORT]" |
5 | 7 | } |
@@ -32,7 +34,8 @@ if [ -z "${VER_DIR}" -o -z "${KEY_LABEL}" ]; then |
32 | 34 | exit 1 |
33 | 35 | fi |
34 | 36 |
|
35 | | -WORKING_DIR="staging/${VER_DIR}/jade2.0" |
| 37 | +WORKING_DIR_PREFIX="staging/${VER_DIR}" |
| 38 | +HWDIRS="jade2.0" |
36 | 39 |
|
37 | 40 | # Can log if required |
38 | 41 | LOGGING="" |
@@ -61,71 +64,76 @@ HASH_OPTS="-sha256 -binary" |
61 | 64 | VERIFY_OPTS="-pubin -inkey ${PUBKEY} -pkeyopt digest:sha256 -pkeyopt rsa_padding_mode:pss" |
62 | 65 | JADE_SIGN_CMD="python ../../../../jade_bip85_rsa_sign.py ${JADE_SERIAL_ARG} ${LOGGING} ${CHECK_JADE_PUBKEY} --keylen ${KEYLEN} --index ${INDEX} --digest-files" |
63 | 66 |
|
64 | | -pushd "${WORKING_DIR}" |
| 67 | +for hwdir in ${HWDIRS}; do |
| 68 | + WORKING_DIR="${WORKING_DIR_PREFIX}/${hwdir}" |
65 | 69 |
|
66 | | -# Verify bootloaders are same |
67 | | -sha1=$(sha256sum "${BLEDIR}/bootloader/bootloader.bin" | cut -d\ -f1) |
68 | | -sha2=$(sha256sum "${NORADIODIR}/bootloader/bootloader.bin" | cut -d\ -f1) |
69 | | -if [ -z "${sha1}" -o -z "${sha2}" -o "${sha1}" != "${sha2}" ] |
70 | | -then |
71 | | - echo "Bootloaders missing or differ!" |
72 | | - popd |
73 | | - exit 2 |
74 | | -fi |
| 70 | + pushd "${WORKING_DIR}" |
75 | 71 |
|
76 | | -# Copy binaries that need signing |
77 | | -cp "${BLEDIR}/bootloader/bootloader.bin" "${FILE_PREFIX}_ble_bootloader.bin" |
78 | | -cp "${BLEDIR}/jade.bin" "${FILE_PREFIX}_ble_jade.bin" |
79 | | -cp "${NORADIODIR}/bootloader/bootloader.bin" "${FILE_PREFIX}_noradio_bootloader.bin" |
80 | | -cp "${NORADIODIR}/jade.bin" "${FILE_PREFIX}_noradio_jade.bin" |
81 | | - |
82 | | -# Hash the bootloaders and fws locally |
83 | | -HASH_FILES="" |
84 | | -for build in "ble" "noradio" |
85 | | -do |
86 | | - for program in "bootloader" "jade" |
87 | | - do |
88 | | - binary="${FILE_PREFIX}_${build}_${program}.bin" |
89 | | - hash_file="${FILE_PREFIX}_${build}_${program}.hash" |
90 | | - HASH_FILES="${HASH_FILES} ${hash_file}" |
| 72 | + # Verify bootloaders are same |
| 73 | + sha1=$(sha256sum "${BLEDIR}/bootloader/bootloader.bin" | cut -d\ -f1) |
| 74 | + sha2=$(sha256sum "${NORADIODIR}/bootloader/bootloader.bin" | cut -d\ -f1) |
| 75 | + if [ -z "${sha1}" -o -z "${sha2}" -o "${sha1}" != "${sha2}" ] |
| 76 | + then |
| 77 | + echo "Bootloaders missing or differ!" |
| 78 | + popd |
| 79 | + exit 2 |
| 80 | + fi |
| 81 | + |
| 82 | + # Copy binaries that need signing |
| 83 | + cp "${BLEDIR}/bootloader/bootloader.bin" "${FILE_PREFIX}_ble_bootloader.bin" |
| 84 | + cp "${BLEDIR}/jade.bin" "${FILE_PREFIX}_ble_jade.bin" |
| 85 | + cp "${NORADIODIR}/bootloader/bootloader.bin" "${FILE_PREFIX}_noradio_bootloader.bin" |
| 86 | + cp "${NORADIODIR}/jade.bin" "${FILE_PREFIX}_noradio_jade.bin" |
91 | 87 |
|
92 | | - openssl dgst ${HASH_OPTS} -out "${hash_file}" "${binary}" |
| 88 | + # Hash the bootloaders and fws locally |
| 89 | + HASH_FILES="" |
| 90 | + for build in "ble" "noradio" |
| 91 | + do |
| 92 | + for program in "bootloader" "jade" |
| 93 | + do |
| 94 | + binary="${FILE_PREFIX}_${build}_${program}.bin" |
| 95 | + hash_file="${FILE_PREFIX}_${build}_${program}.hash" |
| 96 | + HASH_FILES="${HASH_FILES} ${hash_file}" |
| 97 | + |
| 98 | + openssl dgst ${HASH_OPTS} -out "${hash_file}" "${binary}" |
| 99 | + done |
93 | 100 | done |
94 | | -done |
95 | 101 |
|
96 | | -# Sign the hashes with jade |
97 | | -echo "Please approve signing on your Jade device" |
98 | | -${JADE_SIGN_CMD} ${HASH_FILES} |
| 102 | + # Sign the hashes with jade |
| 103 | + echo "Please approve signing on your Jade device" |
| 104 | + ${JADE_SIGN_CMD} ${HASH_FILES} |
99 | 105 |
|
100 | | -# Check signatures with labeled pubkey, and rename if good |
101 | | -for build in "ble" "noradio" |
102 | | -do |
103 | | - for program in "bootloader" "jade" |
| 106 | + # Check signatures with labeled pubkey, and rename if good |
| 107 | + for build in "ble" "noradio" |
104 | 108 | do |
105 | | - hash_file="${FILE_PREFIX}_${build}_${program}.hash" |
106 | | - sig_file="${hash_file}.sig" |
107 | | - openssl pkeyutl -verify ${VERIFY_OPTS} -sigfile "${sig_file}" -in "${hash_file}" |
108 | | - if [ "${?}" -eq 0 ] |
109 | | - then |
110 | | - mv ${sig_file} "${FILE_PREFIX}_${build}_${program}.${SIG_SUFFIX}" |
111 | | - rm "${hash_file}" |
112 | | - else |
113 | | - echo "Signature verification of ${sig_file} over ${hash_file} with ${PUBKEY} failed" |
114 | | - fi |
| 109 | + for program in "bootloader" "jade" |
| 110 | + do |
| 111 | + hash_file="${FILE_PREFIX}_${build}_${program}.hash" |
| 112 | + sig_file="${hash_file}.sig" |
| 113 | + openssl pkeyutl -verify ${VERIFY_OPTS} -sigfile "${sig_file}" -in "${hash_file}" |
| 114 | + if [ "${?}" -eq 0 ] |
| 115 | + then |
| 116 | + mv ${sig_file} "${FILE_PREFIX}_${build}_${program}.${SIG_SUFFIX}" |
| 117 | + rm "${hash_file}" |
| 118 | + else |
| 119 | + echo "Signature verification of ${sig_file} over ${hash_file} with ${PUBKEY} failed" |
| 120 | + fi |
| 121 | + done |
115 | 122 | done |
116 | | -done |
117 | 123 |
|
118 | | -sha256sum *."${SIG_SUFFIX}" |
| 124 | + sha256sum *."${SIG_SUFFIX}" |
119 | 125 |
|
120 | | -# Verify jade pubkey matches expected (if feched) |
121 | | -if [ -n "${CHECK_JADE_PUBKEY}" ] |
122 | | -then |
123 | | - sha1=$(sha256sum "${PUBKEY}" | cut -d\ -f1) |
124 | | - sha2=$(sha256sum "${JADE_PUBKEY_FILE}" | cut -d\ -f1) |
125 | | - if [ -z "${sha1}" -o -z "${sha2}" -o "${sha1}" != "${sha2}" ] |
| 126 | + # Verify jade pubkey matches expected (if feched) |
| 127 | + if [ -n "${CHECK_JADE_PUBKEY}" ] |
126 | 128 | then |
127 | | - echo "Error: Pubkey pem mismatch!" |
| 129 | + sha1=$(sha256sum "${PUBKEY}" | cut -d\ -f1) |
| 130 | + sha2=$(sha256sum "${JADE_PUBKEY_FILE}" | cut -d\ -f1) |
| 131 | + if [ -z "${sha1}" -o -z "${sha2}" -o "${sha1}" != "${sha2}" ] |
| 132 | + then |
| 133 | + echo "Error: Pubkey pem mismatch!" |
| 134 | + fi |
128 | 135 | fi |
129 | | -fi |
130 | 136 |
|
131 | | -popd |
| 137 | + popd |
| 138 | + |
| 139 | +done |
0 commit comments