Skip to content

Commit

Permalink
build(cargo): cargo update
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrubek committed Nov 10, 2024
1 parent 3cbfc80 commit f24b7cc
Show file tree
Hide file tree
Showing 8 changed files with 1,527 additions and 748 deletions.
2,206 changes: 1,489 additions & 717 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository = "https://github.com/justinrubek/thoenix"
authors = ["Justin Rubek"]

[workspace.dependencies]
ed25519-dalek = "2.1.0"
russh = "0.46"
russh-keys = "0.46"
serde_json = "1"
thiserror = "1.0.38"
tracing = "0.1.37"
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ edition = { workspace = true }
anyhow = "1.0.68"
async-trait = "0.1.63"
bytes = "1.3.0"
ed25519-dalek = "2.1.0"
ed25519-dalek = { workspace = true }
flate2 = "1.0.25"
futures = "0.3.26"
futures-util = "0.3.26"
git-pack = "0.30.1"
project-base-directory = "0.2.0"
russh = "0.36.0"
russh-keys = "0.24.0"
project-base-directory = "0.3"
russh = { workspace = true }
russh-keys = { workspace = true }
thiserror = "1.0.38"
clap = { version = "4", features = ["derive"] }
# reqwest = { version = "0.11.12", features = ["rustls-tls"] }
Expand Down
7 changes: 4 additions & 3 deletions crates/cli/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::AppResult;
use russh::server::Server as RusshServer;
use russh_keys::PublicKeyBase64;
use std::{path::PathBuf, sync::Arc};
use tracing::info;
Expand All @@ -22,11 +23,11 @@ impl Server {
auth_rejection_time: std::time::Duration::from_secs(3),
auth_rejection_time_initial: Some(std::time::Duration::from_secs(0)),
keys: vec![keys],
connection_timeout: Some(std::time::Duration::from_secs(30)),
inactivity_timeout: Some(std::time::Duration::from_secs(30)),
..Default::default()
};

let server = thoenix_ssh::handler::SshServer {
let mut server = thoenix_ssh::handler::SshServer {
data_dir: PathBuf::from(data_dir),
};

Expand All @@ -42,7 +43,7 @@ impl Server {
info!(%public_key);

info!(?address, "starting server");
russh::server::run(Arc::new(config), address, server).await?;
server.run_on_address(Arc::new(config), address).await?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Server {
})
.on_request(|_request: &Request<_>, span: &Span| {
let id = "TODO: request ID";
span.record("request_id", &tracing::field::display(id));
span.record("request_id", tracing::field::display(id));
});

let addr = SocketAddr::from(([0, 0, 0, 0], port));
Expand Down
6 changes: 3 additions & 3 deletions crates/ssh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ version = "0.2.0"
anyhow = "1.0.68"
async-trait = "0.1.63"
bytes = "1.3.0"
ed25519-dalek = "1.0.1"
ed25519-dalek = { workspace = true }
flate2 = "1.0.25"
futures = "0.3.26"
futures-util = "0.3.26"
git-pack = "0.30.1"
russh = "0.36.0"
russh-keys = "0.24.0"
russh = { workspace = true }
russh-keys = { workspace = true }
thiserror = "1.0.38"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
Expand Down
34 changes: 17 additions & 17 deletions crates/ssh/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,43 +196,43 @@ impl SshSession {
impl russh::server::Handler for SshSession {
type Error = error::Error;

async fn auth_password(self, user: &str, password: &str) -> Result<(Self, Auth)> {
async fn auth_password(&mut self, user: &str, password: &str) -> Result<Auth> {
info!(?user, ?password, "auth password");
Ok((self, Auth::Accept))
Ok(Auth::Accept)
}

async fn auth_publickey(
self,
&mut self,
user: &str,
public_key: &russh_keys::key::PublicKey,
) -> Result<(Self, Auth)> {
) -> Result<Auth> {
info!(%user, ?public_key, "auth public key");
Ok((self, Auth::Accept))
Ok(Auth::Accept)
}

async fn channel_open_session(
mut self,
&mut self,
channel: russh::Channel<russh::server::Msg>,
session: Session,
) -> Result<(Self, bool, Session)> {
_session: &mut Session,
) -> Result<bool> {
let channel_id = channel.id();
info!(?channel_id, "channel open session");
{
let mut clients = self.clients.lock().await;
clients.insert(channel.id(), channel);
}
Ok((self, true, session))
Ok(true)
}

/// Our entrypoint for connections will be the `exec` command
/// We will determine if the command is one we support and then'
/// create a new task to handle the command
async fn exec_request(
mut self,
&mut self,
channel_id: russh::ChannelId,
data: &[u8],
mut session: Session,
) -> Result<(Self, Session)> {
session: &mut Session,
) -> Result<()> {
info!(%channel_id, "exec request");
let command_str = String::from_utf8_lossy(data);
info!(%command_str, "sending exec request");
Expand Down Expand Up @@ -261,17 +261,17 @@ impl russh::server::Handler for SshSession {
}?;

session.channel_success(channel_id);
Ok((self, session))
Ok(())
}

/// Called with data is received from the client
/// In order for data to be received, the channel must be established as successful
async fn data(
mut self,
&mut self,
channel_id: russh::ChannelId,
data: &[u8],
session: russh::server::Session,
) -> Result<(Self, russh::server::Session)> {
_session: &mut russh::server::Session,
) -> Result<()> {
tracing::info!(%channel_id, "data");
self.input_buf.extend_from_slice(data);

Expand Down Expand Up @@ -311,7 +311,7 @@ impl russh::server::Handler for SshSession {
}
}

Ok((self, session))
Ok(())
}

/*
Expand Down
9 changes: 6 additions & 3 deletions crates/ssh/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ pub async fn get_or_generate_keypair(data_dir: &str) -> Result<russh_keys::key::
let key_path = std::path::Path::new(&data_dir).join("id_rsa");
if !key_path.exists() {
// generate a keypair if none exists
let keys = russh_keys::key::KeyPair::generate_ed25519().unwrap();
let keys = russh_keys::key::KeyPair::generate_ed25519();
let mut key_file = tokio::fs::File::create(&key_path).await?;

let russh_keys::key::KeyPair::Ed25519(inner_pair) = keys;
let russh_keys::key::KeyPair::Ed25519(inner_pair) = keys else {
panic!("failure generating key")
};

key_file.write_all(&inner_pair.to_bytes()).await?;

Ok(russh_keys::key::KeyPair::Ed25519(inner_pair))
} else {
// load the keypair from the file
let key_data = tokio::fs::read(&key_path).await?;
let keypair = ed25519_dalek::Keypair::from_bytes(&key_data)?;
let key_bytes: [u8; 32] = key_data.try_into().unwrap();
let keypair = ed25519_dalek::SigningKey::from_bytes(&key_bytes);

Ok(russh_keys::key::KeyPair::Ed25519(keypair))
}
Expand Down

0 comments on commit f24b7cc

Please sign in to comment.