@@ -300,10 +300,35 @@ int test_x509_verify_cert_hostname_check(void)
300300 ExpectIntEQ (wolfSSL_X509_VERIFY_PARAM_set1_host (param , "wrong.com" ,
301301 XSTRLEN ("wrong.com" )), WOLFSSL_SUCCESS );
302302 ExpectIntNE (wolfSSL_X509_verify_cert (ctx ), WOLFSSL_SUCCESS );
303- ExpectTrue (wolfSSL_X509_STORE_CTX_get_error (ctx ) ==
304- X509_V_ERR_HOSTNAME_MISMATCH ||
305- /* This is the case for OPENSSL_COEXIST */
306- wolfSSL_X509_STORE_CTX_get_error (ctx ) == 1 );
303+ ExpectIntEQ (wolfSSL_X509_STORE_CTX_get_error (ctx ),
304+ X509_V_ERR_HOSTNAME_MISMATCH );
305+ ExpectIntEQ (wolfSSL_X509_STORE_CTX_get_error_depth (ctx ), 0 );
306+ wolfSSL_X509_STORE_CTX_free (ctx );
307+ ctx = NULL ;
308+
309+ /* Case 4: IP matches a SAN IP entry - must succeed. */
310+ ExpectNotNull (ctx = wolfSSL_X509_STORE_CTX_new ());
311+ ExpectIntEQ (wolfSSL_X509_STORE_CTX_init (ctx , store , leaf , NULL ),
312+ WOLFSSL_SUCCESS );
313+ param = wolfSSL_X509_STORE_CTX_get0_param (ctx );
314+ ExpectNotNull (param );
315+ ExpectIntEQ (wolfSSL_X509_VERIFY_PARAM_set1_ip_asc (param , "127.0.0.1" ),
316+ WOLFSSL_SUCCESS );
317+ ExpectIntEQ (wolfSSL_X509_verify_cert (ctx ), WOLFSSL_SUCCESS );
318+ wolfSSL_X509_STORE_CTX_free (ctx );
319+ ctx = NULL ;
320+
321+ /* Case 5: IP does not match - must FAIL with the right error code. */
322+ ExpectNotNull (ctx = wolfSSL_X509_STORE_CTX_new ());
323+ ExpectIntEQ (wolfSSL_X509_STORE_CTX_init (ctx , store , leaf , NULL ),
324+ WOLFSSL_SUCCESS );
325+ param = wolfSSL_X509_STORE_CTX_get0_param (ctx );
326+ ExpectNotNull (param );
327+ ExpectIntEQ (wolfSSL_X509_VERIFY_PARAM_set1_ip_asc (param , "192.168.1.1" ),
328+ WOLFSSL_SUCCESS );
329+ ExpectIntNE (wolfSSL_X509_verify_cert (ctx ), WOLFSSL_SUCCESS );
330+ ExpectIntEQ (wolfSSL_X509_STORE_CTX_get_error (ctx ),
331+ X509_V_ERR_IP_ADDRESS_MISMATCH );
307332 ExpectIntEQ (wolfSSL_X509_STORE_CTX_get_error_depth (ctx ), 0 );
308333 wolfSSL_X509_STORE_CTX_free (ctx );
309334 ctx = NULL ;
0 commit comments