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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
match tokio::io::copy(&mut rx, &mut tx).await {
|
||||
Ok(bytes_copied) => info!("{bytes_copied}"),
|
||||
// Initialize outbound stream
|
||||
let mut inbound = transport.into_inner();
|
||||
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}"),
|
||||
}
|
||||
Ok(())
|
||||
@@ -90,6 +92,8 @@ async fn main() -> std::io::Result<()> {
|
||||
// Tracing Subscriber
|
||||
let subscriber = tracing_subscriber::FmtSubscriber::new();
|
||||
tracing::subscriber::set_global_default(subscriber).unwrap();
|
||||
// Server Name
|
||||
let my_name = "cicciopizza";
|
||||
// Root certs to verify the server is the right one
|
||||
let mut broker_root_cert_store = RootCertStore::empty();
|
||||
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 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();
|
||||
// TODO: Remove this two mutable option
|
||||
let mut myserver_cert: Option<CertificateDer> = None;
|
||||
let mut myserver_prkey: Option<PrivatePkcs8KeyDer> = None;
|
||||
match transport.next().await {
|
||||
@@ -136,7 +141,7 @@ async fn main() -> std::io::Result<()> {
|
||||
myserver_prkey = Some(server_prkey);
|
||||
}
|
||||
FailedNameAlreadyOccupied => {
|
||||
error!("Failed Announce");
|
||||
error!("Failed Announce, name already occupied");
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user