@@ -2159,9 +2159,14 @@ static int ProcessBufferCertHandleDer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
21592159 /* CA certificate to verify with. */
21602160 if (type == CA_TYPE ) {
21612161#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
2162+ /* TEST ONLY CODE:
2163+ * Store the DER encoding of the CA certificate so we can append it to
2164+ * the list of trusted CA certificates if the subsequent call to AddCA
2165+ * is successful */
21622166 word32 derLen ;
21632167 byte * derBuf ;
21642168 if (ctx -> doAppleNativeCertValidationFlag == 1 ) {
2169+ WOLFSSL_MSG ("ANCV Test: copy DER CA cert" );
21652170 derLen = der -> length ;
21662171 derBuf = (byte * )XMALLOC (derLen , NULL , DYNAMIC_TYPE_TMP_BUFFER );
21672172 if (derBuf == NULL ) {
@@ -2176,12 +2181,16 @@ static int ProcessBufferCertHandleDer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
21762181#endif
21772182 /* verify CA unless user set to no verify */
21782183 ret = AddCA (ctx -> cm , & der , WOLFSSL_USER_CA , verify );
2184+
21792185#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
2186+ /* TEST ONLY CODE:
2187+ * Append the DER encoded CA certificate to the list of trusted CA
2188+ * certificates so we can inject them at verification time */
21802189 if (ret == 1 && ctx -> doAppleNativeCertValidationFlag == 1 ) {
2181- WOLFSSL_MSG ("Appending CA to cert list for native cert validation test " );
2190+ WOLFSSL_MSG ("ANCV Test: Appending CA to cert list" );
21822191 ret = wolfSSL_TestAppleNativeCertValidation_AppendCA (ctx , derBuf , (int )derLen );
21832192 if (ret == WOLFSSL_SUCCESS ) {
2184- WOLFSSL_MSG ("Clearing CA table for native cert validation test " );
2193+ WOLFSSL_MSG ("ANCV Test: Clearing CA table" );
21852194 /* Clear the CA table so we can ensure they won't be used for
21862195 * verification */
21872196 ret = wolfSSL_CertManagerUnloadCAs (ctx -> cm );
@@ -2192,6 +2201,7 @@ static int ProcessBufferCertHandleDer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
21922201 XFREE (derBuf , NULL , DYNAMIC_TYPE_TMP_BUFFER );
21932202 }
21942203#endif /* !WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION */
2204+
21952205 if (ret == 1 ) {
21962206 ret = 0 ;
21972207 }
@@ -2978,6 +2988,14 @@ int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
29782988 ret = 0 ;
29792989 }
29802990
2991+ #ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
2992+ if (ret == 1 ) {
2993+ /* TEST ONLY CODE: force native cert validation on */
2994+ WOLFSSL_MSG ("ANCV Test: Loading system CA certs" );
2995+ wolfSSL_CTX_load_system_CA_certs (ctx );
2996+ }
2997+ #endif
2998+
29812999 if (ret == 1 ) {
29823000 /* Get setting on how to verify certificates. */
29833001 verify = GET_VERIFY_SETTING_CTX (ctx );
@@ -2990,19 +3008,19 @@ int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
29903008 /* Load the PEM formatted CA file */
29913009 ret = ProcessFile (ctx , file , WOLFSSL_FILETYPE_PEM , CA_TYPE , NULL , 0 ,
29923010 NULL , verify );
2993- #ifndef NO_WOLFSSL_DIR
3011+ #ifndef NO_WOLFSSL_DIR
29943012 if (ret == 1 ) {
29953013 /* Include success in overall count. */
29963014 successCount ++ ;
29973015 }
2998- #endif
2999- #if defined(WOLFSSL_TRUST_PEER_CERT ) && defined(OPENSSL_COMPATIBLE_DEFAULTS )
3016+ #endif
3017+ #if defined(WOLFSSL_TRUST_PEER_CERT ) && defined(OPENSSL_COMPATIBLE_DEFAULTS )
30003018 /* Load CA as a trusted peer certificate. */
30013019 ret = wolfSSL_CTX_trust_peer_cert (ctx , file , WOLFSSL_FILETYPE_PEM );
30023020 if (ret != 1 ) {
30033021 WOLFSSL_MSG ("wolfSSL_CTX_trust_peer_cert error" );
30043022 }
3005- #endif
3023+ #endif
30063024 }
30073025 }
30083026
@@ -3015,12 +3033,6 @@ int wolfSSL_CTX_load_verify_locations_ex(WOLFSSL_CTX* ctx, const char* file,
30153033 ret = NOT_COMPILED_IN ;
30163034 (void )flags ;
30173035#endif
3018-
3019- #ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
3020- if (ret == 1 ) {
3021- wolfSSL_CTX_load_system_CA_certs (ctx );
3022- }
3023- #endif
30243036 }
30253037
30263038 return ret ;
@@ -3461,15 +3473,14 @@ int wolfSSL_CTX_der_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
34613473 ret = 0 ;
34623474 }
34633475 else {
3464- ret = ProcessFile (ctx , file , format , CA_TYPE , NULL , 0 , NULL ,
3465- GET_VERIFY_SETTING_CTX (ctx ));
3466- }
3467-
34683476#ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
3469- if (ret == 1 ) {
3477+ /* TEST ONLY CODE: force native cert validation on */
3478+ WOLFSSL_MSG ("ANCV Test: loading system CA certs" );
34703479 wolfSSL_CTX_load_system_CA_certs (ctx );
3471- }
34723480#endif
3481+ ret = ProcessFile (ctx , file , format , CA_TYPE , NULL , 0 , NULL ,
3482+ GET_VERIFY_SETTING_CTX (ctx ));
3483+ }
34733484
34743485 /* Return 1 on success or 0 on failure. */
34753486 return WS_RC (ret );
@@ -3975,6 +3986,14 @@ int wolfSSL_CTX_load_verify_buffer_ex(WOLFSSL_CTX* ctx, const unsigned char* in,
39753986
39763987 WOLFSSL_ENTER ("wolfSSL_CTX_load_verify_buffer_ex" );
39773988
3989+ #ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
3990+ /* TEST ONLY CODE: force native cert validation on */
3991+ if (ctx != NULL ) {
3992+ WOLFSSL_MSG ("ANCV Test: loading system CA certs" );
3993+ wolfSSL_CTX_load_system_CA_certs (ctx );
3994+ }
3995+ #endif
3996+
39783997 /* Get setting on how to verify certificates. */
39793998 verify = GET_VERIFY_SETTING_CTX (ctx );
39803999 /* Overwrite setting when flag set. */
@@ -3999,12 +4018,6 @@ int wolfSSL_CTX_load_verify_buffer_ex(WOLFSSL_CTX* ctx, const unsigned char* in,
39994018 }
40004019#endif
40014020
4002- #ifdef WOLFSSL_TEST_APPLE_NATIVE_CERT_VALIDATION
4003- if (ret == 1 ) {
4004- wolfSSL_CTX_load_system_CA_certs (ctx );
4005- }
4006- #endif
4007-
40084021 WOLFSSL_LEAVE ("wolfSSL_CTX_load_verify_buffer_ex" , ret );
40094022 return ret ;
40104023}
0 commit comments