Skip to content

Commit d25f98f

Browse files
authored
Merge pull request #9584 from miyazakh/fix_qtfail
Fix qt jenkins nightly test failure
2 parents 133d29d + cdd75ff commit d25f98f

2 files changed

Lines changed: 133 additions & 1 deletion

File tree

src/x509_str.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,22 @@ static int X509StoreVerifyCertDate(WOLFSSL_X509_STORE_CTX* ctx, int ret)
384384
ret = ASN_BEFORE_DATE_E;
385385
}
386386
}
387+
#if defined(OPENSSL_ALL)
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,
393+
ctx->current_cert->notAfter.length) < 1) {
394+
ret = ASN_AFTER_DATE_E;
395+
}
396+
else if (wc_ValidateDate(beforeDate,
397+
(byte)ctx->current_cert->notBefore.type, ASN_BEFORE,
398+
ctx->current_cert->notBefore.length) < 1) {
399+
ret = ASN_BEFORE_DATE_E;
400+
}
401+
}
402+
#endif
387403
}
388404
#else
389405
if (XVALIDATE_DATE(afterDate,
@@ -424,7 +440,26 @@ static int X509StoreVerifyCert(WOLFSSL_X509_STORE_CTX* ctx)
424440
WOLFSSL_SUCCESS : ret;
425441
#endif
426442
}
427-
443+
#if !defined(NO_ASN_TIME) && defined(OPENSSL_ALL)
444+
if (ret != WC_NO_ERR_TRACE(ASN_BEFORE_DATE_E) &&
445+
ret != WC_NO_ERR_TRACE(ASN_AFTER_DATE_E)) {
446+
/* With OpenSSL, we need to check the certificate's date
447+
* after certificate manager verification,
448+
* as it skips date validation when other errors are present.
449+
*/
450+
ret = X509StoreVerifyCertDate(ctx, ret);
451+
SetupStoreCtxError(ctx, ret);
452+
ret = ret == WOLFSSL_SUCCESS ? 1 : 0;
453+
if (ctx->store->verify_cb) {
454+
if (ctx->store->verify_cb(ret, ctx) == 1) {
455+
ret = WOLFSSL_SUCCESS;
456+
}
457+
else {
458+
ret = -1;
459+
}
460+
}
461+
}
462+
#endif
428463
return ret;
429464
}
430465

tests/api/test_ossl_x509_str.c

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

39+
#if defined(OPENSSL_ALL) && \
40+
!defined(NO_RSA) && !defined(NO_FILESYSTEM)
41+
42+
static int last_errcodes[10];
43+
static int last_errdepths[10];
44+
static int err_index = 0;
45+
46+
static int X509CallbackCount(int ok, X509_STORE_CTX *ctx)
47+
{
48+
if (!ok) {
49+
if (err_index < 10) {
50+
last_errcodes[err_index] = X509_STORE_CTX_get_error(ctx);
51+
last_errdepths[err_index] = X509_STORE_CTX_get_error_depth(ctx);
52+
err_index++;
53+
} else {
54+
/* Should not happen in test */
55+
WOLFSSL_MSG("Error index overflow in X509CallbackCount");
56+
err_index = 0;
57+
}
58+
}
59+
/* Always return OK to allow verification to continue.*/
60+
return 1;
61+
}
62+
#endif
63+
3964
int test_wolfSSL_X509_STORE_CTX_set_time(void)
4065
{
4166
EXPECT_DECLS;
@@ -161,6 +186,78 @@ int test_wolfSSL_X509_STORE_check_time(void)
161186
store = NULL;
162187
wolfSSL_X509_free(cert);
163188
cert = NULL;
189+
190+
#if defined(OPENSSL_ALL) && \
191+
!defined(NO_RSA) && !defined(NO_FILESYSTEM)
192+
193+
err_index = 0;
194+
195+
ExpectNotNull(store = X509_STORE_new());
196+
ExpectNotNull(ctx = X509_STORE_CTX_new());
197+
ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
198+
SSL_FILETYPE_PEM));
199+
ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS);
200+
201+
X509_STORE_set_verify_cb(store, X509CallbackCount);
202+
203+
ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(expiredCertFile,
204+
SSL_FILETYPE_PEM));
205+
206+
ExpectIntEQ(X509_STORE_CTX_init(ctx, store, cert, NULL), WOLFSSL_SUCCESS);
207+
ExpectIntEQ(X509_verify_cert(ctx), WOLFSSL_SUCCESS);
208+
/* while verifying the certificate, it should have two errors */
209+
ExpectIntEQ(err_index, 2);
210+
/* self-signed */
211+
ExpectIntEQ(last_errcodes[err_index - 2],
212+
WOLFSSL_X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT);
213+
/* expired */
214+
ExpectIntEQ(last_errcodes[err_index - 1],
215+
WOLFSSL_X509_V_ERR_CERT_HAS_EXPIRED);
216+
217+
X509_STORE_CTX_free(ctx);
218+
ctx = NULL;
219+
X509_STORE_free(store);
220+
store = NULL;
221+
X509_free(cert);
222+
cert = NULL;
223+
X509_free(ca);
224+
ca = NULL;
225+
226+
err_index = 0;
227+
228+
ExpectNotNull(store = X509_STORE_new());
229+
/* Set NO_CHECK_TIME flag to skip time validation */
230+
ExpectIntEQ(X509_VERIFY_PARAM_set_flags(store->param,
231+
WOLFSSL_NO_CHECK_TIME), WOLFSSL_SUCCESS);
232+
ExpectTrue((store->param->flags & WOLFSSL_NO_CHECK_TIME) ==
233+
WOLFSSL_NO_CHECK_TIME);
234+
ExpectNotNull(ctx = X509_STORE_CTX_new());
235+
ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
236+
SSL_FILETYPE_PEM));
237+
ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, ca), WOLFSSL_SUCCESS);
238+
239+
X509_STORE_set_verify_cb(store, X509CallbackCount);
240+
241+
ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(expiredCertFile,
242+
SSL_FILETYPE_PEM));
243+
244+
ExpectIntEQ(X509_STORE_CTX_init(ctx, store, cert, NULL), WOLFSSL_SUCCESS);
245+
ExpectIntEQ(X509_verify_cert(ctx), WOLFSSL_SUCCESS);
246+
/* while verifying the certificate, it should have an error */
247+
ExpectIntEQ(err_index, 1);
248+
/* self-signed */
249+
ExpectIntEQ(last_errcodes[err_index - 1],
250+
WOLFSSL_X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT);
251+
/* no expired because of no_check_time */
252+
X509_STORE_CTX_free(ctx);
253+
ctx = NULL;
254+
X509_STORE_free(store);
255+
store = NULL;
256+
X509_free(cert);
257+
cert = NULL;
258+
X509_free(ca);
259+
ca = NULL;
260+
#endif
164261
#endif /* OPENSSL_EXTRA && !NO_FILESYSTEM && !NO_ASN_TIME && !NO_RSA */
165262
return EXPECT_RESULT();
166263
}

0 commit comments

Comments
 (0)