Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Add MRENCLAVE verification
Browse files Browse the repository at this point in the history
Related issue: #64
  • Loading branch information
sbellem committed Feb 10, 2021
1 parent e82c1cd commit b018ef6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
22 changes: 16 additions & 6 deletions enclave_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
Expand Down Expand Up @@ -88,14 +88,24 @@ 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");

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;
}

5 changes: 3 additions & 2 deletions enclave_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
4 changes: 4 additions & 0 deletions policy.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# from using the remote service.
MRSIGNER=@MRSIGNER@

# This hex string should match the measurement of the enclave code, etc.
# TODO document properly
MRENCLAVE=f19de84787f1a90ad7bc2d4c2fd952e05545c6f177e8b10b112a4cef31ba0454

# The product ID for the enclave. This must match the ProdId in the
# enclave confgiruation file.
PRODID=0
Expand Down
1 change: 1 addition & 0 deletions run.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
37 changes: 31 additions & 6 deletions sp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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'},
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1649,12 +1670,16 @@ void cleanup_and_exit(int signo)
#define NNL <<endl<<endl<<
#define NL <<endl<<

void usage ()
void usage ()
{
cerr << "usage: sp [ options ] [ port ]" NL
"Required:" NL
" -A, --ias-signing-cafile=FILE" NL
" Specify the IAS Report Signing CA file." NNL
" -M, --mrenclave=HEXSTRING" NL
" Specify the MRENCLAVE value of enclaves that" NL
" are allowed to attest. Enclaves that have a" NL
" different measurment (e.g. source code) are rejected." NNL
" -N, --mrsigner=HEXSTRING" NL
" Specify the MRSIGNER value of encalves that" NL
" are allowed to attest. Enclaves signed by" NL
Expand Down

0 comments on commit b018ef6

Please sign in to comment.