Skip to content

Commit 10d3e25

Browse files
committed
fix qt jenkins nightly test failure
1 parent eab58ae commit 10d3e25

2 files changed

Lines changed: 123 additions & 23 deletions

File tree

src/x509_str.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ static int X509StoreVerifyCertDate(WOLFSSL_X509_STORE_CTX* ctx, int ret)
384384
ret = ASN_BEFORE_DATE_E;
385385
}
386386
}
387+
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
388+
else {
389+
WOLFSSL_MSG("Using system time for date validation");
390+
/* use system time for date validation */
391+
if (wc_ValidateDate(afterDate,
392+
(byte)ctx->current_cert->notAfter.type, ASN_AFTER) < 1) {
393+
ret = ASN_AFTER_DATE_E;
394+
}
395+
else if (wc_ValidateDate(beforeDate,
396+
(byte)ctx->current_cert->notBefore.type, ASN_BEFORE) < 1) {
397+
ret = ASN_BEFORE_DATE_E;
398+
}
399+
}
400+
#endif
387401
}
388402
#else
389403
if (XVALIDATE_DATE(afterDate,
@@ -424,7 +438,20 @@ static int X509StoreVerifyCert(WOLFSSL_X509_STORE_CTX* ctx)
424438
WOLFSSL_SUCCESS : ret;
425439
#endif
426440
}
427-
441+
#if !defined(NO_ASN_TIME) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT))
442+
if (ret != WC_NO_ERR_TRACE(ASN_BEFORE_DATE_E) &&
443+
ret != WC_NO_ERR_TRACE(ASN_AFTER_DATE_E)) {
444+
/* With Qt and OpenSSL, we need to check the certificate's date
445+
* after certificate manager verification,
446+
* as it skips date validation when other errors are present.
447+
*/
448+
ret = X509StoreVerifyCertDate(ctx, ret);
449+
SetupStoreCtxError(ctx, ret);
450+
if (ctx->store->verify_cb)
451+
ret = ctx->store->verify_cb(ret >= 0 ? 1 : 0,
452+
ctx) == 1 ? WOLFSSL_SUCCESS : -1;
453+
}
454+
#endif
428455
return ret;
429456
}
430457

tests/api/test_ossl_x509_str.c

Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@
3636
#include <tests/api/api.h>
3737
#include <tests/api/test_ossl_x509_str.h>
3838

