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 set_cert_verify_callback (SSL_CTX_set_cert_verify) #287

Merged

Conversation

semaj-cf
Copy link
Contributor

@semaj-cf semaj-cf commented Oct 21, 2024

Add a wrapper for SSL_CTX_set_cert_verify, which allows consumers to override the default certificate verification behavior.

The binding resembles SSL_CTX_set_verify's.

See
https://docs.openssl.org/master/man3/SSL_CTX_set_cert_verify_callback/ for more details.

@semaj-cf
Copy link
Contributor Author

failing build looks related to: #285

///
/// This method panics if this `SslContext` is associated with a RPK context.
#[corresponds(SSL_CTX_set_cert_verify_callback)]
pub fn set_cert_verify_callback<F>(&mut self, callback: F)
Copy link
Member

Choose a reason for hiding this comment

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

You can unset by passing NULL, but that's not possible with this binding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems we either change this to Option or add another function that unsets this callback. Changing this to Option seems to make Rust unable to reason about arguments to this function when it is called, requiring type annotations (which are onerous when you just want to pass None).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a TODO

#[cfg(feature = "rpk")]
assert!(!self.is_rpk, "This API is not supported for RPK");

self.replace_ex_data(SslContext::cached_ex_index::<F>(), callback);
Copy link
Member

Choose a reason for hiding this comment

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

set_verify_callback uses

            // this needs to be in an Arc since the callback can register a new callback!
            self.replace_ex_data(Ssl::cached_ex_index(), Arc::new(callback)); 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from my digging, this is copy-pasta. see this comment by @nox https://github.com/cloudflare/boring/blob/master/boring/src/ssl/callbacks.rs#L200-L202

I agree that it is impossible to get a mutable reference to an SslRef or SslContextRef, so I don't see why this needs to be an Arc. I am happy to make it one just to be safe, though

Copy link
Member

Choose a reason for hiding this comment

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

Add a comment with the reference.

@semaj-cf semaj-cf force-pushed the expose-set-cert-verify-callback branch 2 times, most recently from f1e0e77 to d18dca5 Compare October 21, 2024 17:41
@@ -64,6 +64,34 @@ where
unsafe { raw_custom_verify_callback(ssl, out_alert, callback) }
}

pub(super) unsafe extern "C" fn cert_verify<F>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub(super) unsafe extern "C" fn cert_verify<F>(
pub(super) unsafe extern "C" fn raw_cert_verify<F>(

@semaj-cf semaj-cf force-pushed the expose-set-cert-verify-callback branch 2 times, most recently from e7e68e5 to aa7431f Compare October 21, 2024 17:57
Add a wrapper for `SSL_CTX_set_cert_verify`, which allows consumers to
override the default certificate verification behavior.

The binding resembles `SSL_CTX_set_verify`'s.

See
https://docs.openssl.org/master/man3/SSL_CTX_set_cert_verify_callback/
for more details.
@semaj-cf semaj-cf force-pushed the expose-set-cert-verify-callback branch from aa7431f to 921ebbd Compare October 21, 2024 17:58
@rushilmehra rushilmehra merged commit bb373e5 into cloudflare:master Oct 22, 2024
22 of 23 checks passed
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.

3 participants