-
Notifications
You must be signed in to change notification settings - Fork 901
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12930,6 +12930,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl) | |
|
|
||
| void wolfSSL_CTX_set_cert_store(WOLFSSL_CTX* ctx, WOLFSSL_X509_STORE* str) | ||
| { | ||
| WOLFSSL_X509 *x = NULL; | ||
| WOLFSSL_ENTER("wolfSSL_CTX_set_cert_store"); | ||
| if (ctx == NULL || str == NULL || ctx->cm == str->cm) { | ||
| return; | ||
|
|
@@ -12946,6 +12947,26 @@ int wolfSSL_set_compression(WOLFSSL* ssl) | |
| ctx->cm = str->cm; | ||
| ctx->x509_store.cm = str->cm; | ||
|
|
||
| /* wolfSSL_CTX_set_cert_store() (this function) associates str with the | ||
| * wolfSSL_CTX. It is clear that this is a TLS use case which means we | ||
| * should move all the certs, if any, into the CertMgr and set | ||
| * str->certs to NULL as that will allow the certs to be properly | ||
| * processed. */ | ||
| if (str->certs != NULL) { | ||
| while (wolfSSL_sk_X509_num(str->certs) > 0) { | ||
| int ret; | ||
| x = wolfSSL_sk_X509_pop(str->certs); | ||
| ret = X509StoreAddCa(str, x, WOLFSSL_USER_CA); | ||
| if (ret != WOLFSSL_SUCCESS) { | ||
| WOLFSSL_MSG("Error adding CA certificate to store"); | ||
| wolfSSL_X509_free(x); /* Free the certificate to avoid memory leaks */ | ||
| break; /* Exit the loop on failure */ | ||
| } | ||
| } | ||
| wolfSSL_sk_X509_pop_free(str->certs, NULL); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| str->certs = NULL; | ||
| } | ||
|
|
||
| /* free existing store if it exists */ | ||
| wolfSSL_X509_STORE_free(ctx->x509_store_pt); | ||
| ctx->x509_store.cache = str->cache; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28772,6 +28772,47 @@ static int test_wolfSSL_CTX_set_srp_password(void) | |
| return EXPECT_RESULT(); | ||
| } | ||
|
|
||
| static int test_wolfSSL_CTX_set_cert_store_null_certs(void) | ||
| { | ||
| EXPECT_DECLS; | ||
| #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_TLS) && \ | ||
| !defined(NO_WOLFSSL_SERVER) | ||
| X509_STORE *store = NULL; | ||
| WOLFSSL_CTX *ctx = NULL; | ||
| WOLFSSL_METHOD *method = NULL; | ||
| X509 *cert = NULL; | ||
| const char caCert[] = "./certs/ca-cert.pem"; | ||
|
|
||
| /* Create a new X509_STORE */ | ||
| ExpectNotNull(store = X509_STORE_new()); | ||
|
|
||
| /* Load a certificate */ | ||
| ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(caCert, | ||
| SSL_FILETYPE_PEM)); | ||
|
|
||
| /* Add the certificate to the store */ | ||
| ExpectIntEQ(X509_STORE_add_cert(store, cert), SSL_SUCCESS); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :
then
Where a cert store is assigned to the WOLFSSL_CTX struct and after it is assigned to it there is certificates added. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ExpectNotNull(store->certs); | ||
|
|
||
| /* Create a new SSL_CTX */ | ||
| ExpectNotNull(method = wolfSSLv23_server_method()); | ||
| ExpectNotNull(ctx = wolfSSL_CTX_new(method)); | ||
|
|
||
| /* Set the store in the SSL_CTX */ | ||
| wolfSSL_CTX_set_cert_store(ctx, store); | ||
|
|
||
| /* Verify that the certs member of the store is null */ | ||
| ExpectNull(store->certs); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| /* Clean up */ | ||
| wolfSSL_CTX_free(ctx); | ||
| X509_free(cert); | ||
|
|
||
| #endif | ||
| return EXPECT_RESULT(); | ||
| } | ||
|
|
||
|
|
||
| static int test_wolfSSL_X509_STORE(void) | ||
| { | ||
| EXPECT_DECLS; | ||
|
|
@@ -67534,6 +67575,7 @@ TEST_CASE testCases[] = { | |
| TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip), | ||
| TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store), | ||
| TEST_DECL(test_wolfSSL_X509_STORE), | ||
| TEST_DECL(test_wolfSSL_CTX_set_cert_store_null_certs), | ||
| TEST_DECL(test_wolfSSL_X509_STORE_load_locations), | ||
| TEST_DECL(test_X509_STORE_get0_objects), | ||
| TEST_DECL(test_wolfSSL_X509_load_crl_file), | ||
|
|
||
There was a problem hiding this comment.
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 fortrusted, and one namedowned. Are we sure that it is thecertsstack that should get added as CA's?There was a problem hiding this comment.
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.