From a6a43e58ebc5c465678671ea30297b0acbb6efce Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Thu, 11 Feb 2021 20:11:26 +0000 Subject: [PATCH] Add MRENCLAVE verification Related issue: #64 --- Makefile.am | 16 +++--- Makefile.in | 44 ++++++++------- configure | 14 ++--- configure.ac | 4 +- enclave_verify.c | 22 ++++++-- enclave_verify.h | 5 +- policy.in | 7 ++- run.in | 1 + mrsigner.c => sigstruct.c | 94 +++++++++++++++++++++---------- mrsigner.sh.in => sigstruct.sh.in | 2 +- sp.cpp | 37 ++++++++++-- 11 files changed, 164 insertions(+), 82 deletions(-) rename mrsigner.c => sigstruct.c (50%) rename mrsigner.sh.in => sigstruct.sh.in (93%) diff --git a/Makefile.am b/Makefile.am index a66b15d..1688a7f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,7 +63,7 @@ CLEANFILES = Enclave_u.c Enclave_u.h Enclave.edl Enclave.signed.so \ server: sp -bin_PROGRAMS = client sp mrsigner +bin_PROGRAMS = client sp sigstruct ## You can't use $(wildcard ...) with automake so all source files ## have to be explicitly listed. @@ -90,18 +90,20 @@ if AGENT_CURL sp_SOURCES += agent_curl.cpp endif -## mrsigner (helper app) +## sigstruct (helper app) -mrsigner_SOURCES = mrsigner.cpp crypto.c hexutil.c +sigstruct_SOURCES = sigstruct.cpp crypto.c hexutil.c ## Extract the enclave SIGSTRUCT and use it to calculate MRSIGNER -policy: mrsigner policy.in Enclave.signed.so +policy: sigstruct policy.in Enclave.signed.so $(SGX_SIGN) dump -cssfile enclave_sigstruct_raw -dumpfile /dev/null -enclave Enclave.signed.so - sed -e "s^@MRSIGNER@^`./mrsigner.sh enclave_sigstruct_raw`^" policy.in > policy + sed -e "s^@MRSIGNER@^`./sigstruct.sh --mrsigner enclave_sigstruct_raw`^" \ + -e "s^@MRENCLAVE@^`./sigstruct.sh --mrenclave enclave_sigstruct_raw`^" \ + policy.in > policy rm -f enclave_sigstruct_raw sp_LDFLAGS= $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ @CURL_LDFLAGS@ -mrsigner_LDFLAGS= $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ +sigstruct_LDFLAGS= $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ ## Library flags. At minimum, an Intel SGX application will need: ## @@ -113,7 +115,7 @@ mrsigner_LDFLAGS= $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ client_LDADD=-l$(SGX_URTS_LIB) -lsgx_ukey_exchange -lcrypto \ -l:libsgx_capable.a -lpthread -ldl -mrsigner_LDADD=-lcrypto +sigstruct_LDADD=-lcrypto sp_LDADD=-lcrypto @CURL_LIBS@ diff --git a/Makefile.in b/Makefile.in index a712050..31249bf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -86,7 +86,7 @@ POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : -bin_PROGRAMS = client$(EXEEXT) sp$(EXEEXT) mrsigner$(EXEEXT) +bin_PROGRAMS = client$(EXEEXT) sp$(EXEEXT) sigstruct$(EXEEXT) @AGENT_CURL_TRUE@am__append_1 = agent_curl.cpp subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -100,7 +100,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = mrsigner.sh run-server run-client +CONFIG_CLEAN_FILES = sigstruct.sh run-server run-client CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) @@ -114,12 +114,12 @@ client_OBJECTS = $(am_client_OBJECTS) $(nodist_client_OBJECTS) client_DEPENDENCIES = client_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(client_LDFLAGS) \ $(LDFLAGS) -o $@ -am_mrsigner_OBJECTS = mrsigner.$(OBJEXT) crypto.$(OBJEXT) \ +am_sigstruct_OBJECTS = sigstruct.$(OBJEXT) crypto.$(OBJEXT) \ hexutil.$(OBJEXT) -mrsigner_OBJECTS = $(am_mrsigner_OBJECTS) -mrsigner_DEPENDENCIES = -mrsigner_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ - $(mrsigner_LDFLAGS) $(LDFLAGS) -o $@ +sigstruct_OBJECTS = $(am_sigstruct_OBJECTS) +sigstruct_DEPENDENCIES = +sigstruct_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(sigstruct_LDFLAGS) $(LDFLAGS) -o $@ am__sp_SOURCES_DIST = sp.cpp agent_wget.cpp iasrequest.cpp \ enclave_verify.c byteorder.c common.cpp crypto.c hexutil.c \ fileio.c base64.c msgio.cpp logfile.c agent_curl.cpp @@ -172,8 +172,8 @@ am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_1 = SOURCES = $(client_SOURCES) $(nodist_client_SOURCES) \ - $(mrsigner_SOURCES) $(sp_SOURCES) -DIST_SOURCES = $(client_SOURCES) $(mrsigner_SOURCES) \ + $(sigstruct_SOURCES) $(sp_SOURCES) +DIST_SOURCES = $(client_SOURCES) $(sigstruct_SOURCES) \ $(am__sp_SOURCES_DIST) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ @@ -219,7 +219,7 @@ CTAGS = ctags CSCOPE = cscope DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ - $(srcdir)/mrsigner.sh.in $(srcdir)/run.in \ + $(srcdir)/sigstruct.sh.in $(srcdir)/run.in \ $(top_srcdir)/build-aux/sgx_app.am compile depcomp install-sh \ missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -415,13 +415,13 @@ client_LDFLAGS = $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ sp_SOURCES = sp.cpp agent_wget.cpp iasrequest.cpp enclave_verify.c \ $(common) $(am__append_1) EXTRA_sp_DEPENDENCIES = Enclave.signed.so -mrsigner_SOURCES = mrsigner.cpp crypto.c hexutil.c +sigstruct_SOURCES = sigstruct.cpp crypto.c hexutil.c sp_LDFLAGS = $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ @CURL_LDFLAGS@ -mrsigner_LDFLAGS = $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ +sigstruct_LDFLAGS = $(AM_LDFLAGS) @OPENSSL_LDFLAGS@ client_LDADD = -l$(SGX_URTS_LIB) -lsgx_ukey_exchange -lcrypto \ -l:libsgx_capable.a -lpthread -ldl -mrsigner_LDADD = -lcrypto +sigstruct_LDADD = -lcrypto sp_LDADD = -lcrypto @CURL_LIBS@ all: $(BUILT_SOURCES) config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive @@ -477,7 +477,7 @@ $(srcdir)/config.h.in: $(am__configure_deps) distclean-hdr: -rm -f config.h stamp-h1 -mrsigner.sh: $(top_builddir)/config.status $(srcdir)/mrsigner.sh.in +sigstruct.sh: $(top_builddir)/config.status $(srcdir)/sigstruct.sh.in cd $(top_builddir) && $(SHELL) ./config.status $@ run-server: $(top_builddir)/config.status $(srcdir)/run.in cd $(top_builddir) && $(SHELL) ./config.status $@ @@ -526,13 +526,13 @@ uninstall-binPROGRAMS: clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -client$(EXEEXT): $(client_OBJECTS) $(client_DEPENDENCIES) $(EXTRA_client_DEPENDENCIES) +client$(EXEEXT): $(client_OBJECTS) $(client_DEPENDENCIES) $(EXTRA_client_DEPENDENCIES) @rm -f client$(EXEEXT) $(AM_V_CXXLD)$(client_LINK) $(client_OBJECTS) $(client_LDADD) $(LIBS) -mrsigner$(EXEEXT): $(mrsigner_OBJECTS) $(mrsigner_DEPENDENCIES) $(EXTRA_mrsigner_DEPENDENCIES) - @rm -f mrsigner$(EXEEXT) - $(AM_V_CXXLD)$(mrsigner_LINK) $(mrsigner_OBJECTS) $(mrsigner_LDADD) $(LIBS) +sigstruct$(EXEEXT): $(sigstruct_OBJECTS) $(sigstruct_DEPENDENCIES) $(EXTRA_sigstruct_DEPENDENCIES) + @rm -f sigstruct$(EXEEXT) + $(AM_V_CXXLD)$(sigstruct_LINK) $(sigstruct_OBJECTS) $(sigstruct_LDADD) $(LIBS) sp$(EXEEXT): $(sp_OBJECTS) $(sp_DEPENDENCIES) $(EXTRA_sp_DEPENDENCIES) @rm -f sp$(EXEEXT) @@ -557,7 +557,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hexutil.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iasrequest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logfile.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mrsigner.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigstruct.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msgio.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/quote_size.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sgx_detect_linux.Po@am__quote@ @@ -1039,9 +1039,11 @@ Enclave/Enclave.signed.so: server: sp -policy: mrsigner policy.in Enclave.signed.so +policy: sigstruct policy.in Enclave.signed.so $(SGX_SIGN) dump -cssfile enclave_sigstruct_raw -dumpfile /dev/null -enclave Enclave.signed.so - sed -e "s^@MRSIGNER@^`./mrsigner.sh enclave_sigstruct_raw`^" policy.in > policy + sed -e "s^@MRSIGNER@^`./sigstruct.sh --mrsigner enclave_sigstruct_raw`^" \ + -e "s^@MRENCLAVE@^`./sigstruct.sh --mrenclave enclave_sigstruct_raw`^" \ + policy.in > policy rm -f enclave_sigstruct_raw # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/configure b/configure index ecd8948..28cdf19 100755 --- a/configure +++ b/configure @@ -5323,7 +5323,7 @@ cat >>confdefs.h <<_ACEOF _ACEOF -ac_config_files="$ac_config_files mrsigner.sh run-server:run.in run-client:run.in Makefile Enclave/Makefile" +ac_config_files="$ac_config_files sigstruct.sh run-server:run.in run-client:run.in Makefile Enclave/Makefile" cat >confcache <<\_ACEOF @@ -6073,7 +6073,7 @@ do case $ac_config_target in "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - "mrsigner.sh") CONFIG_FILES="$CONFIG_FILES mrsigner.sh" ;; + "sigstruct.sh") CONFIG_FILES="$CONFIG_FILES sigstruct.sh" ;; "run-server") CONFIG_FILES="$CONFIG_FILES run-server:run.in" ;; "run-client") CONFIG_FILES="$CONFIG_FILES run-client:run.in" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; @@ -6766,11 +6766,11 @@ $as_echo X"$file" | done } ;; - "mrsigner.sh":F) chmod -f 755 run-client run-server mrsigner.sh ;; - "run-server":F) chmod -f 755 run-client run-server mrsigner.sh ;; - "run-client":F) chmod -f 755 run-client run-server mrsigner.sh ;; - "Makefile":F) chmod -f 755 run-client run-server mrsigner.sh ;; - "Enclave/Makefile":F) chmod -f 755 run-client run-server mrsigner.sh ;; + "sigstruct.sh":F) chmod -f 755 run-client run-server sigstruct.sh ;; + "run-server":F) chmod -f 755 run-client run-server sigstruct.sh ;; + "run-client":F) chmod -f 755 run-client run-server sigstruct.sh ;; + "Makefile":F) chmod -f 755 run-client run-server sigstruct.sh ;; + "Enclave/Makefile":F) chmod -f 755 run-client run-server sigstruct.sh ;; esac done # for ac_tag diff --git a/configure.ac b/configure.ac index a748288..21f5e5a 100644 --- a/configure.ac +++ b/configure.ac @@ -119,12 +119,12 @@ AC_DEFINE_UNQUOTED([DEFAULT_CA_BUNDLE_AUTO], ["$ac_cv_default_ca_bundle_auto"], dnl Write our configuration dnl ---------------------------------------------------------------------- AC_CONFIG_FILES([ - mrsigner.sh + sigstruct.sh run-server:run.in run-client:run.in Makefile Enclave/Makefile -],[chmod -f 755 run-client run-server mrsigner.sh]) +],[chmod -f 755 run-client run-server sigstruct.sh]) AC_OUTPUT diff --git a/enclave_verify.c b/enclave_verify.c index c6342a1..b270bb0 100644 --- a/enclave_verify.c +++ b/enclave_verify.c @@ -41,17 +41,17 @@ static int _init= 0; extern int verbose; -int verify_enclave_identity(sgx_measurement_t req_mr_signer, - sgx_prod_id_t req_isv_product_id, sgx_isv_svn_t min_isvsvn, - int allow_debug, sgx_report_body_t *report) +int verify_enclave_identity(sgx_measurement_t req_mr_enclave, + sgx_measurement_t req_mr_signer, sgx_prod_id_t req_isv_product_id, + sgx_isv_svn_t min_isvsvn, int allow_debug, sgx_report_body_t *report) { if ( verbose ) { edividerWithText("Client enclave Identity"); - eprintf("Enclave MRSIGNER = %s\n", + eprintf("Enclave MRSIGNER = %s\n", hexstring((const char *) &report->mr_signer, sizeof(sgx_measurement_t)) ); - eprintf("Enclave MRENCLAVE = %s\n", + eprintf("Enclave MRENCLAVE = %s\n", hexstring((const char *) &report->mr_enclave, sizeof(sgx_measurement_t)) ); @@ -88,7 +88,7 @@ int verify_enclave_identity(sgx_measurement_t req_mr_signer, // Does the MRSIGNER match? - if ( memcmp((const void *) &report->mr_signer, + if ( memcmp((const void *) &report->mr_signer, (const void *) &req_mr_signer, sizeof(sgx_measurement_t) ) ) { eprintf("MRSIGNER mismatch\n"); @@ -96,6 +96,16 @@ int verify_enclave_identity(sgx_measurement_t req_mr_signer, return 0; } + // Does the MRENCLAVE match? + + if ( memcmp((const void *) &report->mr_enclave, + (const void *) &req_mr_enclave, sizeof(sgx_measurement_t) ) ) { + + eprintf("MRENCLAVE mismatch\n"); + + return 0; + } + return 1; } diff --git a/enclave_verify.h b/enclave_verify.h index f0d7b25..5cddaf9 100644 --- a/enclave_verify.h +++ b/enclave_verify.h @@ -7,8 +7,9 @@ extern "C" { #endif -int verify_enclave_identity(sgx_measurement_t mrsigner, sgx_prod_id_t prodid, - sgx_isv_svn_t min_isvsvn, int allow_debug, sgx_report_body_t *report); +int verify_enclave_identity(sgx_measurement_t mrenclave, + sgx_measurement_t mrsigner, sgx_prod_id_t prodid, + sgx_isv_svn_t min_isvsvn, int allow_debug, sgx_report_body_t *report); #ifdef __cplusplus }; diff --git a/policy.in b/policy.in index c8b361e..e183b0f 100644 --- a/policy.in +++ b/policy.in @@ -8,10 +8,15 @@ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # This hex string should match the signer of the enclave. This is used to -# prevents unauthorized enclaves (those from unrecognized ISVs/developers) +# prevent unauthorized enclaves (those from unrecognized ISVs/developers) # from using the remote service. MRSIGNER=@MRSIGNER@ +# This hex string should match the measurement of the enclave code, also +# know as the enclave hash. This is used to prevent unauthorized enclaves +# (those with a different hash) from using the remote service. +MRENCLAVE=@MRENCLAVE@ + # The product ID for the enclave. This must match the ProdId in the # enclave confgiruation file. PRODID=0 diff --git a/run.in b/run.in index 29a99b1..cf2ba98 100755 --- a/run.in +++ b/run.in @@ -121,6 +121,7 @@ then -i $IAS_PRIMARY_SUBSCRIPTION_KEY \ -j $IAS_SECONDARY_SUBSCRIPTION_KEY \ -A "$IAS_REPORT_SIGNING_CA_FILE" \ + -M $MRENCLAVE \ -N $MRSIGNER \ -V $MIN_ISVSVN \ -R $PRODID \ diff --git a/mrsigner.c b/sigstruct.c similarity index 50% rename from mrsigner.c rename to sigstruct.c index db9aec7..94d25ff 100644 --- a/mrsigner.c +++ b/sigstruct.c @@ -17,7 +17,7 @@ in the License. /* * Read in a SIGSTRUCT dump file (from: sgx_sign dump -cssfile ...) and - * produce the MRSIGNER hash. + * produce the MRENCLAVE hash. */ #include @@ -44,23 +44,30 @@ in the License. #define MODULUS_OFFSET 128 #define MODULUS_SIZE 384 +#define ENCLAVEHASH_OFFSET 960 +#define ENCLAVEHASH_SIZE 32 void usage (); -int main(int argc, char *argv[]) +int main(int argc, char **argv) { char *cssfile= NULL; char *sigstruct_raw= NULL; unsigned char modulus[MODULUS_SIZE]; unsigned char mrsigner[32]; /* Size of SHA-256 hash */ + unsigned char mrenclave[ENCLAVEHASH_SIZE]; /* Size of SHA-256 hash */ FILE *fp; size_t bread; + static int flag_mrsigner = 0; + static int flag_mrenclave = 0; /* Command line options */ static struct option long_opt[] = { - {"help", no_argument, 0, 'h'}, + {"mrenclave", no_argument, &flag_mrenclave, 1}, + {"mrsigner", no_argument, &flag_mrsigner, 1}, + {"help", no_argument, 0, 'h'}, { 0, 0, 0, 0 } }; @@ -70,13 +77,15 @@ int main(int argc, char *argv[]) int c; int opt_index = 0; - c = getopt_long(argc, argv, "h", long_opt, &opt_index); + c = getopt_long_only(argc, argv, "h", long_opt, &opt_index); if (c == -1) break; switch (c) { - + case 0: + break; case 'h': case '?': + break; default: usage(); } @@ -89,7 +98,8 @@ int main(int argc, char *argv[]) /* The remaining argument is the sigstruct file to read */ - cssfile= argv[1]; + //cssfile= argv[1]; + cssfile= argv[optind]; #ifdef _WIN32 if (fopen_s(&fp, cssfile, "rb") != 0) { @@ -103,38 +113,64 @@ int main(int argc, char *argv[]) exit(1); } - /* Seek to the location of the public key modulus */ + if ( flag_mrenclave ) { + /* Seek to the location of the enclave hash (mrenclave) */ - if ( fseek(fp, MODULUS_OFFSET, SEEK_SET) == -1 ) { - fprintf(stderr, "%s: ", cssfile); - perror("fseek"); - exit(1); - } + if ( fseek(fp, ENCLAVEHASH_OFFSET, SEEK_SET) == -1 ) { + fprintf(stderr, "%s: ", cssfile); + perror("fseek"); + exit(1); + } - /* Read the modulus */ + /* Read the enclave hash (mrenclave) */ - bread = fread(modulus, 1, (size_t) MODULUS_SIZE, fp); - if ( bread != MODULUS_SIZE ) { - fprintf(stderr, "%s: not a valid sigstruct (file too small)\n", - cssfile); - exit(1); - } + bread = fread(mrenclave, 1, (size_t) ENCLAVEHASH_SIZE, fp); + if ( bread != ENCLAVEHASH_SIZE ) { + fprintf(stderr, "%s: not a valid sigstruct (file too small)\n", + cssfile); + exit(1); + } - fclose(fp); + fclose(fp); - /* Calculate MRSIGNER, which is the SHA-256 hash of the modulus */ + print_hexstring_nl(stdout, mrenclave, 32); + } + if ( flag_mrsigner ) { + /* Seek to the location of the public key modulus */ - if ( sha256_digest(modulus, MODULUS_SIZE, mrsigner) ) { - print_hexstring_nl(stdout, mrsigner, 32); - exit(0); - } + if ( fseek(fp, MODULUS_OFFSET, SEEK_SET) == -1 ) { + fprintf(stderr, "%s: ", cssfile); + perror("fseek"); + exit(1); + } - fprintf(stderr, "error calculating MRSIGNER\n"); - exit(1); + /* Read the modulus */ + + bread = fread(modulus, 1, (size_t) MODULUS_SIZE, fp); + if ( bread != MODULUS_SIZE ) { + fprintf(stderr, "%s: not a valid sigstruct (file too small)\n", + cssfile); + exit(1); + } + + fclose(fp); + + /* Calculate MRSIGNER, which is the SHA-256 hash of the modulus */ + + if ( sha256_digest(modulus, MODULUS_SIZE, mrsigner) ) { + print_hexstring_nl(stdout, mrsigner, 32); + exit(0); + } + + fprintf(stderr, "error calculating MRSIGNER\n"); + exit(1); + } + + exit(0); } -void usage () +void usage () { - fprintf(stderr, "usage: mrsigner cssfile\n"); + fprintf(stderr, "usage: sigstruct [--mrenclave | --mrsigner] cssfile\n"); exit(1); } diff --git a/mrsigner.sh.in b/sigstruct.sh.in similarity index 93% rename from mrsigner.sh.in rename to sigstruct.sh.in index 562a310..b92999c 100644 --- a/mrsigner.sh.in +++ b/sigstruct.sh.in @@ -13,5 +13,5 @@ then fi fi -exec ./mrsigner "$@" +exec ./sigstruct "$@" diff --git a/sp.cpp b/sp.cpp index c989f43..082affd 100644 --- a/sp.cpp +++ b/sp.cpp @@ -97,6 +97,7 @@ typedef struct config_struct { X509 *signing_ca; unsigned int apiver; int strict_trust; + sgx_measurement_t req_mrenclave; sgx_measurement_t req_mrsigner; sgx_prod_id_t req_isv_product_id; sgx_isv_svn_t min_isvsvn; @@ -144,6 +145,7 @@ int main(int argc, char *argv[]) char flag_stdio= 0; char flag_isv_product_id= 0; char flag_min_isvsvn= 0; + char flag_mrenclave = 0; char flag_mrsigner= 0; char *sigrl = NULL; config_t config; @@ -165,6 +167,7 @@ int main(int argc, char *argv[]) {"ias-pri-api-key-file", required_argument, 0, 'I'}, {"ias-sec-api-key-file", required_argument, 0, 'J'}, {"service-key-file", required_argument, 0, 'K'}, + {"mrenclave", required_argument, 0, 'M'}, {"mrsigner", required_argument, 0, 'N'}, {"production", no_argument, 0, 'P'}, {"isv-product-id", required_argument, 0, 'R'}, @@ -215,7 +218,7 @@ int main(int argc, char *argv[]) unsigned long val; c = getopt_long(argc, argv, - "A:B:DGI:J:K:N:PR:S:V:X:dg:hk:lp:r:s:i:j:vxz", + "A:B:DGI:J:K:M:N:PR:S:V:X:dg:hk:lp:r:s:i:j:vxz", long_opt, &opt_index); if (c == -1) break; @@ -307,6 +310,19 @@ int main(int argc, char *argv[]) } break; + // MRENCLAVE + // + // TODO double-check if that is correct + case 'M': + if (!from_hexstring((unsigned char *)&config.req_mrenclave, + optarg, 32)) { + + eprintf("MRENCLAVE must be 64-byte hex string\n"); + return 1; + } + ++flag_mrenclave; + break; + case 'N': if (!from_hexstring((unsigned char *)&config.req_mrsigner, optarg, 32)) { @@ -549,12 +565,17 @@ int main(int argc, char *argv[]) eprintf("--isv-product-id is required\n"); flag_usage = 1; } - + if ( ! flag_min_isvsvn ) { eprintf("--min-isvsvn is required\n"); flag_usage = 1; } - + + if ( ! flag_mrenclave ) { + eprintf("--mrenclave is required\n"); + flag_usage = 1; + } + if ( ! flag_mrsigner ) { eprintf("--mrsigner is required\n"); flag_usage = 1; @@ -926,8 +947,8 @@ int process_msg3 (MsgIO *msgio, IAS_Connection *ias, sgx_ra_msg1_t *msg1, #ifndef _WIN32 /* Windows implementation is not available yet */ - if ( ! verify_enclave_identity(config->req_mrsigner, - config->req_isv_product_id, config->min_isvsvn, + if ( ! verify_enclave_identity(config->req_mrenclave, config->req_mrsigner, + config->req_isv_product_id, config->min_isvsvn, config->allow_debug_enclave, r) ) { eprintf("Invalid enclave.\n"); @@ -1649,12 +1670,16 @@ void cleanup_and_exit(int signo) #define NNL <