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 support for MesaLink as a TLS backend #280

Merged
merged 7 commits into from
Aug 19, 2019
Merged

Add support for MesaLink as a TLS backend #280

merged 7 commits into from
Aug 19, 2019

Conversation

sagebind
Copy link
Collaborator

@sagebind sagebind commented Aug 4, 2019

This adds support for compiling libcurl with MesaLink as the TLS backend on all platforms, disabled by default using a crate feature.

This is a potentially valuable feature for several reasons:

  • MesaLink is written primarily in Rust and uses rustls under the hood, so we can benefit from the security, safety, ans performance it offers even in curl.
  • Less compile-time and run-time dependencies. We can always link MesaLink statically on any supported platform, and MesaLink can be compiled with just Rust, gcc, and a few build tools installed. Curl also no longer needs openssl headers installed on the build system.

Note that using MesaLink also requires using the bundled curl version statically (e.g. the static-curl feature).

This is a work-in-progress. I've compiled and ran some binaries using a setup like this with great success so far, very smooth. The primary difficulty I am working out is how to "vendor" MesaLink like we do curl; with curl we just run the required commands inside build.rs, but MesaLink is a Rust project. Do we run Cargo commands inside build.rs inside Cargo? Right now I am using path dependencies, but those are not allowed when publishing to crates.io.

This adds support for compiling libcurl with MesaLink as the TLS backend on all platforms, disabled by default using a crate feature.
@alexcrichton
Copy link
Owner

Thanks for this!

This seems fine to add, and yeah the tricky part here is going to be the build. I'm also worried about the libstd in Rust and how we don't want to duplicate it by accident or cause it to be built twice. Ideally we'd build a crates.io shim which pulls in the C symbols for the library to use, and that way we'd ensure we only link libstd once. Otherwise calling Cargo-in-Cargo I think should probably be avoided.

Could this perhaps assume that there's a dylib pre-installed and work with that for now?

@sagebind
Copy link
Collaborator Author

sagebind commented Aug 8, 2019

That certainly could be a first iteration, though MesaLink is much more likely to be used statically linked, as it is not packaged for installation in most systems and is unlikely to be available on the target system.

@alexcrichton
Copy link
Owner

Do you know if mesalink has documentation about how to be consumed in a Rust project? I'm curious if the pieces of handling libstd and this sort of integration has been handled before.

@sagebind
Copy link
Collaborator Author

sagebind commented Aug 8, 2019

Not from what I've found, this might be the first time MesaLink would be used in this type of scenario. I decided to open an issue on their repo too to see if they have any thoughts on this use-case: mesalock-linux/mesalink#28

@sagebind
Copy link
Collaborator Author

OK, the good people over at MesaLink have published a Crates.io specific version of 1.0.0 that uses the upstream versions of Rustls and friends, with a few features disabled until a better solution arises. These features are not needed by curl, so I think it may be possible now to roll with what we have so far so that we can start experimenting with the mesalink feature.

I decided to copy and paste the generated MesaLink C headers for curl's consumption, as pulling in MesaLink as a submodule just for those headers did not seem like it was worth it to me.

I also did not artificially restrict MesaLink to any particular platforms, as in theory it should support most platforms (though not guaranteed).

@sagebind sagebind marked this pull request as ready for review August 14, 2019 04:21
@alexcrichton
Copy link
Owner

Nice! Since this is all relatively security sensitive though it seems like it'd be best if we could avoid copying the headers around. I wonder if the mesalink folks would be interested in shipping the header files with the crate itself (perhaps as part of the publication process) and then we could use the header files from the crate?

@sagebind
Copy link
Collaborator Author

Agreed, that's definitely the better solution. In theory it should be doable inside their build.rs like a typical -sys crate might. I'll go down that route first before continuing.

Point to a MesaLink fork with the changes until they are published.
@alexcrichton
Copy link
Owner

👍

Looks great!

@sagebind
Copy link
Collaborator Author

OK, this PR should be ready now that MesaLink 1.1.0-cratesio has been published with everything we need.

@alexcrichton alexcrichton merged commit 20162df into alexcrichton:master Aug 19, 2019
@alexcrichton
Copy link
Owner

Nice!

@sagebind sagebind deleted the mesalink-ssl branch September 14, 2019 00:06
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.

2 participants