Add first real SSH bridge
This commit is contained in:
@@ -2,7 +2,7 @@ use std::io::{Error, ErrorKind};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::net::{TcpStream, TcpListener};
|
||||
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
|
||||
use tokio_rustls::rustls::pki_types::ServerName;
|
||||
use tokio_rustls::TlsConnector;
|
||||
@@ -78,22 +78,16 @@ async fn datastream(tlsconfig: ClientConfig, conn_id: Uuid) -> std::io::Result<(
|
||||
}
|
||||
}
|
||||
}
|
||||
let (mut rx, mut tx) = tokio::io::split(transport.into_inner());
|
||||
let mut stdout = tokio::io::stdout();
|
||||
let mut stdin = tokio::io::stdin();
|
||||
let stdout_task = async move {
|
||||
match tokio::io::copy(&mut rx, &mut stdout).await {
|
||||
Ok(bytes_copied) => info!("{bytes_copied}"),
|
||||
let mut outbound = transport.into_inner();
|
||||
let listener = TcpListener::bind("127.0.0.1:9919").await?;
|
||||
if let Ok((mut inbound, _)) = listener.accept().await {
|
||||
match tokio::io::copy_bidirectional(&mut inbound, &mut outbound).await {
|
||||
Ok(bytes_copied) => info!("{bytes_copied:?}"),
|
||||
Err(e) => error!("Error during copy: {e}"),
|
||||
}
|
||||
};
|
||||
let stdin_task = async move {
|
||||
match tokio::io::copy(&mut stdin, &mut tx).await {
|
||||
Ok(bytes_copied) => info!("{bytes_copied}"),
|
||||
Err(e) => error!("Error during copy: {e}"),
|
||||
}
|
||||
};
|
||||
tokio::join!(stdout_task, stdin_task);
|
||||
} else {
|
||||
error!("Error");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user