Skip to content

Commit

Permalink
Changes after code review
Browse files Browse the repository at this point in the history
- Script now works for both signed and unsigned binaries
- Added usage documentation
  • Loading branch information
italo-sampaio committed Nov 22, 2024
1 parent e9a7935 commit e796dc1
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions firmware/build/extract-mrenclave
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
#! /usr/bin/env bash

if [[ $# -ne 1 ]]; then
echo "Usage: $0 <signed_enclave>"
function print_usage() {
echo "Usage: $0 <enclave_binary> <config_file>"
echo ""
echo "Options:"
echo " enclave_binary: path of an 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 ""
echo "Description:"
echo " This script extracts the MRENCLAVE and the DIGEST values from the enclave"
echo " binary and prints them to stdout. The script can be used both for unsigned"
echo " and signed enclave binaries."
echo ""
echo " Signed binaries:"
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 ""
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
print_usage
exit 1
fi

Expand All @@ -19,8 +43,13 @@ if [[ ! -f $ENCLAVE_BIN ]]; then
echo "Invalid signed enclave path: $ENCLAVE_BIN"
exit 1
fi
CONFIG_FILE=$(realpath $2 --relative-to=$HSM_ROOT)
if [[ ! -f $CONFIG_FILE ]]; then
echo "Invalid config file path: $CONFIG_FILE"
exit 1
fi

DIGEST_CMD="oesign digest -e $ENCLAVE_BIN -d /tmp/enclave_digest > /dev/null && hexdump -v -e '/1 \"%02x\"' /tmp/enclave_digest"
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"
EXTRACT_CMD="\$SGX_ENVSETUP && echo digest: \$($DIGEST_CMD) && echo mrenclave: \$($MRENCLAVE_CMD)"

Expand Down

0 comments on commit e796dc1

Please sign in to comment.