Skip to content

Commit 30fe079

Browse files
committed
Addressed review comments
1 parent 10d3e25 commit 30fe079

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

src/x509_str.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ 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)
387+
#if defined(OPENSSL_ALL)
388388
else {
389389
WOLFSSL_MSG("Using system time for date validation");
390390
/* use system time for date validation */
@@ -438,18 +438,24 @@ static int X509StoreVerifyCert(WOLFSSL_X509_STORE_CTX* ctx)
438438
WOLFSSL_SUCCESS : ret;
439439
#endif
440440
}
441-
#if !defined(NO_ASN_TIME) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT))
441+
#if !defined(NO_ASN_TIME) && defined(OPENSSL_ALL)
442442
if (ret != WC_NO_ERR_TRACE(ASN_BEFORE_DATE_E) &&
443443
ret != WC_NO_ERR_TRACE(ASN_AFTER_DATE_E)) {
444-
/* With Qt and OpenSSL, we need to check the certificate's date
444+
/* With OpenSSL, we need to check the certificate's date
445445
* after certificate manager verification,
446446
* as it skips date validation when other errors are present.
447447
*/
448448
ret = X509StoreVerifyCertDate(ctx, ret);
449449
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;
450+
ret = ret == WOLFSSL_SUCCESS ? 1 : 0;
451+
if (ctx->store->verify_cb) {
452+
if (ctx->store->verify_cb(ret, ctx) == 1) {
453+
ret = WOLFSSL_SUCCESS;
454+
}
455+
else {
456+
ret = -1;
457+
}
458+
}
453459
}
454460
#endif
455461
return ret;

tests/api/test_ossl_x509_str.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,36 @@
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];
4446
static int err_index = 0;
4547

4648
static 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

5971
int 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

Comments
 (0)