2022-10-18 10:23:00 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) Edgeless Systems GmbH
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
# This script contains shared functions for pcr calculation.
|
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
set -euo pipefail
|
|
|
|
shopt -s inherit_errexit
|
|
|
|
|
2022-10-18 10:23:00 -04:00
|
|
|
pcr_extend() {
|
2022-11-10 08:17:04 -05:00
|
|
|
local CURRENT_PCR="$1"
|
|
|
|
local EXTEND_WITH="$2"
|
|
|
|
local HASH_FUNCTION="$3"
|
|
|
|
(
|
|
|
|
echo -n "${CURRENT_PCR}" | xxd -r -p
|
|
|
|
echo -n "${EXTEND_WITH}" | xxd -r -p
|
|
|
|
) | ${HASH_FUNCTION} | cut -d " " -f 1
|
2022-10-18 10:23:00 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 08:17:04 -05:00
|
|
|
extract() {
|
|
|
|
local image="$1"
|
|
|
|
local path="$2"
|
|
|
|
local output="$3"
|
|
|
|
sudo systemd-dissect --copy-from "${image}" "${path}" "${output}"
|
2022-10-18 10:23:00 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 08:17:04 -05:00
|
|
|
mktempdir() {
|
|
|
|
mktemp -d
|
2022-10-18 10:23:00 -04:00
|
|
|
}
|
|
|
|
|
2022-11-10 08:17:04 -05:00
|
|
|
cleanup() {
|
|
|
|
local dir="$1"
|
|
|
|
rm -rf "${dir}"
|
2022-10-18 10:23:00 -04:00
|
|
|
}
|