Skip to content

Commit

Permalink
Upgraded dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tnewman committed Apr 1, 2024
1 parent 0feb916 commit b0f4841
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 73 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"

[dependencies]
async-trait = "0.1"
bytes = "1.5"
bytes = "1.6"
chrono = "0.4"
dotenv = "0.15"
envy = "0.4"
Expand All @@ -18,21 +18,21 @@ opentelemetry = { version = "0.22" }
opentelemetry_sdk = { version = "0.22", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.15", features = ["grpc-tonic"] }
serde = "1.0"
russh = { version = "0.42.0", features = ["flate2", "openssl"] }
russh-keys = { version = "0.42.0", features = ["openssl"] }
russh = { version = "0.43.0", features = ["flate2", "openssl"] }
russh-keys = { version = "0.43.0", features = ["openssl"] }
thiserror = "1.0"
tokio = { version = "1.36", features = ["full", "tracing"] }
tokio = { version = "1.37", features = ["full", "tracing"] }
tracing = "0.1"
tracing-opentelemetry = "0.23"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uuid = { version = "1.7.0", features = ["v4"], default-features = false }
uuid = { version = "1.8.0", features = ["v4"], default-features = false }

# S3 Dependencies
aws-config = "1.1.7"
aws-sdk-s3 = "1.17.0"
aws-config = "1.1.9"
aws-sdk-s3 = "1.21.0"

[dev-dependencies]
once_cell = "1.19.0"
rand = "0.8"
tempfile = "3.10"
testcontainers-modules = { version = "0.3.5", features = ["minio"] }
testcontainers-modules = { version = "0.3.6", features = ["minio"] }
112 changes: 51 additions & 61 deletions src/ssh_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::storage::{s3::S3StorageFactory, Storage, StorageFactory};
use async_trait::async_trait;
use russh::SshId;
use russh::{
server::{run, Auth, Config, Handler, Msg, Server, Session},
server::{Auth, Config, Handler, Msg, Server, Session},
Channel, ChannelId,
};
use russh_keys::{
Expand Down Expand Up @@ -45,7 +45,7 @@ impl DraySshServer {
Ok(())
}

pub async fn run_server(self) -> Result<(), Error> {
pub async fn run_server(mut self) -> Result<(), Error> {
let ssh_config = Config {
server_id: SshId::Standard(format!(
"SSH-2.0-{}_{}",
Expand All @@ -59,22 +59,45 @@ impl DraySshServer {
};

let ssh_config = Arc::new(ssh_config);
let addr = &self.dray_config.get_host_socket_addr()?;

info!("Binding to Host {}", self.dray_config.host);

run(ssh_config, &self.dray_config.get_host_socket_addr()?, self)
self.run_on_address(ssh_config, addr)
.await
.map_err(|error| Error::Failure(error.to_string()))
}
}

impl Server for DraySshServer {
type Handler = Self;

fn new_client(&mut self, _peer_addr: Option<std::net::SocketAddr>) -> Self::Handler {
DraySshServer {
dray_config: self.dray_config.clone(),
object_storage_factory: self.object_storage_factory.clone(),
object_storage: self.object_storage_factory.create_storage(),
channels: Arc::from(Mutex::from(HashMap::new())),
user: RwLock::from(None),
}
}
}

#[async_trait]
impl Handler for DraySshServer {
type Error = Error;

async fn auth_publickey(
self,
user: String,
public_key: PublicKey,
) -> Result<(DraySshServer, Auth), Error> {
&mut self,
user: &str,
public_key: &PublicKey,
) -> Result<Auth, Self::Error> {
let public_key =
key::parse_public_key(&public_key.public_key_bytes(), Option::None).unwrap();

let authorized_keys = match self
.object_storage
.get_authorized_keys_fingerprints(&user)
.get_authorized_keys_fingerprints(user)
.await
{
Ok(authorized_keys) => authorized_keys,
Expand All @@ -98,89 +121,56 @@ impl DraySshServer {

{
let mut self_user = self.user.write().await;
*self_user = Some(user);
*self_user = Some(user.to_string());
}

Ok((self, Auth::Accept))
Ok(Auth::Accept)
}
false => {
info!("Rejected public key authentication attempt from {}", user);
Ok((
self,
Auth::Reject {
proceed_with_methods: Option::None,
},
))
Ok(Auth::Reject {
proceed_with_methods: Option::None,
})
}
}
}
}

impl Server for DraySshServer {
type Handler = Self;

fn new_client(&mut self, _peer_addr: Option<std::net::SocketAddr>) -> Self::Handler {
DraySshServer {
dray_config: self.dray_config.clone(),
object_storage_factory: self.object_storage_factory.clone(),
object_storage: self.object_storage_factory.create_storage(),
channels: Arc::from(Mutex::from(HashMap::new())),
user: RwLock::from(None),
}
}
}

#[async_trait]
impl Handler for DraySshServer {
type Error = Error;

async fn auth_publickey(
self,
user: &str,
public_key: &PublicKey,
) -> Result<(Self, Auth), Self::Error> {
let public_key =
key::parse_public_key(&public_key.public_key_bytes(), Option::None).unwrap();

self.auth_publickey(user.to_owned(), public_key).await
}

async fn channel_open_session(
self,
&mut self,
channel: Channel<Msg>,
session: Session,
) -> Result<(Self, bool, Session), Self::Error> {
_session: &mut Session,
) -> Result<bool, Self::Error> {
{
let mut channels = self.channels.lock().await;
channels.insert(channel.id(), channel);
}

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

async fn channel_close(
self,
&mut self,
channel: ChannelId,
session: Session,
) -> Result<(Self, Session), Self::Error> {
_session: &mut Session,
) -> Result<(), Self::Error> {
{
let mut channels = self.channels.lock().await;
channels.remove(&channel);
}

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

async fn subsystem_request(
self,
&mut self,
channel_id: ChannelId,
name: &str,
mut session: Session,
) -> Result<(Self, Session), Self::Error> {
session: &mut Session,
) -> Result<(), Self::Error> {
if name != "sftp" {
error!("Failed to start unsupported subsystem {}", name);
session.channel_failure(channel_id);
return Ok((self, session));
return Ok(());
}

let user = {
Expand All @@ -195,7 +185,7 @@ impl Handler for DraySshServer {
"Failed to start sftp subsystem because a user was not found on the channel"
);
session.channel_failure(channel_id);
return Ok((self, session));
return Ok(());
}
};

Expand All @@ -212,7 +202,7 @@ impl Handler for DraySshServer {
channel_id
);
session.channel_failure(channel_id);
return Ok((self, session));
return Ok(());
}
};

Expand Down Expand Up @@ -240,6 +230,6 @@ impl Handler for DraySshServer {
};
});

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

0 comments on commit b0f4841

Please sign in to comment.