From 15cf5321137cb77ab88e19a5e317a5e82f401d24 Mon Sep 17 00:00:00 2001 From: Stadicus Date: Thu, 12 Dec 2019 13:22:49 +0100 Subject: [PATCH] add HSM version file / Redis key Because: * To check if the HSM firmware should be updated, the Base image needs to know the firmware version that it contains. * From the firmware file, only the versioning counter can be read directly, but to get this information from the HSM it would need to boot into the bootloader first, which is cumbersome. * Getting the semantic version from the HSM firmware (not bootloader) and decide whether to update is less complex. * The downgrade protection using the monotonic counter is still in place when actually updating the HSM firmware. This commit: * adds the file `config/version_hsm`, containing the semantiv version * renames the file `config/version` to `config/version_bbb` for consistency * stores the HSM firmware version in Redis key `hsm:firmware:version` during build * resets this Redis key from the file on every boot --- armbian/base/config/redis/factorysettings.txt | 2 ++ armbian/base/config/{version => version_bbb} | 0 armbian/base/config/version_hsm | 1 + armbian/base/customize-armbian-rockpro64.sh | 12 +++++++++--- armbian/base/scripts/systemd-startup-after-redis.sh | 7 +++++-- armbian/mender-convert.sh | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) rename armbian/base/config/{version => version_bbb} (100%) create mode 100644 armbian/base/config/version_hsm diff --git a/armbian/base/config/redis/factorysettings.txt b/armbian/base/config/redis/factorysettings.txt index effaff8d..3065986c 100644 --- a/armbian/base/config/redis/factorysettings.txt +++ b/armbian/base/config/redis/factorysettings.txt @@ -16,6 +16,8 @@ SET base:setup 0 ZADD base:descriptionCode 0 0 SET base:stateCode 0 +SET hsm:firmware:version xxx + SET middleware:passwordSetup 0 SET middleware:datadir /data/bbbmiddleware SET middleware:hsmserialport /dev/ttyS2 diff --git a/armbian/base/config/version b/armbian/base/config/version_bbb similarity index 100% rename from armbian/base/config/version rename to armbian/base/config/version_bbb diff --git a/armbian/base/config/version_hsm b/armbian/base/config/version_hsm new file mode 100644 index 00000000..fdc66988 --- /dev/null +++ b/armbian/base/config/version_hsm @@ -0,0 +1 @@ +4.4.0 diff --git a/armbian/base/customize-armbian-rockpro64.sh b/armbian/base/customize-armbian-rockpro64.sh index baf317fb..1fdb4035 100755 --- a/armbian/base/customize-armbian-rockpro64.sh +++ b/armbian/base/customize-armbian-rockpro64.sh @@ -34,13 +34,15 @@ set -e # CONFIG # ------------------------------------------------------------------------------ +# BitBoxBase and HSM version are set here: +# armbian/base/config/version_bbb +# armbian/base/config/version_hsm + BITCOIN_VERSION="0.18.1" LIGHTNING_VERSION="0.7.3" ELECTRS_VERSION="0.7.0" BIN_DEPS_TAG='0.0.5' -HSM_VERSION='4.3.0' - PROMETHEUS_VERSION="2.11.1" PROMETHEUS_CHKSUM="33b4763032e7934870721ca3155a8ae0be6ed590af5e91bf4d2d4133a79e4548" NODE_EXPORTER_VERSION="0.18.1" @@ -60,6 +62,7 @@ PRODUCTION IMAGE: ${BASE_PRODUCTION_IMAGE} ================================================================================ VERSIONS: BASE IMAGE ${BASE_VERSION} + HSM ${HSM_VERSION} BINARY DEPS ${BIN_DEPS_TAG} BITCOIN ${BITCOIN_VERSION} LIGHTNING ${LIGHTNING_VERSION} @@ -151,7 +154,9 @@ source /etc/os-release BASE_DISTRIBUTION=${VERSION_CODENAME} BASE_DISTRIBUTION=${BASE_DISTRIBUTION:-"bionic"} -BASE_VERSION=$(head -n1 /opt/shift/config/version) +BASE_VERSION=$(head -n1 /opt/shift/config/version_bbb) +HSM_VERSION=$(head -n1 /opt/shift/config/version_hsm) + BASE_BUILDMODE=${1:-"armbian-build"} # Source configuration to read BASE_PRODUCTION_IMAGE @@ -370,6 +375,7 @@ fi < /opt/shift/config/redis/factorysettings.txt sh /opt/shift/scripts/redis-pipe.sh | redis-cli --pipe redis-cli SET base:version "${BASE_VERSION}" +redis-cli SET hsm:firmware:version "${HSM_VERSION}" redis-cli SET build:date "$(date +%Y-%m-%d)" redis-cli SET build:time "$(date +%H:%M)" redis-cli SET build:commit "$(cat /opt/shift/config/latest_commit)" diff --git a/armbian/base/scripts/systemd-startup-after-redis.sh b/armbian/base/scripts/systemd-startup-after-redis.sh index 3674025d..b45d0be3 100755 --- a/armbian/base/scripts/systemd-startup-after-redis.sh +++ b/armbian/base/scripts/systemd-startup-after-redis.sh @@ -31,8 +31,11 @@ source /opt/shift/scripts/include/updateTorOnions.sh.inc redis_require # update hardcoded Base image version -VERSION=$(head -n1 /opt/shift/config/version) -redis_set "base:version" "${VERSION}" +VERSION_BBB=$(head -n1 /opt/shift/config/version_bbb) +redis_set "base:version" "${VERSION_BBB}" + +VERSION_HSM=$(head -n1 /opt/shift/config/version_hsm) +redis_set "base:version" "${VERSION_HSM}" # check for reset triggers on flashdrive diff --git a/armbian/mender-convert.sh b/armbian/mender-convert.sh index e9b40e35..92a57e5d 100755 --- a/armbian/mender-convert.sh +++ b/armbian/mender-convert.sh @@ -18,7 +18,7 @@ fi ACTION=${1:-"build"} SOURCE_NAME="BitBoxBase_Armbian_RockPro64" -VERSION="$(head -n1 base/config/version)" +VERSION="$(head -n1 base/config/version_bbb)" TEMP_NAME="BitBoxBase" TARGET_NAME="BitBoxBase-v${VERSION}-RockPro64"