Skip to content

Commit 048083c

Browse files
authored
Merge pull request #6329 from tmael/crl_off
Add support for enabling and disabling CRLs.
2 parents d029ba4 + 26e6fd9 commit 048083c

9 files changed

Lines changed: 163 additions & 60 deletions

File tree

scripts/crl-revoked.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cp -rp . $RUNNING_DIR/.
2222
cd $RUNNING_DIR
2323

2424
revocation_code="-361"
25+
revocation_code_openssl="23"
2526
exit_code=1
2627
counter=0
2728
# need a unique resume port since may run the same time as testsuite
@@ -112,7 +113,7 @@ run_test() {
112113
server_result=$?
113114

114115
case "$capture_out" in
115-
*$revocation_code*)
116+
*"$revocation_code"*|*"$revocation_code_openssl"*)
116117
# only exit with zero on detection of the expected error code
117118
echo ""
118119
echo "Successful Revocation!!!!"
@@ -178,7 +179,7 @@ run_hashdir_test() {
178179
server_result=$?
179180

180181
case "$capture_out" in
181-
*$revocation_code*)
182+
*"$revocation_code"*|*"$revocation_code_openssl"*)
182183
# only exit with zero on detection of the expected error code
183184
echo ""
184185
echo "Successful Revocation!!!! with hash dir"

src/internal.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,13 @@ WOLFSSL_CALLBACKS needs LARGE_STATIC_BUFFERS, please add LARGE_STATIC_BUFFERS
185185

186186
#endif /* !WOLFSSL_NO_TLS12 */
187187

188-
#ifndef NO_WOLFSSL_SERVER
189-
#if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
188+
#if !defined(NO_WOLFSSL_SERVER) && defined(HAVE_SESSION_TICKET)
189+
#if defined(WOLFSSL_HAPROXY)
190+
#define SSL_TICKET_CTX(ssl) ssl->initial_ctx->ticketEncCtx
191+
#else
192+
#define SSL_TICKET_CTX(ssl) ssl->ctx->ticketEncCtx
193+
#endif
194+
#if !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
190195
static int TicketEncCbCtx_Init(WOLFSSL_CTX* ctx,
191196
TicketEncCbCtx* keyCtx);
192197
static void TicketEncCbCtx_Free(TicketEncCbCtx* keyCtx);
@@ -6213,6 +6218,9 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
62136218
if (!newSSL) {
62146219
WOLFSSL_MSG("freeing old ctx to decrement reference count. Switching ctx.");
62156220
wolfSSL_CTX_free(ssl->ctx);
6221+
#if defined(WOLFSSL_HAPROXY)
6222+
wolfSSL_CTX_free(ssl->initial_ctx);
6223+
#endif
62166224
}
62176225

62186226
/* increment CTX reference count */
@@ -6229,6 +6237,20 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
62296237
ssl->ctx = ctx; /* only for passing to calls, options could change */
62306238
/* Don't change version on a SSL object that has already started a
62316239
* handshake */
6240+
#if defined(WOLFSSL_HAPROXY)
6241+
ret = wolfSSL_CTX_up_ref(ctx);
6242+
if (ret == WOLFSSL_SUCCESS) {
6243+
ssl->initial_ctx = ctx; /* Save access to session key materials */
6244+
}
6245+
else {
6246+
#ifdef WOLFSSL_REFCNT_ERROR_RETURN
6247+
return ret;
6248+
#else
6249+
(void)ret;
6250+
#endif
6251+
}
6252+
6253+
#endif
62326254
if (!ssl->msgsReceived.got_client_hello &&
62336255
!ssl->msgsReceived.got_server_hello)
62346256
ssl->version = ctx->method->version;
@@ -23135,6 +23157,8 @@ const char* wolfSSL_ERR_reason_error_string(unsigned long e)
2313523157
#ifdef OPENSSL_EXTRA
2313623158
case 0 :
2313723159
return "ok";
23160+
case -WOLFSSL_X509_V_ERR_CERT_REVOKED :
23161+
return "certificate revoked";
2313823162
#endif
2313923163

