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

SSL Context Callback #1021

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

SSL Context Callback #1021

wants to merge 8 commits into from

Conversation

COM8
Copy link
Member

@COM8 COM8 commented Jan 28, 2024

Implements #1019.

As an extension to #1020 this PR adds a function that gets called by libcurl just before the initialization of an SSL connection after having processed all other SSL related options to give a last chance to an application to modify the behavior of the SSL initialization.

Ref: https://curl.se/libcurl/c/CURLOPT_SSL_CTX_FUNCTION.html

How to use:

    size_t count{0};
    cpr::ssl::SslCtxCallback sslCtxCb{[](const std::shared_ptr<cpr::CurlHolder>& /*curl_holder*/, void* /*ssl_ctx*/, intptr_t userdata) {
                                          // NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
                                          size_t* count = reinterpret_cast<size_t*>(userdata);
                                          (*count)++;
                                          return CURLE_OK;
                                      },
                                      // NOLINTNEXTLINE (cppcoreguidelines-pro-type-reinterpret-cast)
                                      reinterpret_cast<intptr_t>(&count)};

    cpr::SslOptions sslOpts = cpr::Ssl(sslCtxCb);

    cpr::Get(url, sslOpts);
    EXPECT_EQ(count, 1);

This option is incompatible with cpr::ssl::CaBuffer. In case both options are present an instance of std::logic_error gets thrown while performing the request.

@COM8 COM8 added this to the CPR 1.11.0 milestone Jan 28, 2024
@COM8 COM8 self-assigned this Jan 28, 2024
@COM8 COM8 mentioned this pull request Jan 28, 2024
@COM8
Copy link
Member Author

COM8 commented Feb 4, 2024

Docs: libcpr/docs#44

@COM8
Copy link
Member Author

COM8 commented Feb 4, 2024

Currently still WIP since something seams to be broken when using this functionality when cpr is used via fetch content e.g. in our example repo.

Unit tests as well as sanitizers do not find anything yet...

@COM8 COM8 force-pushed the feature/ssl_ctx_callback branch 2 times, most recently from 4b2f86c to 4a460b7 Compare May 30, 2024 04:58
@COM8 COM8 force-pushed the feature/ssl_ctx_callback branch from 0bd7dcb to eebff44 Compare July 10, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants