Skip to content

Commit

Permalink
lxc-alpine: use SHA256 signature if available
Browse files Browse the repository at this point in the history
to verify apk.static

Signed-off-by: Kaarle Ritvanen <[email protected]>
  • Loading branch information
kunkku committed Dec 10, 2024
1 parent 4908667 commit f78b226
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions templates/lxc-alpine.in
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ fetch_apk_keys() {
cd - >/dev/null
}

find_keyfile() {
ls -1 "$1".alpine-*.pub 2>/dev/null | head -n 1
}

fetch_apk_static() {
local dest="$1"
local arch="$2"
Expand All @@ -222,10 +226,15 @@ fetch_apk_static() {
local apk=$dest/sbin/apk.static
[ -s "$apk" ] || die 2 'apk.static not found'

local sigprefix=$apk.SIGN.RSA.
local keyfile=$(ls -1 "$sigprefix"alpine-*.pub 2>/dev/null | head -n 1)
if ! openssl dgst -sha1 \
-verify "$APK_KEYS_DIR/${keyfile#$sigprefix}" \
local sigprefix=$apk.SIGN.RSA.sha256
local algorithm=sha256
if ! [ -s "$(find_keyfile "$sigprefix")" ]; then
sigprefix=${sigprefix%.*}
algorithm=sha1
fi
local keyfile=$(find_keyfile "$sigprefix")
if ! openssl dgst -$algorithm \
-verify "$APK_KEYS_DIR/${keyfile#$sigprefix.}" \
-signature "$keyfile" \
"$apk"; then

Expand Down

0 comments on commit f78b226

Please sign in to comment.