Got gemini proxy working, via a custom tokio_rustls branch

This commit is contained in:
Brian Picciano 2023-07-24 19:06:01 +02:00
parent c8176c819f
commit c1659fab2a
5 changed files with 16 additions and 17 deletions

View File

@ -23,7 +23,7 @@ service:
value: ""
gemini:
proxied_domains:
localhost:
mediocregopher.com:
url: gemini://127.0.0.1:1965
passphrase: foobar
dns_records:

3
Cargo.lock generated
View File

@ -2964,8 +2964,7 @@ dependencies = [
[[package]]
name = "tokio-rustls"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081"
source = "git+https://code.betamike.com/micropelago/tokio-rustls.git?branch=transparent-acceptor#18fd688b335430e17e054e15ff7d6ce073db2419"
dependencies = [
"rustls",
"tokio",

View File

@ -45,3 +45,6 @@ serde_yaml = "0.9.22"
rand = "0.8.5"
reqwest = "0.11.18"
hyper-reverse-proxy = "0.5.1"
[patch.crates-io]
tokio-rustls = { git = "https://code.betamike.com/micropelago/tokio-rustls.git", branch = "transparent-acceptor" }

View File

@ -45,7 +45,7 @@
pkgs.openssl
toolchain
pkgs.gmni
pkgs.nmap # ncat
];
shellHook = ''
source $(pwd)/.env.dev

View File

@ -36,11 +36,14 @@ impl Service {
service
}
async fn proxy_conn(
async fn proxy_conn<IO>(
&self,
proxied_domain: &ConfigProxiedDomain,
mut conn: tokio::net::TcpStream,
) -> unexpected::Result<()> {
mut conn: IO,
) -> unexpected::Result<()>
where
IO: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin,
{
let mut proxy_conn = tokio::net::TcpStream::connect(&proxied_domain.url.addr)
.await
.map_unexpected_while(|| {
@ -55,10 +58,10 @@ impl Service {
async fn handle_conn(
&self,
conn: tokio::net::TcpStream,
tls_conn: rustls::ServerConnection,
_tls_config: sync::Arc<rustls::ServerConfig>,
) -> Result<(), HandleConnError> {
let acceptor =
tokio_rustls::LazyConfigAcceptor::new(rustls::server::Acceptor::default(), conn);
tokio_rustls::TransparentConfigAcceptor::new(rustls::server::Acceptor::default(), conn);
futures::pin_mut!(acceptor);
match acceptor.as_mut().await {
@ -77,10 +80,7 @@ impl Service {
// If the domain should be proxied, then proxy it
if let Some(proxied_domain) = self.config.gemini.proxied_domains.get(&domain) {
let conn = acceptor
.take_io()
.expect("failed to take back underlying TCP connection");
let conn = start.into_original_stream();
self.proxy_conn(proxied_domain, conn).await?;
return Ok(());
}
@ -130,10 +130,7 @@ async fn listen(
let tls_config = tls_config.clone();
tokio::spawn(async move {
let tls_conn = rustls::ServerConnection::new(tls_config)
.expect("failed to initialize TLS connection state");
match service.handle_conn(conn, tls_conn).await {
match service.handle_conn(conn, tls_config).await {
Ok(_) => (),
Err(HandleConnError::ClientError(e)) => {
log::warn!("Bad request from connection {addr}: {e}")