Skip to content

In wolfSSL_CTX_set_cert_store, send certificates into the CertMgr #8708

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

anhu
Copy link
Member

@anhu anhu commented Apr 23, 2025

Fixes ZD 19760

Before this fix, the certificates were not getting into the certificate manager. This makes sure they are going in.

@anhu anhu self-assigned this Apr 23, 2025
@anhu
Copy link
Member Author

anhu commented Apr 24, 2025

Will need to add test so that will kick off another round of PRB

Found unhandled org.jenkinsci.plugins.workflow.support.steps.AgentOfflineException exception:

@anhu anhu force-pushed the wolfSSL_CTX_set_cert_store branch from 6eda342 to f83ebb2 Compare April 24, 2025 19:02
@anhu
Copy link
Member Author

anhu commented May 12, 2025

Jenkins retest this please

(lost the build data)

@anhu
Copy link
Member Author

anhu commented May 13, 2025

Jenkins retest this please

java.io.StreamCorruptedException: invalid stream header: 636F7272

@anhu anhu force-pushed the wolfSSL_CTX_set_cert_store branch 2 times, most recently from adc18d7 to c90fb03 Compare May 15, 2025 13:26
@anhu
Copy link
Member Author

anhu commented May 15, 2025

Jenkins retest this please

(aborted after 1.5 hours)

@anhu
Copy link
Member Author

anhu commented Jun 4, 2025

jenkins retest this please

@anhu anhu force-pushed the wolfSSL_CTX_set_cert_store branch from 8166be6 to 5e78122 Compare June 6, 2025 14:59
@anhu
Copy link
Member Author

anhu commented Jun 6, 2025

Jenkins retest this please

@anhu anhu assigned wolfSSL-Bot and unassigned anhu Jun 6, 2025
@JacobBarthelmeh JacobBarthelmeh requested a review from Copilot June 6, 2025 20:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for moving existing certificates into the CertMgr when setting a certificate store on an SSL context.

  • Introduces X509StoreAddCa and updates wolfSSL_sk_X509_num and wolfSSL_sk_X509_pop declarations
  • Modifies wolfSSL_CTX_set_cert_store to transfer all stored certs into the CertMgr and clear the original stack
  • Adds a unit test to verify the store’s cert stack is cleared after calling wolfSSL_CTX_set_cert_store

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
wolfssl/ssl.h Moved declaration of wolfSSL_sk_X509_num out of the legacy block
wolfssl/internal.h Declared X509StoreAddCa for internal CertMgr additions
tests/api.c Added test_wolfSSL_CTX_set_cert_store_null_certs
src/x509_str.c Implemented X509StoreAddCa and removed duplicate static copy
src/x509.c Added wolfSSL_sk_X509_pop wrapper and extended sk_X509_num scope
src/ssl.c Updated wolfSSL_CTX_set_cert_store to move certs into CertMgr
Comments suppressed due to low confidence (2)

tests/api.c:28775

  • The new test only verifies that store->certs is set to NULL; consider adding a complementary test case to confirm that certificates are actually added into the internal CertMgr (e.g., by inspecting ctx->cm).
static int test_wolfSSL_CTX_set_cert_store_null_certs(void)

src/x509.c:4180

  • The function signature for wolfSSL_sk_X509_pop uses WOLFSSL_X509_NAME instead of WOLFSSL_X509. This mismatch may cause invalid casts or runtime errors. Update the parameter to WOLF_STACK_OF(WOLFSSL_X509)* sk.
WOLFSSL_X509* wolfSSL_sk_X509_pop(WOLF_STACK_OF(WOLFSSL_X509_NAME)* sk)

anhu and others added 2 commits June 6, 2025 16:23
Don't ignore return code.

Co-authored-by: Copilot <[email protected]>
SSL_FILETYPE_PEM));

/* Add the certificate to the store */
ExpectIntEQ(X509_STORE_add_cert(store, cert), SSL_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was looking over the support case referenced and I don't think this test reflects the edge case reported. It looks like we should be testing the order of :

wolfSSL_CTX_set_cert_store(ctx, store);

then

X509_STORE_add_cert(store, cert)

Where a cert store is assigned to the WOLFSSL_CTX struct and after it is assigned to it there is certificates added.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to be tricky or even impossible to fully support with the current design. X509_STORE owned by SSL_CTX expects everything to be in underlying CM, while X509_STORE not-owned expects them in str->certs. I should say this flow will work for TLS, but setting a X509_STORE inside a SSL_CTX, then expecting direct X509_STORE APIs to work right is likely not going to work with current model.

if (str->certs != NULL) {
while (wolfSSL_sk_X509_num(str->certs) > 0) {
int ret;
x = wolfSSL_sk_X509_pop(str->certs);
Copy link
Contributor

Choose a reason for hiding this comment

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

The cert store has 3 X509 stacks, one for certs, one for trusted, and one named owned. Are we sure that it is the certs stack that should get added as CA's?

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, certs should get added but trusted should also.

break; /* Exit the loop on failure */
}
}
wolfSSL_sk_X509_pop_free(str->certs, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the certs stack need free'd and emptied here? Is it being converted over to a WOLFSSL_CTX cert store, and that future calls to wolfSSL_X509_STORE_add_cert would then load certs as a CA?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it would be worth checking if this behavior conforms to the expected OpenSSL compat behavior. Attempting untrusted vs trusted self signed certificate loads after the store is set to the WOLFSSL_CTX struct.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a concept of SSL_CTX owned X509_STORE vs non-owned. While confusing, it was done this way to leave all existing code for TLS and CM usage unmodified. To determine if X509_STORE is owned by SSL_CTX or not, we do NULL checks on str->certs. So that is why it needs to be pop_freed here, otherwise logic in X509_STORE wont work right.

wolfSSL_CTX_set_cert_store(ctx, store);

/* Verify that the certs member of the store is null */
ExpectNull(store->certs);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be testing a successful verification making use of the loaded CA's.

@JacobBarthelmeh JacobBarthelmeh assigned anhu and unassigned wolfSSL-Bot Jun 6, 2025
@anhu anhu assigned ColtonWilley and unassigned anhu Jun 23, 2025
@anhu
Copy link
Member Author

anhu commented Jun 23, 2025

Assigned to @ColtonWilley as agreed in offline conversation.

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