3838#define SERVER_PORT 443
3939#define ALPN_PROTOS "http/1.1"
4040
41- #define SYS_CERTS_FILE "/etc/ssl/certs/ca-certificates.crt"
41+ #if defined(WOLFSSL_ASYNC_CRYPT ) && defined(HAVE_SNI ) && defined(HAVE_ALPN ) \
42+ && defined(WOLFSSL_NONBLOCK_OCSP ) && defined(HAVE_CERTIFICATE_STATUS_REQUEST ) \
43+ && defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2 )
44+
45+ static const char * sys_certs_file = "/etc/ssl/certs/ca-certificates.crt" ;
4246
4347#if defined(WOLFSSL_ASYNC_CRYPT )
4448static int wait_async (WOLFSSL_CTX * ctx , WOLFSSL * ssl )
@@ -89,7 +93,7 @@ static int ocsp_cb(void* ctx, const char* url, int urlSz, unsigned char* request
8993 if (frq != NULL ) {
9094 size_t nbytes = fwrite (request , 1 , requestSz , frq );
9195 if (requestSz != nbytes ) {
92- printf ("Failed to write all data. Wrote only %u bytes.\n" , nbytes );
96+ printf ("Failed to write all data. Wrote only %zu bytes.\n" , nbytes );
9397 }
9498 fclose (frq );
9599 frq = NULL ;
@@ -107,12 +111,12 @@ static int ocsp_cb(void* ctx, const char* url, int urlSz, unsigned char* request
107111 printf ("Reading OCSP response from file...\n" );
108112 char resp [4096 ];
109113 size_t nbytes = fread (resp , 1 , sizeof (resp ), frsp );
110- printf ("Read %u bytes.\n" , nbytes );
114+ printf ("Read %zu bytes.\n" , nbytes );
111115 fclose (frsp );
112116 frsp = NULL ;
113117
114118 printf ("*response is %p\n" , * response );
115- printf ("Allocating %u bytes...\n" , nbytes );
119+ printf ("Allocating %zu bytes...\n" , nbytes );
116120 * response = malloc (nbytes );
117121 if (* response == NULL ) {
118122 printf ("malloc() failed\n" );
@@ -307,9 +311,14 @@ int test_connect(WOLFSSL_CTX* ctx)
307311exit :
308312 return result ;
309313}
314+ #endif
310315
311- int main (void )
316+ int main (int argc , char * * argv )
312317{
318+ #if defined(WOLFSSL_ASYNC_CRYPT ) && defined(HAVE_SNI ) && defined(HAVE_ALPN ) \
319+ && defined(WOLFSSL_NONBLOCK_OCSP ) && defined(HAVE_CERTIFICATE_STATUS_REQUEST ) \
320+ && defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2 )
321+
313322 int err ;
314323 int result = 0 ;
315324 WC_RNG rng ;
@@ -318,10 +327,29 @@ int main(void)
318327 WOLFSSL_METHOD * method = NULL ;
319328 WOLFSSL_CTX * ctx = NULL ;
320329
330+ /* Check presence of sys_certs_file */
331+ if (access (sys_certs_file , F_OK ) == -1 && argc == 1 ) {
332+ fprintf (stderr , "Default system cert file /etc/ssl/certs/ca-certificates.crt doesn't exist."
333+ " Please provide cert file path as show below.\n" );
334+ fprintf (stderr , "./ocsp_nonblock_asynccrypt ../../mycerts/ca.crt\n" );
335+ return -1 ;
336+ }
337+ /* Handle user provided certs file */
338+ else if (argc == 2 ) {
339+ if (access (argv [1 ], F_OK ) == -1 ) {
340+ fprintf (stderr , "Provided cert file %s doesn't exist."
341+ " Please provide a valid path.\n" , argv [1 ]);
342+ return -1 ;
343+ }
344+ else {
345+ sys_certs_file = argv [1 ];
346+ }
347+ }
348+
321349 wolfSSL_Debugging_ON ();
322350
323351 err = wolfSSL_Init ();
324- if (err != 0 ) {
352+ if (err != SSL_SUCCESS ) {
325353 fprintf (stderr , "wolfSSL_Init() failed with code %d\n" , err );
326354 return -1 ;
327355 }
@@ -398,7 +426,7 @@ int main(void)
398426 goto exit ;
399427 }
400428
401- err = wolfSSL_CTX_load_verify_locations (ctx , SYS_CERTS_FILE , NULL );
429+ err = wolfSSL_CTX_load_verify_locations (ctx , sys_certs_file , NULL );
402430 if (err != SSL_SUCCESS ) {
403431 fprintf (stderr , "wolfSSL_CTX_load_verify_locations() returned %d\n" , err );
404432 result = -1 ;
@@ -443,4 +471,13 @@ int main(void)
443471 wolfSSL_Cleanup ();
444472
445473 return result ;
474+ #else
475+ (void )argc ;
476+ (void )argv ;
477+
478+ printf ("Please compile wolfSSL with ./configure --enable-asynccrypt --enable-sni"
479+ " --enable-alpn --enable-ocspstapling --enable-ocspstapling2 --enable-opensslextra"
480+ " --enable-curve25519 CFLAGS=-DWOLFSSL_NONBLOCK_OCSP" )
481+ return -1 ;
482+ #endif
446483}
0 commit comments