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::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::{TcpStream, TcpListener};
|
||||||
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
|
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
|
||||||
use tokio_rustls::rustls::pki_types::ServerName;
|
use tokio_rustls::rustls::pki_types::ServerName;
|
||||||
use tokio_rustls::TlsConnector;
|
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 outbound = transport.into_inner();
|
||||||
let mut stdout = tokio::io::stdout();
|
let listener = TcpListener::bind("127.0.0.1:9919").await?;
|
||||||
let mut stdin = tokio::io::stdin();
|
if let Ok((mut inbound, _)) = listener.accept().await {
|
||||||
let stdout_task = async move {
|
match tokio::io::copy_bidirectional(&mut inbound, &mut outbound).await {
|
||||||
match tokio::io::copy(&mut rx, &mut stdout).await {
|
Ok(bytes_copied) => info!("{bytes_copied:?}"),
|
||||||
Ok(bytes_copied) => info!("{bytes_copied}"),
|
|
||||||
Err(e) => error!("Error during copy: {e}"),
|
Err(e) => error!("Error during copy: {e}"),
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
let stdin_task = async move {
|
error!("Error");
|
||||||
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);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,9 +77,11 @@ async fn datastream(tlsconfig: Arc<ClientConfig>, conn_id: Uuid) -> std::io::Res
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let (mut rx, mut tx) = tokio::io::split(transport.into_inner());
|
// Initialize outbound stream
|
||||||
match tokio::io::copy(&mut rx, &mut tx).await {
|
let mut inbound = transport.into_inner();
|
||||||
Ok(bytes_copied) => info!("{bytes_copied}"),
|
let mut outbound = TcpStream::connect("127.0.0.1:22").await?;
|
||||||
|
match tokio::io::copy_bidirectional(&mut inbound, &mut outbound).await {
|
||||||
|
Ok(bytes_copied) => info!("{bytes_copied:?}"),
|
||||||
Err(e) => error!("Error during copy: {e}"),
|
Err(e) => error!("Error during copy: {e}"),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -90,6 +92,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
// Tracing Subscriber
|
// Tracing Subscriber
|
||||||
let subscriber = tracing_subscriber::FmtSubscriber::new();
|
let subscriber = tracing_subscriber::FmtSubscriber::new();
|
||||||
tracing::subscriber::set_global_default(subscriber).unwrap();
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
||||||
|
// Server Name
|
||||||
|
let my_name = "cicciopizza";
|
||||||
// Root certs to verify the server is the right one
|
// Root certs to verify the server is the right one
|
||||||
let mut broker_root_cert_store = RootCertStore::empty();
|
let mut broker_root_cert_store = RootCertStore::empty();
|
||||||
let broker_root_cert_der = load_cert("certs/broker_root_cert.pem").unwrap();
|
let broker_root_cert_der = load_cert("certs/broker_root_cert.pem").unwrap();
|
||||||
@@ -114,8 +118,9 @@ async fn main() -> std::io::Result<()> {
|
|||||||
let stream = connector.connect(dnsname, stream).await?;
|
let stream = connector.connect(dnsname, stream).await?;
|
||||||
|
|
||||||
let mut transport = Framed::new(stream, LengthDelimitedCodec::new());
|
let mut transport = Framed::new(stream, LengthDelimitedCodec::new());
|
||||||
let msg = FromGuestServerMessage::Announce { name: "cicciopizza".into() };
|
let msg = FromGuestServerMessage::Announce { name: my_name.into() };
|
||||||
transport.send(rmp_serde::to_vec(&msg).unwrap().into()).await.unwrap();
|
transport.send(rmp_serde::to_vec(&msg).unwrap().into()).await.unwrap();
|
||||||
|
// TODO: Remove this two mutable option
|
||||||
let mut myserver_cert: Option<CertificateDer> = None;
|
let mut myserver_cert: Option<CertificateDer> = None;
|
||||||
let mut myserver_prkey: Option<PrivatePkcs8KeyDer> = None;
|
let mut myserver_prkey: Option<PrivatePkcs8KeyDer> = None;
|
||||||
match transport.next().await {
|
match transport.next().await {
|
||||||
@@ -136,7 +141,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
myserver_prkey = Some(server_prkey);
|
myserver_prkey = Some(server_prkey);
|
||||||
}
|
}
|
||||||
FailedNameAlreadyOccupied => {
|
FailedNameAlreadyOccupied => {
|
||||||
error!("Failed Announce");
|
error!("Failed Announce, name already occupied");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user