Skip to content

Implement custom certificate handler option - #42

Merged
simon-lemay-unity merged 2 commits into
masterfrom
unity/custom-cert-handler-option
Sep 1, 2026
Merged

Implement custom certificate handler option#42
simon-lemay-unity merged 2 commits into
masterfrom
unity/custom-cert-handler-option

Conversation

@simon-lemay-unity

Copy link
Copy Markdown

Currently in UnityWebRequest we grab the SSL context object from the backend (using SSL_CTX_FUNCTION) and set a custom certificate handler through that. In our builds of Curl, the backend is always UnityTLS so this works well.

However if we wanted to switch backends on some platforms, it could be problematic. The Schannel backend doesn't offer a SSL context object, and while the OpenSSL one does, it's obviously its own object type and would require custom code in UnityWebRequest to hook up correctly (code that would need to be aware of the OpenSSL API).

Instead I'd like to propose a different approach: introduce a new Unity-only Curl option to set a custom certificate validation callback. And then hook up that validation callback in every backend that we might use. This addresses the current limitation of the Schannel backend, while also making the UnityWebRequest code agnostic to the backend being used.

Of course, it also means more invasive changes to upstream Curl code, which might represent a maintenance cost when updating to new versions. I've tried to keep the changes so that they're unlikely to conflict when these files churn. (Also in terms of maintenance cost, it could be argued that maintaining our own entire VTLS backend is more work than dealing with a few patches to existing ones.)

@Petezah Petezah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Seems pretty sane to me actually. The changes are fairly minimal, and express intent a lot more clearly than a piecemeal approach we've tended to do. I have a minor suggestion before I approve, but I won't push back if you think it's not beneficial.

Comment thread include/curl/curl.h
mbedtls_ssl_config */
void *userptr);

/* Unity extension: CURLOPT_UNITY_CERTVERIFY_FUNCTION callback prototype.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

An idea: What if we wrap all these blocks in #if USE_UNITY_CERTVERIFY? Then we can easily find all the modified blocks for maintenance purposes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good idea! Put all new code behind UNITY_CERTVERIFY.

@fadedreamz

Copy link
Copy Markdown

looks good to me, easy to follow and make sense. One trade-off of this unification is that it may become a tid bit more work to upgrade curl in future, but I don't have a good proposal except what peter has suggested above.

@simon-lemay-unity
simon-lemay-unity merged commit fa94e3b into master Sep 1, 2026
23 of 175 checks passed
@simon-lemay-unity
simon-lemay-unity deleted the unity/custom-cert-handler-option branch September 1, 2026 18:34
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.

3 participants