From c383a8d72dc035d7e28de42a47714162957a67d5 Mon Sep 17 00:00:00 2001 From: Mykola Malkov Date: Mon, 2 Mar 2020 13:28:46 +0200 Subject: [PATCH] TT#54410 Get rid of hardcoded checksum of sipwise.gpg file We want to get rid of old sipwise gpg file as it contains weak key. To do it we need either update this hardcoded value (and do it every time when key is updated) or use the same behavior as it's used in installer. Change-Id: I4eba8a22cbc0b620b468fc133c07800d7f671cac --- templates/scripts/includes/deployment.sh | 31 +++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/templates/scripts/includes/deployment.sh b/templates/scripts/includes/deployment.sh index c8d148e..79e3410 100755 --- a/templates/scripts/includes/deployment.sh +++ b/templates/scripts/includes/deployment.sh @@ -93,8 +93,6 @@ VIRTUALBOX_DIR="/usr/share/virtualbox" VIRTUALBOX_ISO="VBoxGuestAdditions_5.1.26.iso" VIRTUALBOX_ISO_CHECKSUM="6df8c8ab6e7ac3a70a5e29116f8a5dcdb7dfbd0b226ef849a5cd9502e956b06f" # sha256 VIRTUALBOX_ISO_URL_PATH="/files/${VIRTUALBOX_ISO}" -SIPWISE_APT_KEY_CHECKSUM_OLD="f4cdbe4994ae8ca6c4b24eb164e82a20579b335da4eca0907ecaace832e9a0a7" # sha256 -SIPWISE_APT_KEY_CHECKSUM_NEW="c3b8271ec7cfd8debfd3ffcb1604a952cdf8c1033511e449684658c866eff6d8" # sha256 SIPWISE_APT_KEY_PATH="/etc/apt/trusted.gpg.d/sipwise.gpg" # overriden later, although since the checksum is the same we could use this URL # also for Pro/Carrier installations @@ -193,18 +191,29 @@ install_sipwise_key() { echo "Sipwise keyring not found, downloading." fi + local tmp_key + tmp_key="$(mktemp)" + for try in 1 2 3; do - wget --retry-connrefused --no-verbose -O "${SIPWISE_APT_KEY_PATH}" "${SIPWISE_URL}${SIPWISE_APT_KEY_URL_PATH}" - sipwise_key_checksum=$(sha256sum "${SIPWISE_APT_KEY_PATH}" | awk '{print $1}') - if [[ "${sipwise_key_checksum}" != "${SIPWISE_APT_KEY_CHECKSUM_OLD}" && \ - "${sipwise_key_checksum}" != "${SIPWISE_APT_KEY_CHECKSUM_NEW}" ]] ; then - echo "Sipwise keyring downloaded has wrong checksum (expected: [${SIPWISE_APT_KEY_CHECKSUM}] - got: [${sipwise_key_checksum}]), retry $try" >&2 - else - echo "Sipwise keyring downloaded with expected checksum (sha256sum: [${sipwise_key_checksum}]), debootstrap sipwise key" - debootstrap_sipwise_key - return + wget -q -T 10 --retry-connrefused --tries=3 --no-verbose -O "${tmp_key}" "${SIPWISE_URL}${SIPWISE_APT_KEY_URL_PATH}" + chmod 644 "${tmp_key}" + local sipwise_key_checksum + sipwise_key_checksum=$(sha256sum "${tmp_key}" | awk '{print $1}') + echo "Sipwise keyring downloaded with checksum (sha256sum: [${sipwise_key_checksum}]). Is it correct and should be imported into the system? [y/N]" + + if "${INTERACTIVE}"; then + local a + read -r a + if [[ "${a,,}" != "y" ]] ; then + echo "The key wasn't accepted, retrying... ${try}/3" + continue + fi fi + echo "The key has been accepted, installing it as /etc/apt/trusted.gpg.d/sipwise.gpg" + debootstrap_sipwise_key + mv "${tmp_key}" "${SIPWISE_APT_KEY_PATH}" + return done die "Error validating sipwise keyring for apt usage, aborting installation."