Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for enabling and disabling CRLs. #6329

Merged
merged 5 commits into from
Jun 28, 2023
Merged

Conversation

tmael
Copy link
Contributor

@tmael tmael commented Apr 21, 2023

Description

This PR adds the ability to turn CRL checks on or off from X509_STORE during runtime. This functionality would be consistent with OpenSSL. By default, the CRL check is enabled when wolfSSL is configured with HAVE_CRL. wolfSSL_DisableCRL() can be used to disable CRL check on SSL object but we are missing an ability to turn it off for a WOLFSSL_X509_STORE object.

Fixes zd#15424

Testing

How did you test?

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@tmael tmael self-assigned this Apr 21, 2023
@julek-wolfssl julek-wolfssl self-requested a review May 8, 2023 17:26
@tmael
Copy link
Contributor Author

tmael commented May 25, 2023

retest this please!

src/internal.c Outdated Show resolved Hide resolved
src/internal.c Outdated Show resolved Hide resolved
src/ssl.c Outdated Show resolved Hide resolved
src/ssl.c Outdated Show resolved Hide resolved
src/ssl.c Outdated Show resolved Hide resolved
@tmael
Copy link
Contributor Author

tmael commented Jun 2, 2023

retest this please!

Copy link
Contributor

@kareem-wolfssl kareem-wolfssl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good Tesfa, just a few questions and potential changes.

src/ssl.c Outdated Show resolved Hide resolved
src/ssl.c Outdated Show resolved Hide resolved
src/x509_str.c Show resolved Hide resolved
src/x509_str.c Outdated
if ((flag & WOLFSSL_CRL_CHECKALL) || (flag & WOLFSSL_CRL_CHECK)) {
ret = wolfSSL_CertManagerEnableCRL(store->cm, (int)flag);
}
ret = wolfSSL_CertManagerEnableCRL(store->cm, (int)flag);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to make this change, considering the new behavior only applies when OPENSSL_COMPATIBLE_DEFAULTS is defined? Shouldn't this also be gated behind OPENSSL_COMPATIBLE_DEFAULTS?

Copy link
Contributor Author

@tmael tmael Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OPENSSL_COMPATIBLE_DEFAULTS flag is unnecessary here because wolfSSL_CertManagerEnableCRL() does not utilize the provided flag when OPENSSL_COMPATIBLE_DEFAULTS is not defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, wolfSSL_CertManagerEnableCRL is only being called if either WOLFSSL_CRL_CHECKALL or WOLFSSL_CRL_CHECK is set. But after this change, wolfSSL_CertManagerEnableCRL is always being called. In the case where OPENSSL_COMPATIBLE_DEFAULTS is not defined, calling wolfSSL_CertManagerEnableCRL will enable the CRL, so this is leading to a behavior change for that case. The function X509_STORE_set_flags is used for other X509 flags unrelated to CRL, and it is not expected to enable the CRL in this case.

Is there a reason you need to remove the flag check? If I'm understanding right, this should work fine in both cases with this check kept.

@tmael
Copy link
Contributor Author

tmael commented Jun 8, 2023

retest this please!