39+
#if (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && \
40+
!defined(NO_RSA) && !defined(NO_FILESYSTEM)
41+
42+
static int last_errcode[2];
43+
static int last_errdepth[2];
44+
static int err_index = 0;
45+
46+
static int X509Callback(int ok, X509_STORE_CTX *ctx)
47+
{
48+
49+
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+
}
53+
/* Always return OK to allow verification to continue.*/
54+
return 1;
55+
}
56+
57+
#endif
58+
3959
int test_wolfSSL_X509_STORE_CTX_set_time(void)
4060
{
4161
EXPECT_DECLS;
@@ -161,6 +181,78 @@ int test_wolfSSL_X509_STORE_check_time(void)
161181
store = NULL;
162182
wolfSSL_X509_free(cert);
163183
cert = NULL;
184+
185+
#if (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && \
186+
!defined(NO_RSA) && !defined(NO_FILESYSTEM)
187+
188+
err_index = 0;
189+
190+
ExpectNotNull(store = X509_STORE_new());
191+
ExpectNotNull(ctx = X509_STORE_CTX_new());
192+
ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
193+
SSL_FILETYPE_PEM));
194+
ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS);
195+
196+
X509_STORE_set_verify_cb(store, X509Callback);
197+
198+
ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(expiredCertFile,
199+
SSL_FILETYPE_PEM));
200+
201+
ExpectIntEQ(X509_STORE_CTX_init(ctx, store, cert, NULL), WOLFSSL_SUCCESS);
202+
ExpectIntEQ(X509_verify_cert(ctx), WOLFSSL_SUCCESS);
203+
/* while verifying the certificate, it should have two errors */
204+
ExpectIntEQ(err_index, 2);
205+
/* self-signed */
206+
ExpectIntEQ(last_errcode[err_index - 2],
207+
WOLFSSL_X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT);
208+
/* expired */
209+
ExpectIntEQ(last_errcode[err_index - 1],
210+
WOLFSSL_X509_V_ERR_CERT_HAS_EXPIRED);
211+
212+
X509_STORE_CTX_free(ctx);
213+
ctx = NULL;
214+
X509_STORE_free(store);
215+
store = NULL;
216+
X509_free(cert);
217+
cert = NULL;
218+
X509_free(ca);
219+
ca = NULL;
220+
221+
err_index = 0;
222+
223+
ExpectNotNull(store = X509_STORE_new());
224+
/* Set NO_CHECK_TIME flag to skip time validation */
225+
ExpectIntEQ(X509_VERIFY_PARAM_set_flags(store->param,
226+
WOLFSSL_NO_CHECK_TIME), WOLFSSL_SUCCESS);
227+
ExpectTrue((store->param->flags & WOLFSSL_NO_CHECK_TIME) ==
228+
WOLFSSL_NO_CHECK_TIME);
229+
ExpectNotNull(ctx = X509_STORE_CTX_new());
230+
ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
231+
SSL_FILETYPE_PEM));
232+
ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS);
233+
234+
X509_STORE_set_verify_cb(store, X509Callback);
235+
236+
ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(expiredCertFile,
237+
SSL_FILETYPE_PEM));
238+
239+
ExpectIntEQ(X509_STORE_CTX_init(ctx, store, cert, NULL), WOLFSSL_SUCCESS);
240+
ExpectIntEQ(X509_verify_cert(ctx), WOLFSSL_SUCCESS);
241+
/* while verifying the certificate, it should have an error */
242+
ExpectIntEQ(err_index, 1);
243+
/* self-signed */
244+
ExpectIntEQ(last_errcode[err_index - 1],
245+
WOLFSSL_X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT);
246+
/* no expired because of no_check_time */
247+
X509_STORE_CTX_free(ctx);
248+
ctx = NULL;
249+
X509_STORE_free(store);
250+
store = NULL;
251+
X509_free(cert);
252+
cert = NULL;
253+
X509_free(ca);
254+
ca = NULL;
255+
#endif
164256
#endif /* OPENSSL_EXTRA && !NO_FILESYSTEM && !NO_ASN_TIME && !NO_RSA */
165257
return EXPECT_RESULT();
166258
}
@@ -919,24 +1011,6 @@ int test_X509_STORE_untrusted(void)
9191011
return EXPECT_RESULT();
9201012
}
9211013

922-
#if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
923-
924-
static int last_errcode;
925-
static int last_errdepth;
926-
927-
static int X509Callback(int ok, X509_STORE_CTX *ctx)
928-
{
929-
930-
if (!ok) {
931-
last_errcode = X509_STORE_CTX_get_error(ctx);
932-
last_errdepth = X509_STORE_CTX_get_error_depth(ctx);
933-
}
934-
/* Always return OK to allow verification to continue.*/
935-
return 1;
936-
}
937-
938-
#endif
939-
9401014
int test_X509_STORE_InvalidCa(void)
9411015
{
9421016
EXPECT_DECLS;
@@ -951,9 +1025,7 @@ int test_X509_STORE_InvalidCa(void)
9511025
X509* cert = NULL;
9521026
STACK_OF(X509)* untrusted = NULL;
9531027

954-
last_errcode = 0;
955-
last_errdepth = 0;
956-
1028+
err_index = 0;
9571029
ExpectTrue((fp = XFOPEN(srvfile, "rb"))
9581030
!= XBADFILE);
9591031
ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
@@ -978,7 +1050,8 @@ int test_X509_STORE_InvalidCa(void)
9781050

9791051
ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
9801052
ExpectIntEQ(X509_verify_cert(ctx), 1);
981-
ExpectIntEQ(last_errcode, X509_V_ERR_INVALID_CA);
1053+
ExpectIntEQ(err_index, 1);
1054+
ExpectIntEQ(last_errcode[err_index - 1], X509_V_ERR_INVALID_CA);
9821055

9831056
X509_free(cert);
9841057
X509_STORE_free(str);

0 commit comments

Comments
 (0)