mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-16 17:35:04 +01:00
misc improvements
This commit is contained in:
parent
ca4213ba81
commit
26cdcd0524
7 changed files with 39 additions and 31 deletions
|
|
@ -43,7 +43,7 @@ impl InteractiveShell {
|
|||
127 => {
|
||||
// Backspace, space, backspace.
|
||||
// We literally erase it.
|
||||
if self.line_buf.len() > 0 {
|
||||
if !self.line_buf.is_empty() {
|
||||
self.write(&[8, 32, 8]);
|
||||
self.line_buf.truncate(self.line_buf.len() - 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ impl UserPublicKey {
|
|||
|
||||
let file = tokio::fs::read_to_string(sshd_dir)
|
||||
.await
|
||||
.map_err(|err| AuthError::NoAuthorizedKeys(err))?;
|
||||
.map_err(AuthError::NoAuthorizedKeys)?;
|
||||
|
||||
let authorized_keys = AuthorizedKeys::parse(&file)?;
|
||||
|
||||
if let Some(key) = authorized_keys.contains(&provided_key) {
|
||||
if let Some(key) = authorized_keys.contains(provided_key) {
|
||||
Ok(Self(key.clone()))
|
||||
} else {
|
||||
Err(AuthError::UnauthorizedPublicKey)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ async fn handle_connection(
|
|||
}
|
||||
},
|
||||
},
|
||||
result = futures::future::try_join_all(&mut channel_tasks), if channel_tasks.len() > 0 => {
|
||||
result = futures::future::try_join_all(&mut channel_tasks), if !channel_tasks.is_empty() => {
|
||||
match result {
|
||||
Ok(_) => channel_tasks.clear(),
|
||||
Err(err) => return Err((err as eyre::Report).wrap_err("channel task failed")),
|
||||
|
|
@ -259,20 +259,17 @@ async fn handle_session_channel(user: String, channel: Channel) -> Result<()> {
|
|||
}
|
||||
}
|
||||
exit = state.process_exit_recv.recv() => {
|
||||
match exit {
|
||||
Some(exit) => {
|
||||
let exit = exit?;
|
||||
state.channel.send(ChannelOperationKind::Eof).await?;
|
||||
// TODO: also handle exit-signal
|
||||
state.channel
|
||||
.send(ChannelOperationKind::Request(ChannelRequest::ExitStatus {
|
||||
status: exit.code().unwrap_or(0) as u32,
|
||||
}))
|
||||
.await?;
|
||||
state.channel.send(ChannelOperationKind::Close).await?;
|
||||
return Ok(());
|
||||
}
|
||||
None => {}
|
||||
if let Some(exit) = exit {
|
||||
let exit = exit?;
|
||||
state.channel.send(ChannelOperationKind::Eof).await?;
|
||||
// TODO: also handle exit-signal
|
||||
state.channel
|
||||
.send(ChannelOperationKind::Request(ChannelRequest::ExitStatus {
|
||||
status: exit.code().unwrap_or(0) as u32,
|
||||
}))
|
||||
.await?;
|
||||
state.channel.send(ChannelOperationKind::Close).await?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
read = read => {
|
||||
|
|
@ -346,12 +343,11 @@ impl SessionState {
|
|||
};
|
||||
}
|
||||
ChannelUpdateKind::OpenFailed { .. } => todo!(),
|
||||
ChannelUpdateKind::Data { data } => match &mut self.writer {
|
||||
Some(pty) => {
|
||||
pty.write_all(&data).await?;
|
||||
ChannelUpdateKind::Data { data } => {
|
||||
if let Some(writer) = &mut self.writer {
|
||||
writer.write_all(&data).await?;
|
||||
}
|
||||
None => {}
|
||||
},
|
||||
}
|
||||
ChannelUpdateKind::Open(_)
|
||||
| ChannelUpdateKind::Closed
|
||||
| ChannelUpdateKind::ExtendedData { .. }
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ impl Debug for PlaintextPrivateKey {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum PrivateKey {
|
||||
Ed25519 {
|
||||
public_key: ed25519_dalek::VerifyingKey,
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ use crate::{Channel, ChannelState, PendingChannel};
|
|||
pub struct ServerListener {
|
||||
listener: TcpListener,
|
||||
auth_verify: ServerAuthVerify,
|
||||
transport_config: cluelessh_transport::server::ServerConfig
|
||||
// TODO ratelimits etc
|
||||
transport_config: cluelessh_transport::server::ServerConfig, // TODO ratelimits etc
|
||||
}
|
||||
|
||||
pub struct ServerConnection<S> {
|
||||
|
|
@ -80,7 +79,11 @@ impl From<eyre::Report> for Error {
|
|||
}
|
||||
|
||||
impl ServerListener {
|
||||
pub fn new(listener: TcpListener, auth_verify: ServerAuthVerify, transport_config: cluelessh_transport::server::ServerConfig) -> Self {
|
||||
pub fn new(
|
||||
listener: TcpListener,
|
||||
auth_verify: ServerAuthVerify,
|
||||
transport_config: cluelessh_transport::server::ServerConfig,
|
||||
) -> Self {
|
||||
Self {
|
||||
listener,
|
||||
auth_verify,
|
||||
|
|
@ -101,7 +104,12 @@ impl ServerListener {
|
|||
}
|
||||
|
||||
impl<S: AsyncRead + AsyncWrite> ServerConnection<S> {
|
||||
pub fn new(stream: S, peer_addr: SocketAddr, auth_verify: ServerAuthVerify, transport_config: cluelessh_transport::server::ServerConfig) -> Self {
|
||||
pub fn new(
|
||||
stream: S,
|
||||
peer_addr: SocketAddr,
|
||||
auth_verify: ServerAuthVerify,
|
||||
transport_config: cluelessh_transport::server::ServerConfig,
|
||||
) -> Self {
|
||||
let (operations_send, operations_recv) = tokio::sync::mpsc::channel(15);
|
||||
let (channel_ops_send, channel_ops_recv) = tokio::sync::mpsc::channel(15);
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ impl AlgorithmName for EncryptionAlgorithm {
|
|||
pub struct EncodedSshSignature(pub Vec<u8>);
|
||||
|
||||
pub struct HostKeySigningAlgorithm {
|
||||
private_key: PrivateKey,
|
||||
private_key: Box<PrivateKey>,
|
||||
}
|
||||
|
||||
impl AlgorithmName for HostKeySigningAlgorithm {
|
||||
|
|
@ -121,7 +121,9 @@ impl AlgorithmName for HostKeySigningAlgorithm {
|
|||
|
||||
impl HostKeySigningAlgorithm {
|
||||
pub fn new(private_key: PrivateKey) -> Self {
|
||||
Self { private_key }
|
||||
Self {
|
||||
private_key: Box::new(private_key),
|
||||
}
|
||||
}
|
||||
pub fn sign(&self, data: &[u8]) -> Signature {
|
||||
self.private_key.sign(data)
|
||||
|
|
|
|||
|
|
@ -145,8 +145,9 @@ impl ServerConnection {
|
|||
let kex_algorithm = sup_algs.key_exchange.find(kex.kex_algorithms.0)?;
|
||||
debug!(name = %kex_algorithm.name(), "Using KEX algorithm");
|
||||
|
||||
let server_host_key_algorithm =
|
||||
sup_algs.hostkey_sign.find(kex.server_host_key_algorithms.0)?;
|
||||
let server_host_key_algorithm = sup_algs
|
||||
.hostkey_sign
|
||||
.find(kex.server_host_key_algorithms.0)?;
|
||||
debug!(name = %server_host_key_algorithm.name(), "Using host key algorithm");
|
||||
|
||||
// TODO: Implement aes128-ctr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue