Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example-setup: move generic functions to common file #188

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions example-setup/setup-full-ids
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
set -euo pipefail

trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
source "${dir}/utils.sh"
export PATH=${PATH}:${HOME}/go/bin

function abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

if [[ "$#" -ne 3 ]]; then
echo "Usage: ./setup-full-ids <cmc-folder> <data-folder> <cbor|json>"
exit 1
Expand Down
9 changes: 2 additions & 7 deletions example-setup/setup-full-simple
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
set -euo pipefail

trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
source "${dir}/utils.sh"
export PATH=${PATH}:${HOME}/go/bin

abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

if [[ "$#" -ne 3 ]]; then
echo "Usage: ./setup-full-simple <cmc-folder> <data-folder> <cbor|json>"
exit
Expand Down
21 changes: 9 additions & 12 deletions example-setup/sgx-setup-sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@
set -euo pipefail

trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
source "${dir}/utils.sh"
export PATH=${PATH}:${HOME}/go/bin

abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

if [[ "$#" -ne 3 ]]; then
echo "Usage: ./setup-full-simple <cmc-folder> <data-folder> <cbor|json>"
if [[ "$#" -ne 5 ]]; then
echo "Usage: ./setup-full-simple <cmc-folder> <data-folder> <cbor|json> <mrenclave> <mrsigner>"
exit
fi


cmc="$(abs_path "${1}")"
data="$(abs_path "${2}")"
ser="${3}"
mrenclave="${4}"
mrsigner="${5}"

if [[ ! -d "$cmc" ]]; then
echo "cmc directory does not exist. Did you clone the repository? Abort.."
exit 1
fi

if [[ ! -d "${data}" ]]; then
if [[ ! -d "${data}" ]]; then
mkdir -p "${data}"
fi

Expand Down Expand Up @@ -80,7 +77,7 @@ decoded=$(printf '%b' "$(echo "$cert_chain" | sed 's/SGX-PCK-Certificate-Issuer-
root_ca=$(echo -e "$decoded" | sed -n '/-----END CERTIFICATE-----/,$p' | sed '1d')
ca_fingerprint=$(openssl x509 -in <(echo "$root_ca") -noout -sha256 -fingerprint | awk -F= '{print $2}' | tr -d ': ' | tr '[:upper:]' '[:lower:]')

# GET TCB Info
# GET TCB Info
tcb_info="$(curl -s -X GET "https://api.trustedservices.intel.com/sgx/certification/v4/tcb?fmspc=$fmspc" | jq -c .)"
echo "$tcb_info" > "${data}/metadata-raw/tcb_info.json"

Expand All @@ -98,7 +95,7 @@ jq --argjson tcb_info "$tcb_info" --argjson qe_identity "$qe_identity" --argjson
"sgx": {
"version": 3,
"collateral": {
"teeType": 0,
"teeType": 0,
"tcbInfo": $tcb_info,
"tcbInfoSize": $tcb_info_size,
"qeIdentity": $qe_identity,
Expand Down
21 changes: 2 additions & 19 deletions example-setup/update-app-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@
set -euo pipefail

trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
source "${dir}/utils.sh"
export PATH=${PATH}:${HOME}/go/bin

abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

extendarr() {
local key=$1
shift
local param=$1

# Add new value
json="$(echo "${json}" | jq ".${key} += [${param}]")"
}

if [[ "$#" -ne 2 ]]; then
echo "Usage: ./update-app-manifest <data-folder> <cbor|json>"
exit 1
Expand All @@ -39,9 +25,6 @@ fi

echo "Using ${data} as directory for local data"

# Load manifest
json=$(cat "${data}/metadata-raw/app.manifest.json")

# Calculate the IMA app reference values
referenceValues=$(sudo calculate-ima-pcr -t 10 -i ima-ng -p /usr/bin)

Expand Down
16 changes: 0 additions & 16 deletions example-setup/update-app-manifest-live
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ set -euo pipefail
trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
export PATH=${PATH}:${HOME}/go/bin

abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

extendarr() {
local key=$1
shift
local param=$1

# Add new value
json="$(echo "${json}" | jq ".${key} += [${param}]")"
}

if [[ "$#" -ne 2 ]]; then
echo "Usage: ./update-app-manifest-live <data-folder> <cbor|json>"
exit 1
Expand Down
9 changes: 2 additions & 7 deletions example-setup/update-full-ids
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
set -euo pipefail

trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
source "${dir}/utils.sh"
export PATH=${PATH}:${HOME}/go/bin

function abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

if [[ "$#" -ne 2 ]]; then
echo "Usage: ./update-full-ids <data-folder> <cbor|json>"
exit 1
Expand Down
10 changes: 2 additions & 8 deletions example-setup/update-full-simple
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
set -euo pipefail

trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
source "${dir}/utils.sh"
export PATH=${PATH}:${HOME}/go/bin

abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}


if [[ "$#" -ne 2 ]]; then
echo "Usage: ./update-full-simple <data-folder> <cbor|json>"
exit 1
Expand Down
17 changes: 17 additions & 0 deletions example-setup/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

abs_path() {
if [[ -d "$(dirname "$1")" ]]
then
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" || true
fi
}

extendarr() {
local key=$1
shift
local param=$1

# Add new value
json="$(echo "${json}" | jq ".${key} += [${param}]")"
}
Loading