3636#include <tests/api/api.h>
3737#include <tests/api/test_ossl_x509_str.h>
3838
39- #if ( defined(OPENSSL_ALL ) || defined( WOLFSSL_QT ) ) && \
39+ #if defined(OPENSSL_ALL ) && \
4040 !defined(NO_RSA ) && !defined(NO_FILESYSTEM )
4141
42- static int last_errcode [2 ];
43- static int last_errdepth [2 ];
42+ static int last_errcode ;
43+ static int last_errdepth ;
44+ static int last_errcodes [10 ];
45+ static int last_errdepths [10 ];
4446static int err_index = 0 ;
4547
4648static int X509Callback (int ok , X509_STORE_CTX * ctx )
4749{
4850
4951 if (!ok ) {
50- last_errcode [ err_index ] = X509_STORE_CTX_get_error (ctx );
51- last_errdepth [ err_index ++ ] = X509_STORE_CTX_get_error_depth (ctx );
52+ last_errcode = X509_STORE_CTX_get_error (ctx );
53+ last_errdepth = X509_STORE_CTX_get_error_depth (ctx );
5254 }
5355 /* Always return OK to allow verification to continue.*/
5456 return 1 ;
5557}
5658
59+ static int X509CallbackCount (int ok , X509_STORE_CTX * ctx )
60+ {
61+ if (!ok ) {
62+ last_errcodes [err_index ] = X509_STORE_CTX_get_error (ctx );
63+ last_errdepths [err_index ] = X509_STORE_CTX_get_error_depth (ctx );
64+ err_index ++ ;
65+ }
66+ /* Always return OK to allow verification to continue.*/
67+ return 1 ;
68+ }
5769#endif
5870
5971int test_wolfSSL_X509_STORE_CTX_set_time (void )
@@ -182,7 +194,7 @@ int test_wolfSSL_X509_STORE_check_time(void)
182194 wolfSSL_X509_free (cert );
183195 cert = NULL ;
184196
185- #if ( defined(OPENSSL_ALL ) || defined( WOLFSSL_QT ) ) && \
197+ #if defined(OPENSSL_ALL ) && \
186198 !defined(NO_RSA ) && !defined(NO_FILESYSTEM )
187199
188200 err_index = 0 ;
@@ -193,7 +205,7 @@ int test_wolfSSL_X509_STORE_check_time(void)
193205 SSL_FILETYPE_PEM ));
194206 ExpectIntEQ (wolfSSL_X509_STORE_add_cert (store , ca ), WOLFSSL_SUCCESS );
195207
196- X509_STORE_set_verify_cb (store , X509Callback );
208+ X509_STORE_set_verify_cb (store , X509CallbackCount );
197209
198210 ExpectNotNull (cert = wolfSSL_X509_load_certificate_file (expiredCertFile ,
199211 SSL_FILETYPE_PEM ));
@@ -203,10 +215,10 @@ int test_wolfSSL_X509_STORE_check_time(void)
203215 /* while verifying the certificate, it should have two errors */
204216 ExpectIntEQ (err_index , 2 );
205217 /* self-signed */
206- ExpectIntEQ (last_errcode [err_index - 2 ],
218+ ExpectIntEQ (last_errcodes [err_index - 2 ],
207219 WOLFSSL_X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT );
208220 /* expired */
209- ExpectIntEQ (last_errcode [err_index - 1 ],
221+ ExpectIntEQ (last_errcodes [err_index - 1 ],
210222 WOLFSSL_X509_V_ERR_CERT_HAS_EXPIRED );
211223
212224 X509_STORE_CTX_free (ctx );
@@ -231,7 +243,7 @@ int test_wolfSSL_X509_STORE_check_time(void)
231243 SSL_FILETYPE_PEM ));
232244 ExpectIntEQ (wolfSSL_X509_STORE_add_cert (store , ca ), WOLFSSL_SUCCESS );
233245
234- X509_STORE_set_verify_cb (store , X509Callback );
246+ X509_STORE_set_verify_cb (store , X509CallbackCount );
235247
236248 ExpectNotNull (cert = wolfSSL_X509_load_certificate_file (expiredCertFile ,
237249 SSL_FILETYPE_PEM ));
@@ -241,7 +253,7 @@ int test_wolfSSL_X509_STORE_check_time(void)
241253 /* while verifying the certificate, it should have an error */
242254 ExpectIntEQ (err_index , 1 );
243255 /* self-signed */
244- ExpectIntEQ (last_errcode [err_index - 1 ],
256+ ExpectIntEQ (last_errcodes [err_index - 1 ],
245257 WOLFSSL_X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT );
246258 /* no expired because of no_check_time */
247259 X509_STORE_CTX_free (ctx );
@@ -1025,7 +1037,6 @@ int test_X509_STORE_InvalidCa(void)
10251037 X509 * cert = NULL ;
10261038 STACK_OF (X509 )* untrusted = NULL ;
10271039
1028- err_index = 0 ;
10291040 ExpectTrue ((fp = XFOPEN (srvfile , "rb" ))
10301041 != XBADFILE );
10311042 ExpectNotNull (cert = PEM_read_X509 (fp , 0 , 0 , 0 ));
@@ -1050,8 +1061,7 @@ int test_X509_STORE_InvalidCa(void)
10501061
10511062 ExpectIntEQ (X509_STORE_CTX_init (ctx , str , cert , untrusted ), 1 );
10521063 ExpectIntEQ (X509_verify_cert (ctx ), 1 );
1053- ExpectIntEQ (err_index , 1 );
1054- ExpectIntEQ (last_errcode [err_index - 1 ], X509_V_ERR_INVALID_CA );
1064+ ExpectIntEQ (last_errcode , X509_V_ERR_INVALID_CA );
10551065
10561066 X509_free (cert );
10571067 X509_STORE_free (str );
0 commit comments