2314023164
case UNSUPPORTED_SUITE :
@@ -34639,7 +34663,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3463934663
if (error == 0) {
3464034664
ret = ssl->ctx->ticketEncCb(ssl, et->key_name, et->iv, et->mac,
3464134665
1, et->enc_ticket, sizeof(InternalTicket), &encLen,
34642-
ssl->ctx->ticketEncCtx);
34666+
SSL_TICKET_CTX(ssl));
3464334667
}
3464434668
else {
3464534669
ret = WOLFSSL_TICKET_RET_FATAL;
@@ -34764,7 +34788,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3476434788
ret = ssl->ctx->ticketEncCb((WOLFSSL*)ssl, et->key_name, et->iv,
3476534789
et->enc_ticket + inLen, 0,
3476634790
et->enc_ticket, inLen, &outLen,
34767-
ssl->ctx->ticketEncCtx);
34791+
SSL_TICKET_CTX(ssl));
3476834792
}
3476934793
if (ret != WOLFSSL_TICKET_RET_OK) {
3477034794
#ifdef WOLFSSL_ASYNC_CRYPT

src/ssl.c

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,7 +4509,11 @@ int wolfSSL_get_error(WOLFSSL* ssl, int ret)
45094509
return WOLFSSL_ERROR_WANT_WRITE; /* convert to OpenSSL type */
45104510
else if (ssl->error == ZERO_RETURN || ssl->options.shutdownDone)
45114511
return WOLFSSL_ERROR_ZERO_RETURN; /* convert to OpenSSL type */
4512-
return ssl->error;
4512+
#if defined(WOLFSSL_HAPROXY)
4513+
return GetX509Error(ssl->error);
4514+
#else
4515+
return (ssl->error);
4516+
#endif
45134517
}
45144518

45154519

