-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resin-init-flasher: with secure boot, authenticate the inner image
At this moment resin-init-flasher just takes whatever image lies in /opt and dd's it to the target drive. This is fine for general use, but with secure boot enabled, we want to perform at least basic authentication of the image being written. This patch gets the image signed at build time and makes flasher verify the signature against a key built-in the kernel trust store. At this very moment it fails hard if the signature does not match, but this may change in the future. Technically we only want to know if we are about to flash a balena-provided image or not, we might want to support both but behave slightly differently in each scenario. Change-type: minor Signed-off-by: Michal Toman <[email protected]>
- Loading branch information
Showing
4 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
do_sign_digest () { | ||
if [ "x${SIGN_API}" = "x" ]; then | ||
bbnote "Signing API not defined" | ||
return 0 | ||
fi | ||
if [ "x${SIGN_API_KEY}" = "x" ]; then | ||
bbfatal "Signing API key must be defined" | ||
fi | ||
|
||
for SIGNING_ARTIFACT in ${SIGNING_ARTIFACTS} | ||
do | ||
if [ -z "${SIGNING_ARTIFACT}" ] || [ ! -f "${SIGNING_ARTIFACT}" ]; then | ||
bbfatal "Nothing to sign" | ||
fi | ||
|
||
DIGEST=$(openssl dgst -hex -sha256 "${SIGNING_ARTIFACT}" | awk '{print $2}') | ||
|
||
REQUEST_FILE=$(mktemp) | ||
RESPONSE_FILE=$(mktemp) | ||
echo "{\"cert_id\": \"${SIGN_KMOD_KEY_ID}\", \"digest\": \"${DIGEST}\"}" > "${REQUEST_FILE}" | ||
CURL_CA_BUNDLE="${STAGING_DIR_NATIVE}/etc/ssl/certs/ca-certificates.crt" curl --retry 5 --fail --silent "${SIGN_API}/cert/sign" -X POST -H "Content-Type: application/json" -H "X-API-Key: ${SIGN_API_KEY}" -d "@${REQUEST_FILE}" > "${RESPONSE_FILE}" | ||
jq -r ".signature" < "${RESPONSE_FILE}" | base64 -d > "${SIGNING_ARTIFACT}.sig" | ||
rm -f "${REQUEST_FILE}" "${RESPONSE_FILE}" | ||
done | ||
} | ||
|
||
do_sign_digest[network] = "1" | ||
do_sign_digest[depends] += " \ | ||
openssl-native:do_populate_sysroot \ | ||
curl-native:do_populate_sysroot \ | ||
jq-native:do_populate_sysroot \ | ||
ca-certificates-native:do_populate_sysroot \ | ||
coreutils-native:do_populate_sysroot \ | ||
gnupg-native:do_populate_sysroot \ | ||
" | ||
|
||
do_sign_digest[vardeps] += " \ | ||
SIGN_API \ | ||
SIGN_KMOD_KEY_ID \ | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters