Skip to content

Commit

Permalink
Config file now optional for signed enclaves
Browse files Browse the repository at this point in the history
This replicates the behavior of the `oesign` tool. If a config file
is provided, the values in this file will override the properties
already written to the signed enclave binary.

See `oesign sign --help` for more details on that
  • Loading branch information
italo-sampaio committed Nov 22, 2024
1 parent e796dc1 commit 59faee7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions firmware/build/extract-mrenclave
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#! /usr/bin/env bash

function print_usage() {
echo "Usage: $0 <enclave_binary> <config_file>"
echo "Usage: $0 <signed_enclave> [config_file]"
echo " or $0 <unsigned_enclave> <config_file>"
echo ""
echo "Options:"
echo " enclave_binary: path of an enclave binary file."
echo " signed_enclave: path of a signed enclave binary file."
echo " unsigned_enclave: path of an unsigned enclave binary file."
echo " config_file: configuration file specifying the enclave properties."
echo " refer to the oesign sign --help for the list of properties."
echo " this option is only required for unsigned enclaves."
echo ""
echo "Description:"
echo " This script extracts the MRENCLAVE and the DIGEST values from the enclave"
Expand All @@ -17,14 +20,16 @@ function print_usage() {
echo " The MRENCLAVE and DIGEST are calculated from the signed enclave binary and"
echo " the enclave properties specified in the configuration file. Both values are"
echo " printed in hexadecimal format to stdout."
echo " If a configuration file is provided, the properties in the file will override"
echo " the properties that were already defined in the signed enclave binary."
echo ""
echo " Unsigned binaries:"
echo " The DIGEST is calculated from the unsigned enclave binary and the enclave"
echo " properties specified in the configuration file. The MRENCLAVE is set to zero."
echo " Both values are printed in hexadecimal format to stdout."
}

if [[ $# -lt 2 ]]; then
if [[ $# -lt 1 ]]; then
print_usage
exit 1
fi
Expand All @@ -42,15 +47,18 @@ ENCLAVE_BIN=$(realpath $1 --relative-to=$HSM_ROOT)
if [[ ! -f $ENCLAVE_BIN ]]; then
echo "Invalid signed enclave path: $ENCLAVE_BIN"
exit 1
else
ENCLAVE_ARG="-e $ENCLAVE_BIN"
fi
CONFIG_FILE=$(realpath $2 --relative-to=$HSM_ROOT)
if [[ ! -f $CONFIG_FILE ]]; then
echo "Invalid config file path: $CONFIG_FILE"
exit 1

if [[ $# -eq 1 ]]; then
CONFIG_ARG=""
else
CONFIG_ARG="-c $(realpath $2 --relative-to=$HSM_ROOT)"
fi

DIGEST_CMD="oesign digest -e $ENCLAVE_BIN -c $CONFIG_FILE -d /tmp/enclave_digest > /dev/null && hexdump -v -e '/1 \"%02x\"' /tmp/enclave_digest"
MRENCLAVE_CMD="oesign dump -e $ENCLAVE_BIN | grep mrenclave | cut -d '=' -f 2"
DIGEST_CMD="oesign digest $ENCLAVE_ARG $CONFIG_ARG -d /tmp/enclave_digest > /dev/null && hexdump -v -e '/1 \"%02x\"' /tmp/enclave_digest"
MRENCLAVE_CMD="oesign dump $ENCLAVE_ARG | grep mrenclave | cut -d '=' -f 2"
EXTRACT_CMD="\$SGX_ENVSETUP && echo digest: \$($DIGEST_CMD) && echo mrenclave: \$($MRENCLAVE_CMD)"

DOCKER_USER="$(id -u):$(id -g)"
Expand Down

0 comments on commit 59faee7

Please sign in to comment.