@@ -8152,7 +8156,8 @@ int wolfSSL_CertManagerLoadCRLBuffer(WOLFSSL_CERT_MANAGER* cm,
81528156
return BAD_FUNC_ARG;
81538157

81548158
if (cm->crl == NULL) {
8155-
if (wolfSSL_CertManagerEnableCRL(cm, 0) != WOLFSSL_SUCCESS) {
8159+
if (wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK) !=
8160+
WOLFSSL_SUCCESS) {
81568161
WOLFSSL_MSG("Enable CRL failed");
81578162
return WOLFSSL_FATAL_ERROR;
81588163
}
@@ -8204,11 +8209,21 @@ int wolfSSL_CertManagerEnableCRL(WOLFSSL_CERT_MANAGER* cm, int options)
82048209
{
82058210
int ret = WOLFSSL_SUCCESS;
82068211

8207-
(void)options;
8208-
82098212
WOLFSSL_ENTER("wolfSSL_CertManagerEnableCRL");
82108213
if (cm == NULL)
82118214
return BAD_FUNC_ARG;
8215+
#if defined(OPENSSL_COMPATIBLE_DEFAULTS)
8216+
if (options == 0) {
8217+
8218+
/* Turn off doing Leaf CRL check */
8219+
cm->crlEnabled = 0;
8220+
/* Turn off all checks */
8221+
cm->crlCheckAll = 0;
8222+
return ret;
8223+
}
8224+
#else
8225+
(void)options;
8226+
#endif
82128227

82138228
#ifdef HAVE_CRL
82148229
if (cm->crl == NULL) {
@@ -8228,10 +8243,15 @@ int wolfSSL_CertManagerEnableCRL(WOLFSSL_CERT_MANAGER* cm, int options)
82288243
cm->crl->crlIOCb = EmbedCrlLookup;
82298244
#endif
82308245
}
8231-
8232-
cm->crlEnabled = 1;
8233-
if (options & WOLFSSL_CRL_CHECKALL)
8234-
cm->crlCheckAll = 1;
8246+
#if defined(OPENSSL_COMPATIBLE_DEFAULTS)
8247+
if ((options & WOLFSSL_CRL_CHECKALL) ||
8248+
(options & WOLFSSL_CRL_CHECK))
8249+
#endif
8250+
{
8251+
cm->crlEnabled = 1;
8252+
if (options & WOLFSSL_CRL_CHECKALL)
8253+
cm->crlCheckAll = 1;
8254+
}
82358255
#else
82368256
ret = NOT_COMPILED_IN;
82378257
#endif
@@ -9431,7 +9451,8 @@ int wolfSSL_CertManagerLoadCRL(WOLFSSL_CERT_MANAGER* cm, const char* path,
94319451
return BAD_FUNC_ARG;
94329452

94339453
if (cm->crl == NULL) {
9434-
if (wolfSSL_CertManagerEnableCRL(cm, 0) != WOLFSSL_SUCCESS) {
9454+
if (wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK)
9455+
!= WOLFSSL_SUCCESS) {
94359456
WOLFSSL_MSG("Enable CRL failed");
94369457
return WOLFSSL_FATAL_ERROR;
94379458
}
@@ -9448,7 +9469,8 @@ int wolfSSL_CertManagerLoadCRLFile(WOLFSSL_CERT_MANAGER* cm, const char* file,
94489469
return BAD_FUNC_ARG;
94499470

94509471
if (cm->crl == NULL) {
9451-
if (wolfSSL_CertManagerEnableCRL(cm, 0) != WOLFSSL_SUCCESS) {
9472+
if (wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK)
9473+
!= WOLFSSL_SUCCESS) {
94529474
WOLFSSL_MSG("Enable CRL failed");
94539475
return WOLFSSL_FATAL_ERROR;
94549476
}
@@ -14494,12 +14516,17 @@ void SetupSession(WOLFSSL* ssl)
1449414516

1449514517
WOLFSSL_ENTER("SetupSession");
1449614518

14497-
if (!IsAtLeastTLSv1_3(ssl->version) && ssl->arrays != NULL &&
14498-
!session->haveAltSessionID) {
14519+
if (!IsAtLeastTLSv1_3(ssl->version) && ssl->arrays != NULL) {
1449914520
/* Make sure the session ID is available when the user calls any
1450014521
* get_session API */
14501-
XMEMCPY(session->sessionID, ssl->arrays->sessionID, ID_LEN);
14502-
session->sessionIDSz = ssl->arrays->sessionIDSz;
14522+
if (!session->haveAltSessionID) {
14523+
XMEMCPY(session->sessionID, ssl->arrays->sessionID, ID_LEN);
14524+
session->sessionIDSz = ssl->arrays->sessionIDSz;
14525+
}
14526+
else {
14527+
XMEMCPY(session->sessionID, session->altSessionID, ID_LEN);
14528+
session->sessionIDSz = ID_LEN;
14529+
}
1450314530
}
1450414531
session->side = (byte)ssl->options.side;
1450514532
if (!IsAtLeastTLSv1_3(ssl->version) && ssl->arrays != NULL)
@@ -14904,7 +14931,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output)
1490414931
if (SslSessionCacheOff(ssl, ssl->session))
1490514932
return WOLFSSL_FAILURE;
1490614933

14907-
if (ssl->options.haveSessionId == 0)
14934+
if (ssl->options.haveSessionId == 0 && !ssl->session->haveAltSessionID)
1490814935
return WOLFSSL_FAILURE;
1490914936

1491014937
#ifdef HAVE_SESSION_TICKET
@@ -14913,7 +14940,8 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output)
1491314940
#endif
1491414941

1491514942
XMEMSET(bogusID, 0, sizeof(bogusID));
14916-
if (!IsAtLeastTLSv1_3(ssl->version) && ssl->arrays != NULL)
14943+
if (!IsAtLeastTLSv1_3(ssl->version) && ssl->arrays != NULL
14944+
&& !ssl->session->haveAltSessionID)
1491714945
id = ssl->arrays->sessionID;
1491814946
else if (ssl->session->haveAltSessionID) {
1491914947
id = ssl->session->altSessionID;
@@ -23116,8 +23144,9 @@ int wolfSSL_ERR_GET_REASON(unsigned long err)
2311623144
#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
2311723145
/* Nginx looks for this error to know to stop parsing certificates.
2311823146
* Same for HAProxy. */
23119-
if (err == ((ERR_LIB_PEM << 24) | PEM_R_NO_START_LINE)
23120-
|| (err & 0xFFFFFFL) == -ASN_NO_PEM_HEADER)
23147+
if (err == ((ERR_LIB_PEM << 24) | PEM_R_NO_START_LINE) ||
23148+
((err & 0xFFFFFFL) == -ASN_NO_PEM_HEADER) ||
23149+
((err & 0xFFFL) == PEM_R_NO_START_LINE ))
2312123150
return PEM_R_NO_START_LINE;
2312223151
if (err == ((ERR_LIB_SSL << 24) | -SSL_R_HTTP_REQUEST))
2312323152
return SSL_R_HTTP_REQUEST;
@@ -31248,6 +31277,9 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
3124831277
#endif
3124931278
if (ssl->ctx) {
3125031279
wolfSSL_CTX_free(ssl->ctx);
31280+
#if defined(WOLFSSL_HAPROXY)
31281+
wolfSSL_CTX_free(ssl->initial_ctx);
31282+
#endif
3125131283
}
3125231284
ssl->ctx = ctx;
3125331285

@@ -31450,6 +31482,12 @@ const byte* wolfSSL_SESSION_get_id(const WOLFSSL_SESSION* sess,
3145031482
WOLFSSL_MSG("Bad func args. Please provide idLen");
3145131483
return NULL;
3145231484
}
31485+
#ifdef HAVE_SESSION_TICKET
31486+
if (sess->haveAltSessionID) {
31487+
*idLen = ID_LEN;
31488+
return sess->altSessionID;
31489+
}
31490+
#endif
3145331491
*idLen = sess->sessionIDSz;
3145431492
return sess->sessionID;
3145531493
}

src/x509.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7028,7 +7028,8 @@ int wolfSSL_X509_LOOKUP_load_file(WOLFSSL_X509_LOOKUP* lookup,
70287028
WOLFSSL_CERT_MANAGER* cm = lookup->store->cm;
70297029

70307030
if (cm->crl == NULL) {
7031-
if (wolfSSL_CertManagerEnableCRL(cm, 0) != WOLFSSL_SUCCESS) {
7031+
if (wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK)
7032+
!= WOLFSSL_SUCCESS) {
70327033
WOLFSSL_MSG("Enable CRL failed");
70337034
goto end;
70347035
}
@@ -12440,7 +12441,7 @@ WOLF_STACK_OF(WOLFSSL_X509_NAME) *wolfSSL_dup_CA_list(
1244012441

1244112442
for (i = 0; i < num; i++) {
1244212443
name = wolfSSL_X509_NAME_dup(wolfSSL_sk_X509_NAME_value(sk, i));
12443-
if (name == NULL || 0 != wolfSSL_sk_X509_NAME_push(copy, name)) {
12444+
if (name == NULL || WOLFSSL_SUCCESS != wolfSSL_sk_X509_NAME_push(copy, name)) {
1244412445
WOLFSSL_MSG("Memory error");
1244512446
wolfSSL_sk_X509_NAME_pop_free(copy, wolfSSL_X509_NAME_free);
1244612447
return NULL;

src/x509_str.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int GetX509Error(int e)
170170
case ASN_BEFORE_DATE_E:
171171
return WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
172172
case ASN_AFTER_DATE_E:
173-
return WOLFSSL_X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
173+
return WOLFSSL_X509_V_ERR_CERT_HAS_EXPIRED;
174174
case ASN_NO_SIGNER_E: /* get issuer error if no CA found locally */
175175
return WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
176176
case ASN_SELF_SIGNED_E:
@@ -183,6 +183,8 @@ int GetX509Error(int e)
183183
case ASN_SIG_HASH_E:
184184
case ASN_SIG_KEY_E:
185185
return WOLFSSL_X509_V_ERR_CERT_SIGNATURE_FAILURE;
186+
case CRL_CERT_REVOKED:
187+
return WOLFSSL_X509_V_ERR_CERT_REVOKED;
186188
default:
187189
#ifdef HAVE_WOLFSSL_MSG_EX
188190
WOLFSSL_MSG_EX("Error not configured or implemented yet: %d", e);
@@ -980,7 +982,11 @@ int wolfSSL_X509_STORE_set_flags(WOLFSSL_X509_STORE* store, unsigned long flag)
980982
if ((flag & WOLFSSL_CRL_CHECKALL) || (flag & WOLFSSL_CRL_CHECK)) {
981983
ret = wolfSSL_CertManagerEnableCRL(store->cm, (int)flag);
982984
}
983-
985+
#if defined(OPENSSL_COMPATIBLE_DEFAULTS)
986+
else if (flag == 0) {
987+
ret = wolfSSL_CertManagerDisableCRL(store->cm);
988+
}
989+
#endif
984990
return ret;
985991
}
986992

@@ -1023,7 +1029,8 @@ WOLFSSL_API int wolfSSL_X509_STORE_load_locations(WOLFSSL_X509_STORE *str,
10231029

10241030
#ifdef HAVE_CRL
10251031
if (str->cm->crl == NULL) {
1026-
if (wolfSSL_CertManagerEnableCRL(str->cm, 0) != WOLFSSL_SUCCESS) {
1032+
if (wolfSSL_CertManagerEnableCRL(str->cm, WOLFSSL_CRL_CHECK)
1033+
!= WOLFSSL_SUCCESS) {
10271034
WOLFSSL_MSG("Enable CRL failed");
10281035
wolfSSL_CTX_free(ctx);
10291036
return WOLFSSL_FAILURE;

0 commit comments

Comments
 (0)