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

curl client checkpoint #1

Merged
merged 15 commits into from
Apr 3, 2024
Merged

curl client checkpoint #1

merged 15 commits into from
Apr 3, 2024

Conversation

ctz
Copy link
Member

@ctz ctz commented Feb 23, 2024

The commits here are kinda artificial for the purposes of review -- I started from a single commit that contained everything. So there's are some commits that introduce fully-fledged modules that only pay off later. That is especially true of ffi.rs, which is mostly cloned from rustls-ffi.

The initial commit currently on main also contains things wanting review -- please leave comments there and I will collect some fixes on this PR.

At the end of this branch, on ubuntu linux1 you should be able to:

$ make
(...)
$ LD_LIBRARY_PATH=target/debug curl https://google.com
[2024-02-23T16:42:51Z ERROR ssl::error] raising Error { lib: Ssl, reason: Unsupported, string: Some("_SSL_CTX_set_next_proto_select_cb") }
[2024-02-23T16:42:51Z ERROR ssl::error] raising Error { lib: Ssl, reason: Unsupported, string: Some("_SSL_CTX_set_post_handshake_auth") }
[2024-02-23T16:42:51Z ERROR ssl::error] raising Error { lib: Ssl, reason: Unsupported, string: Some("_SSL_CTX_sess_set_new_cb") }
[2024-02-23T16:42:51Z ERROR ssl::error] raising Error { lib: User, reason: OperationFailed, string: Some("operation would block") }
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
[2024-02-23T16:42:51Z ERROR ssl::error] raising Error { lib: User, reason: OperationFailed, string: Some("operation would block") }

In other words, the libssl.so.3 is enough to be a drop-in for really very basic uses of curl.

Footnotes

  1. others untested, but probably work

@cpu
Copy link
Member

cpu commented Feb 23, 2024

Nice! I will give this some 👀 early-to-mid next week.

@djc
Copy link
Member

djc commented Mar 20, 2024

Do we have a good rationale for keeping this work private? It's public in our roadmap, so might make sense to just make this repo public, too?

@cpu is this waiting for something in particular? ISTR that this is relatively high priority?

@cpu
Copy link
Member

cpu commented Mar 20, 2024

@cpu is this waiting for something in particular?

Sorry, this just fell off my task list when I went out of office. I will do a review pass today.

I don't have any preference w.r.t keeping the repo private or public in the meantime.

@ctz
Copy link
Member Author

ctz commented Mar 20, 2024

I don't mind making it public now, really. My thought was: in case the initial commit wants edits, that would mean force-pushing main. But likely not a big deal as I doubt there would be anyone looking at this repo until it contains something useful and substantial.

@djc
Copy link
Member

djc commented Mar 20, 2024

I don't mind making it public now, really. My thought was: in case the initial commit wants edits, that would mean force-pushing main. But likely not a big deal as I doubt there would be anyone looking at this repo until it contains something useful and substantial.

It sounds like we have at least a couple of people who would be looking at this repo today if they could, and I remember it came up one time before when I inadvertently linked to it. But yeah, force pushing main is probably okay for now.

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Phew, that's a lot to digest 😆 In general: this is really, really cool.

I left a lot of comments, some of them are actionable feedback, some of them are questions, and some are just me rubber ducking in the hopes it might save someone else reviewing this branch from chasing the same threads as I did. I hope it's useful!

rustls-libssl/src/constants.rs Outdated Show resolved Hide resolved
rustls-libssl/src/constants.rs Outdated Show resolved Hide resolved
rustls-libssl/src/constants.rs Outdated Show resolved Hide resolved
rustls-libssl/src/entry.rs Show resolved Hide resolved
rustls-libssl/src/entry.rs Outdated Show resolved Hide resolved
rustls-libssl/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +665 to +695
entry! {
pub fn _SSL_get_peer_cert_chain(ssl: *const SSL) -> *mut stack_st_X509 {
let ssl = try_clone_arc!(ssl);
ssl.lock()
.ok()
.and_then(|mut ssl| ssl.get_peer_cert_chain().map(|x509| x509.pointer()))
.unwrap_or_else(ptr::null_mut)
}
}

entry! {
pub fn _SSL_get0_verified_chain(ssl: *const SSL) -> *mut stack_st_X509 {
_SSL_get_peer_cert_chain(ssl)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's somewhere we should be documenting small divergences like occur here. The upstream API has an important distinction between the peer's presented chain (returned in SSL_get_peer_cert_chain) and the verified chain (returned in SSL_get0_verified_chain). Rustls (sensibly) doesn't have this distinction, and so the API surface is flattened here. I don't know that it's super important to call out the change that now SSL_get_peer_cert_chain is returning a verified chain but it gave me reason to think.

rustls-libssl/src/lib.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
Copy link
Member

Choose a reason for hiding this comment

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

This expires in 2029, so we have a decent window before needing to regenerate it, but there might still be value in lifting some of the rcgen test PKI tooling in here to make these easier to recreate.

rustls-libssl/src/entry.rs Outdated Show resolved Hide resolved
@cpu
Copy link
Member

cpu commented Mar 20, 2024

At the end of this branch, on ubuntu linux you should be able to:

Can I ask what curl version you're getting on your Ubuntu system? I haven't looked closely yet, but on my system w/ curl 8.6.0 the repro fails with a complaint about the SSL_CTX_set_cert_store symbol being missing:

[daniel@blanc:~/Code/Rust/rustls-openssl-compat/rustls-libssl]$ curl --version
curl 8.6.0 (x86_64-pc-linux-gnu) libcurl/8.6.0 OpenSSL/3.0.13 zlib/1.3.1 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 libpsl/0.21.5 libssh2/1.11.0 nghttp2/1.59.0
Release-Date: 2024-01-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

[daniel@blanc:~/Code/Rust/rustls-openssl-compat/rustls-libssl]$ LD_LIBRARY_PATH=target/debug curl https://google.com
curl: symbol lookup error: /nix/store/2hapkajcapp9vzwrlj58jwsrjpr4vj70-curl-8.6.0/lib/libcurl.so.4: undefined symbol: SSL_CTX_set_cert_store, version OPENSSL_3.0.0

[daniel@blanc:~/Code/Rust/rustls-openssl-compat/rustls-libssl]$ nm target/debug/libssl.so | grep "SSL_CTX_set_cert"

[daniel@blanc:~/Code/Rust/rustls-openssl-compat/rustls-libssl]$ nm /nix/store/h24v1xs4i9l3k18ygxvs62361rl77804-openssl-3.0.13/lib/libssl.so.3 | grep "SSL_CTX_set_cert"
0000000000039180 T SSL_CTX_set_cert_cb
000000000003a170 T SSL_CTX_set_cert_store
0000000000039150 T SSL_CTX_set_cert_verify_callback

@ctz
Copy link
Member Author

ctz commented Mar 21, 2024

Thanks for the review! I'll work my way through these today.

Can I ask what curl version you're getting on your Ubuntu system?

Ubuntu 22.04 has curl 7.81.0.

rustls-libssl/src/constants.rs Outdated Show resolved Hide resolved
@ctz ctz force-pushed the jbp-curl-checkpoint branch 2 times, most recently from 7145fb9 to b33f41e Compare March 26, 2024 15:23
ctz added 15 commits March 26, 2024 15:29
Introduce integration test programs -- written in C and linked against
the openssl known to pkg-config -- that are required to produce the
same output when run against rustls-libssl or openssl-libssl.
Run `make integration`.

Note that openssl project has no test coverage of these functions,
so they produce incorrect output (eg,
`SSL_alert_desc_string_long(TLS13_AD_MISSING_EXTENSION)` gives "unknown").
This commit gives bug-for-bug compatibility because that is easiest to
test for.
These are notable because they have different return value
convention, `error::MysteriouslyOppositeReturnValue` represents
that fact.
This includes `SSL_ctrl` because it backs `SSL_set_tlsext_host_name`
for setting the SNI hostname.  `SSL_CTX_ctrl` comes along for the ride.
Some of these certainly will be implemented later, others almost
certainly will not.
@ctz ctz force-pushed the jbp-curl-checkpoint branch from 736cc01 to dae2189 Compare March 26, 2024 15:29
@cpu
Copy link
Member

cpu commented Apr 2, 2024

Ubuntu 22.04 has curl 7.81.0.

I came back around to see if I could repro the check-point success by matching this curl version and the answer was: almost 🎉

If I stub SSL_CTX_set_default_verify_paths and then also specify -capath or -cadir manually the demo works as expected. I think it's probably a difference in configure options between what Ubuntu/Debian ships and what the NixPkgs derivation I hacked up to use 7.81.0 is doing. Would it be helpful if I tried to implement this fn properly? It seems doable but maybe it's mostly worthwhile as a task to get familiar with this repo vs a critical piece of functionality for our goals.

Otherwise it seems like all of my review feedback was addressed. Should we merge? 🚀

@ctz
Copy link
Member Author

ctz commented Apr 3, 2024

Would it be helpful if I tried to implement this fn properly?

Yes that sounds like a good call!

@ctz ctz merged commit 902c17a into main Apr 3, 2024
20 checks passed
@cpu cpu deleted the jbp-curl-checkpoint branch April 3, 2024 14:04
@cpu
Copy link
Member

cpu commented Apr 3, 2024

cpu deleted the jbp-curl-checkpoint branch now

I turned on the automatic branch tidying in the settings to match the other repos. Hope that's OK.

@ctz
Copy link
Member Author

ctz commented Apr 3, 2024

Yep! I have just protected the main branch too, and made this repo public.

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