@@ -46,6 +46,34 @@ static int mStop = 0;
4646 double benchStart ;
4747#endif
4848
49+ /* CA Certificate path defines with defaults */
50+ #ifndef CA_RSA_CERT_PATH
51+ #define CA_RSA_CERT_PATH "./certs/ca-rsa-cert.pem"
52+ #endif
53+ #ifndef WOLF_CA_RSA_CERT_PATH
54+ #define WOLF_CA_RSA_CERT_PATH "./certs/wolf-ca-rsa-cert.pem"
55+ #endif
56+ #ifndef CA_ECC_CERT_PATH
57+ #define CA_ECC_CERT_PATH "./certs/ca-ecc-cert.pem"
58+ #endif
59+ #ifndef WOLF_CA_ECC_CERT_PATH
60+ #define WOLF_CA_ECC_CERT_PATH "./certs/wolf-ca-ecc-cert.pem"
61+ #endif
62+
63+ /* Server Certificate path defines with defaults */
64+ #ifndef SERVER_RSA_CERT_PATH
65+ #define SERVER_RSA_CERT_PATH "./certs/server-rsa-cert.pem"
66+ #endif
67+ #ifndef TPM_RSA_CERT_PATH
68+ #define TPM_RSA_CERT_PATH "./certs/tpm-rsa-cert.pem"
69+ #endif
70+ #ifndef SERVER_ECC_CERT_PATH
71+ #define SERVER_ECC_CERT_PATH "./certs/server-ecc-cert.pem"
72+ #endif
73+ #ifndef TPM_ECC_CERT_PATH
74+ #define TPM_ECC_CERT_PATH "./certs/tpm-ecc-cert.pem"
75+ #endif
76+
4977/*
5078 * Generating the Server Certificate
5179 *
@@ -380,14 +408,14 @@ int TPM2_TLS_ServerArgs(void* userCtx, int argc, char *argv[])
380408 /* Load CA Certificates */
381409 if (!useECC ) {
382410 #ifndef NO_RSA
383- if (wolfSSL_CTX_load_verify_locations (ctx , "./certs/ca-rsa-cert.pem" ,
411+ if (wolfSSL_CTX_load_verify_locations (ctx , CA_RSA_CERT_PATH ,
384412 0 ) != WOLFSSL_SUCCESS ) {
385- printf ("Error loading ca-rsa-cert.pem cert\n" );
413+ printf ("Error loading %s cert\n" , CA_RSA_CERT_PATH );
386414 goto exit ;
387415 }
388- if (wolfSSL_CTX_load_verify_locations (ctx , "./certs/wolf-ca-rsa-cert.pem" ,
416+ if (wolfSSL_CTX_load_verify_locations (ctx , WOLF_CA_RSA_CERT_PATH ,
389417 0 ) != WOLFSSL_SUCCESS ) {
390- printf ("Error loading wolf-ca-rsa-cert.pem cert\n" );
418+ printf ("Error loading %s cert\n" , WOLF_CA_RSA_CERT_PATH );
391419 goto exit ;
392420 }
393421 #else
@@ -398,16 +426,16 @@ int TPM2_TLS_ServerArgs(void* userCtx, int argc, char *argv[])
398426 }
399427 else {
400428 #ifdef HAVE_ECC
401- if (wolfSSL_CTX_load_verify_locations (ctx , "./certs/ca-ecc-cert.pem" ,
429+ if (wolfSSL_CTX_load_verify_locations (ctx , CA_ECC_CERT_PATH ,
402430 0 ) != WOLFSSL_SUCCESS ) {
403- printf ("Error loading ca-ecc-cert.pem cert\n" );
431+ printf ("Error loading %s cert\n" , CA_ECC_CERT_PATH );
404432 #ifndef WOLFTPM_MFG_IDENTITY /* not fatal if using mfg identity */
405433 goto exit ;
406434 #endif
407435 }
408- if (wolfSSL_CTX_load_verify_locations (ctx , "./certs/wolf-ca-ecc-cert.pem" ,
436+ if (wolfSSL_CTX_load_verify_locations (ctx , WOLF_CA_ECC_CERT_PATH ,
409437 0 ) != WOLFSSL_SUCCESS ) {
410- printf ("Error loading wolf-ca-ecc-cert.pem cert\n" );
438+ printf ("Error loading %s cert\n" , WOLF_CA_ECC_CERT_PATH );
411439 goto exit ;
412440 }
413441 #else
@@ -461,14 +489,18 @@ int TPM2_TLS_ServerArgs(void* userCtx, int argc, char *argv[])
461489 WOLFSSL_FILETYPE_ASN1 );
462490 #endif
463491 #else
464- const char * useCert = "./certs/server-rsa-cert.pem" ;
492+ const char * useCert = SERVER_RSA_CERT_PATH ;
465493 if (useSelfSign ) {
466- useCert = "./certs/tpm-rsa-cert.pem" ;
494+ useCert = TPM_RSA_CERT_PATH ;
467495 }
468496 rc = wolfSSL_CTX_use_certificate_file (ctx , useCert , WOLFSSL_FILETYPE_PEM );
469497 #endif
470498 if (rc != WOLFSSL_SUCCESS ) {
499+ #ifndef NO_FILESYSTEM
500+ printf ("Error loading RSA client cert: %s\n" , useCert );
501+ #else
471502 printf ("Error loading RSA client cert\n" );
503+ #endif
472504 goto exit ;
473505 }
474506#else
@@ -496,14 +528,18 @@ int TPM2_TLS_ServerArgs(void* userCtx, int argc, char *argv[])
496528 WOLFSSL_FILETYPE_ASN1 );
497529 #endif
498530 #else
499- const char * useCert = "./certs/server-ecc-cert.pem" ;
531+ const char * useCert = SERVER_ECC_CERT_PATH ;
500532 if (useSelfSign ) {
501- useCert = "./certs/tpm-ecc-cert.pem" ;
533+ useCert = TPM_ECC_CERT_PATH ;
502534 }
503535 rc = wolfSSL_CTX_use_certificate_file (ctx , useCert , WOLFSSL_FILETYPE_PEM );
504536 #endif
505537 if (rc != WOLFSSL_SUCCESS ) {
538+ #ifndef NO_FILESYSTEM
539+ printf ("Error loading ECC client cert: %s\n" , useCert );
540+ #else
506541 printf ("Error loading ECC client cert\n" );
542+ #endif
507543 goto exit ;
508544 }
509545#else
@@ -649,7 +685,7 @@ int TPM2_TLS_ServerArgs(void* userCtx, int argc, char *argv[])
649685 }
650686
651687exit :
652-
688+ mStop = 0 ; /* Reset the stop flag for if example is compiled into a demo */
653689 if (rc != 0 ) {
654690 printf ("Failure %d (0x%x): %s\n" , rc , rc , wolfTPM2_GetRCString (rc ));
655691 }
0 commit comments