Skip to content

Commit

Permalink
chore: update dependencies, fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirsamdarshi committed Apr 18, 2023
1 parent 67d6227 commit 64210f7
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 120 deletions.
117 changes: 63 additions & 54 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
members = [
"common",
"async-ssh2-lite",
"russh"
"russh",
"ssh2-rs"
]
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Specifically this repository contains experiments with two crates thus far:

- [russh](https://github.com/warp-tech/russh) - An (updated) fork of Thrussh, which is a pure-Rust implementation of the
SSH protocol.
- [ssh2-rs](https://github.com/alexcrichton/ssh2-rs) - A Rust wrapper around libssh2.
- [async-ssh2-lite](https://github.com/bk-rs/ssh-rs) - An async wrapper around ssh2-rs, which is a Rust wrapper around
libssh2.

Expand All @@ -22,18 +23,14 @@ None of the binaries work as expected, and struggle to handle a full remote port
debugged the issues in either library, and am working on fixing/upstreaming the fixes that I make to whichever library I
get working. Therefore, this repository is a work in progress, and I will be updating it as I work further.

In addition, other libraries that I have tried (but that aren't in this library and plan to add are):

- [async-ssh2](https://github.com/spebern/async-ssh2) - Another async wrapper around ssh2-rs

## Example

To run a demo web application on your local computer and connect to it via SSH, ensure that you have Docker and are
running an SSH server on your local machine. Add your own SSH public key to `~/.ssh/authorized_keys`. Then, run the
following commands:

```bash
docker run docker run -d -p 8080:8080 --rm mihirstanford/gatsby-gitbook-starter
docker run -d -p 8080:8080 --rm mihirstanford/gatsby-gitbook-starter
```

Then, you may navigate into either the `async-ssh2-lite` or `russh` directories and run the following:
Expand All @@ -55,7 +52,7 @@ locally

### To Enable SSH Login (On Mac)

First, go to System Preferences > Sharing and enable Remote Login. You may need to restart your computer.
First, go to Settings > General > Sharing and enable Remote Login. You may need to restart your computer.

To create an SSH key and add it to your `authorized_keys` file, run the following commands:

Expand All @@ -66,4 +63,4 @@ ssh-keygen -t ed25519 -C "<your email here>"
# add your SSH key to your authorized_keys file
touch ~/.ssh/authorized_keys
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
```
```
24 changes: 12 additions & 12 deletions async-ssh2-lite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tokio::{
net::{TcpListener, TcpStream},
select,
};
use tracing::{debug, debug_span, instrument, Instrument};
use tracing::{debug, debug_span, error, instrument, Instrument};
use uuid::Uuid;

const BUFFER_SIZE: usize = 8192;
Expand Down Expand Up @@ -51,7 +51,7 @@ async fn read_stream<R: AsyncRead + Unpin + Debug>(mut stream: R) -> (Vec<u8>, u
}
}
Err(e) => {
println!("Error in reading request data: {:?}", e);
println!("Error in reading request data: {e:?}");
break;
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ async fn read_async_channel<R: AsyncReadExt + Unpin>(stream: &mut R) -> (Vec<u8>
}
}
Err(e) => {
println!("Error in reading response data: {:?}", e);
error!("Error in reading response data: {e:?}");
break;
}
}
Expand All @@ -93,7 +93,7 @@ async fn handle_req(
remote_port: u16,
session: Arc<AsyncSession<TcpStream>>,
mut stream: TcpStream,
_unique_id: String,
unique_id: String,
) {
let mut channel = session
.channel_direct_tcpip("localhost", remote_port, None)
Expand Down Expand Up @@ -138,13 +138,13 @@ async fn create_ssh_session(
)
.await?;

if !session.authenticated() {
Err(session
.last_error()
.map(Error::from)
.unwrap_or_else(|| Error::new(ErrorKind::Other, "unknown user auth error")))
} else {
if session.authenticated() {
Ok(session)
} else {
Err(session.last_error().map_or_else(
|| Error::new(ErrorKind::Other, "unknown user auth error"),
Error::from,
))
}
}

Expand Down Expand Up @@ -196,8 +196,8 @@ async fn main() -> std::io::Result<()> {
.unwrap();

let key_pair = SSHKeyPair {
public_key: public_key.as_ref().map(|p| p.as_ref()),
private_key: private_key.as_ref().map(|p| p.as_ref()),
public_key: public_key.as_ref().map(AsRef::as_ref),
private_key: private_key.as_ref().map(AsRef::as_ref),
};

let session = match create_ssh_session(&args.user, remote_address, key_pair).await {
Expand Down
Loading

0 comments on commit 64210f7

Please sign in to comment.