mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 19:24:41 +00:00
30 lines
1.1 KiB
Bash
30 lines
1.1 KiB
Bash
# Resolve symlinks so the key is provisioned outside every receipt directory.
|
|
check_restore_key_location() {
|
|
local key receipt_dir directory
|
|
key="$(realpath -e -- "$1")" || return 78
|
|
shift
|
|
for receipt_dir in "$@"; do
|
|
directory="$(realpath -m -- "$receipt_dir")" || return 78
|
|
if [[ "$key" == "${directory%/}/"* ]]; then
|
|
echo "RESTORE_RECEIPT_VERIFY_KEY must be provisioned outside the receipt directory" >&2
|
|
return 78
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Both callers enable pipefail. Print the normalized pin for the signed receipt.
|
|
verify_restore_key_fingerprint() {
|
|
local key="$1" expected="${2#sha256:}" actual
|
|
expected="${expected,,}"
|
|
if ! [[ "$expected" =~ ^[a-f0-9]{64}$ ]]; then
|
|
echo "RESTORE_RECEIPT_VERIFY_KEY_SHA256 must be a sha256 fingerprint of 64 hex characters" >&2
|
|
return 78
|
|
fi
|
|
actual="$(openssl pkey -pubin -in "$key" -outform DER | sha256sum)" || return 78
|
|
if [[ "${actual%% *}" != "$expected" ]]; then
|
|
echo "restore receipt verify key does not match RESTORE_RECEIPT_VERIFY_KEY_SHA256" >&2
|
|
return 78
|
|
fi
|
|
printf '%s\n' "$expected"
|
|
}
|