/* Turn off all checks */
cm->crlCheckAll = 0;
}
#endif
#ifdef HAVE_CRL
if (cm->crl == NULL) {
cm->crl = (WOLFSSL_CRL*)XMALLOC(sizeof(WOLFSSL_CRL), cm->heap,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If OPENSSL_COMPATIBLE_DEFAULTS is defined, and we don't end up enabling CRL, is there any point in allocating and initializing the cert manager's CRL? Or should the entire function be skipped in this case? I'm not seeing anywhere else in the code where we set crlEnabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kareem-wolfssl. Excellent observation! Your feedback has been implemented in the update.

src/x509_str.c Outdated
if ((flag & WOLFSSL_CRL_CHECKALL) || (flag & WOLFSSL_CRL_CHECK)) {
ret = wolfSSL_CertManagerEnableCRL(store->cm, (int)flag);
}
ret = wolfSSL_CertManagerEnableCRL(store->cm, (int)flag);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, wolfSSL_CertManagerEnableCRL is only being called if either WOLFSSL_CRL_CHECKALL or WOLFSSL_CRL_CHECK is set. But after this change, wolfSSL_CertManagerEnableCRL is always being called. In the case where OPENSSL_COMPATIBLE_DEFAULTS is not defined, calling wolfSSL_CertManagerEnableCRL will enable the CRL, so this is leading to a behavior change for that case. The function X509_STORE_set_flags is used for other X509 flags unrelated to CRL, and it is not expected to enable the CRL in this case.

Is there a reason you need to remove the flag check? If I'm understanding right, this should work fine in both cases with this check kept.

@tmael tmael requested a review from kareem-wolfssl June 9, 2023 17:18
@tmael tmael removed their assignment Jun 13, 2023
src/internal.c Show resolved Hide resolved
src/ssl.c Outdated Show resolved Hide resolved
src/ssl.c Show resolved Hide resolved
src/x509.c Show resolved Hide resolved
src/x509_str.c Outdated Show resolved Hide resolved
@julek-wolfssl julek-wolfssl assigned tmael and unassigned julek-wolfssl Jun 16, 2023
@tmael tmael assigned julek-wolfssl and unassigned tmael Jun 16, 2023
@tmael tmael requested a review from julek-wolfssl June 16, 2023 23:44
src/x509_str.c Show resolved Hide resolved
src/internal.c Outdated
Comment on lines 6240 to 6246
else {
#ifdef WOLFSSL_REFCNT_ERROR_RETURN
return ret;
#else
(void)ret;
#endif
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the return value logic needs to be gated on WOLFSSL_REFCNT_ERROR_RETURN. I can see that this follows a similar pattern that happens in many other places. I'm not a fan of this but I'll allow it for now.

Copy link
Member

@julek-wolfssl julek-wolfssl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of my previous reviews have been addressed yet.

Do leaf CRL check by default
Correct wolfSSL_sk_X509_NAME_push return check
Update OpenSSL compatibility errors for HAProxy
Change X509_V to literal constant values
Fix the compat layer with TLS session ticket reuse
Fix for tls1_2 session resume and cache miss
Save intitial wolfSSL ctx
Check for OpenSSL CRL error code 23
#ifndef NO_WOLFSSL_SERVER
#if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
#if !defined(NO_WOLFSSL_SERVER) && defined(HAVE_SESSION_TICKET)
#if defined(WOLFSSL_HAPROXY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we support a way to use initial_ctx with a macro besides WOLFSSL_HAPROXY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgarske, not in this PR. More comfortable with the current changes since it has been tested against Haproxy.

Copy link
Contributor

@dgarske dgarske Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems shortsighted to limit that area of code to HAPROXY only. Could you instead create a new macro like WOLFSSL_TICKET_USE_INITIAL_CTX and set this macro in settings.h for WOLFSSL_HAPROXY? At least giving other OSP projects the opportunity to use it?

Copy link
Contributor Author

@tmael tmael Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the use case for initial_ctx is quite rare, and I'm skeptical about its use in other OSP projects.
Currently, #define SSL_TICKET_CTX(ssl) ssl->initial_ctx->ticketEncCtx , initial_ctx, and ssl->initial_ctx are gated by WOLFSSL_HAPROXY. Are you suggesting alterations to the gating for all of these?
If that's the case, I can replace the WOLFSSL_HAPROXY gating with WOLFSSL_USE_INITIAL_CTX, which would provide a bit more flexibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, looking for flexibility around the use of the initial_ctx feature. Its a fairly easy refactor. If you think HAPROXY is the only project that will ever use this feature then we can take the PR as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying. Currently, I'm inclined to leave it as-is and consider the easy refactor only when necessary. None of our supported OSP projects require it presently, and if they had, we would have run into issues earlier. I can't predict the needs of future OSP projects. Although introducing a new setting is straightforward, it implies the added responsibility of maintenance and instructing non-configure autotool users to add one more setting to their user_settings.h file.

@dgarske dgarske assigned julek-wolfssl and unassigned dgarske Jun 28, 2023
@julek-wolfssl julek-wolfssl assigned tmael and unassigned julek-wolfssl Jun 28, 2023
@julek-wolfssl
Copy link
Member

@dgarske
Reassigning to @tmael as this is his PR.

@tmael tmael assigned dgarske and unassigned tmael Jun 28, 2023
@dgarske dgarske assigned tmael and unassigned dgarske Jun 28, 2023
@dgarske dgarske merged commit 048083c into wolfSSL:master Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants