WIP: SNI-aware proxy with tokio #329
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is really bad code and does everything very wrong, sorry about that, it's just a proof-of-concept. I just submitted this because it took me a while to figure it out already, and people seemed interested in #58 (5 upvotes at the time of writing).
Supports:
It's very quick & dirty, as it will peek in the stream to find the TLS handshake (i couldn't find a peek equivalent in monoio, so only tokio is supported for now), which will be parsed a second time if the connection is not reverse proxied without TLS termination.
Also, i mostly have no idea what i'm doing with that backend
TcpStreamreading/writing, i just hacked this around, but i'm guessing it's possible to pipe actualtcp_streamintodest_streamwithout dark magic (i just don't know how).Testing
It's using the
proxy_tlsdirective in vhosts. For example:Now you can curl it:
Additional notes
rustlswithout consuming the connection (hence the peeked buffer hack), there's plenty of issues about it upstream, and i don't understand why the maintainers don't want to make it easier (i had to fork rustls to make more types public, but there may be a simpler way)