Skip to content

Commit

Permalink
Merge pull request #73 from HsuJv/ver0_4_0
Browse files Browse the repository at this point in the history
Release v0.4
  • Loading branch information
HsuJv authored Sep 16, 2023
2 parents 661dbac + 22c6a3c commit fc7a520
Show file tree
Hide file tree
Showing 77 changed files with 1,486 additions and 992 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: add user
run: addgroup ubuntu && adduser --shell /bin/ash --disabled-password --home /home/ubuntu --ingroup ubuntu ubuntu && echo "ubuntu:password" | chpasswd
- name: config ssh
run: ssh-keygen -A && sed -i -E "s|(AuthorizedKeysFile).*|\1 %h/.ssh/authorized_keys|g" /etc/ssh/sshd_config && echo "HostKeyAlgorithms=+ssh-rsa" >> /etc/ssh/sshd_config && echo "PubkeyAcceptedAlgorithms=+ssh-rsa" >> /etc/ssh/sshd_config && echo "KexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" >> /etc/ssh/sshd_config && sed -i -E "s/#?(ChallengeResponseAuthentication|PasswordAuthentication).*/\1 yes/g" /etc/ssh/sshd_config
run: ssh-keygen -A && sed -i -E "s|(AuthorizedKeysFile).*|\1 %h/.ssh/authorized_keys|g" /etc/ssh/sshd_config && echo "HostKeyAlgorithms=+ssh-rsa" >> /etc/ssh/sshd_config && echo "PubkeyAcceptedAlgorithms=+ssh-rsa" >> /etc/ssh/sshd_config && echo "KexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1" >> /etc/ssh/sshd_config && echo "Ciphers=+aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc" >> /etc/ssh/sshd_config && sed -i -E "s/#?(ChallengeResponseAuthentication|PasswordAuthentication).*/\1 yes/g" /etc/ssh/sshd_config
- name: create .ssh
run: mkdir -p /home/ubuntu/.ssh && umask 066; touch /home/ubuntu/.ssh/authorized_keys
- name: generate rsa files
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
target
.gitignore
.vscode
# Generated by Cargo
# will have compiled files and executables
/target/
Expand Down
52 changes: 34 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ssh-rs"
version = "0.3.3"
version = "0.4.0"
edition = "2021"
authors = [
"Gao Xiang Kang <1148118271@qq.com>",
Expand All @@ -14,42 +14,58 @@ repository = "https://github.com/1148118271/ssh-rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
dangerous-algorithms = ["dangerous-rsa-sha1", "dangerous-dh-group1-sha1"]
dangerous-rsa-sha1 = ["sha1"]
dangerous-dh-group1-sha1 = []
deprecated-algorithms = [
"deprecated-rsa-sha1",
"deprecated-dh-group1-sha1",
"deprecated-aes-cbc",
"deprecated-des-cbc",
]
deprecated-rsa-sha1 = ["dep:sha1"]
deprecated-dh-group1-sha1 = ["dep:sha1"]
deprecated-aes-cbc = ["dep:cbc", "dep:cipher"]
deprecated-des-cbc = ["dep:cbc", "dep:cipher", "dep:des"]
scp = ["dep:filetime"]

[lib]
name = "ssh"
path = "src/lib.rs"

[dependencies]
log = "0.4"
rand = "0.8"
num-bigint = { version = "0.4", features = ["rand"] }
## error
thiserror = "^1.0"

## log
tracing = { version = "^0.1", features = ["log"] }

## string enum
strum = "0.25"
strum_macros = "0.25"

## algorithm
rand = "0.8"
num-bigint = { version = "0.4", features = ["rand"] }
# the crate rsa has removed the internal hash implement from 0.7.0
sha1 = { version = "0.10.5", default-features = false, features = ["oid"], optional = true }
sha2 = { version = "0.10.6", default-features = false, features = ["oid"]}
rsa = "0.9"
aes = "0.8"
ctr = "0.9"
des = { version = "0.8", optional = true }
cbc = { version = "0.1", optional = true }
cipher = { version = "0.4", optional = true }
ssh-key = { version = "0.6", features = ["rsa", "ed25519", "alloc"]}
signature = "2.1"
ring = "0.16"
filetime = "0.2"

# async
# [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# tokio = { version = "^1", features = ["full"] }
## utils
filetime = { version = "0.2", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
# tokio = { version = "^1", features = [
# "sync",
# "macros",
# "io-util",
# "rt",
# "time"
# ]}


[dev-dependencies]
tracing-subscriber = { version = "^0.3" }
paste = "1"


Expand Down
48 changes: 34 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ or [PR](https://github.com/1148118271/ssh-rs/pulls) .
### 1. Password:

```rust
use ssh_rs::ssh;
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
let mut session = ssh::create_session()
.username("ubuntu")
.password("password")
Expand All @@ -67,7 +69,9 @@ let mut session = ssh::create_session()
// and end with
// -----END RSA PRIVATE KEY----- / -----END OPENSSH PRIVATE KEY-----
// simply generated by `ssh-keygen -t rsa -m PEM -b 4096`
use ssh_rs::ssh;
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
let mut session = ssh::create_session()
.username("ubuntu")
.private_key_path("./id_rsa")
Expand All @@ -82,7 +86,9 @@ let mut session = ssh::create_session()
// -----BEGIN RSA PRIVATE KEY----- / -----BEGIN OPENSSH PRIVATE KEY-----
// and end with
// -----END RSA PRIVATE KEY----- / -----END OPENSSH PRIVATE KEY-----
use ssh_rs::ssh;
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
let mut session = ssh::create_session()
.username("ubuntu")
.private_key("rsa_string")
Expand All @@ -95,7 +101,9 @@ let mut session = ssh::create_session()
* According to the implementation of OpenSSH, it will try public key first and fallback to password. So both of them can be provided.

```Rust
use ssh_rs::ssh;
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
let mut session = ssh::create_session()
.username("username")
.password("password")
Expand All @@ -106,24 +114,32 @@ let mut session = ssh::create_session()

## Enable global logging:

* There are two APIs to enable logs, basicly `enable_log()` will set the log level to `INFO`, and `debug()` will set it to `Debug`

* But you can implement your own logger as well.
* This crate now uses the `log` compatible `tracing` for logging functionality

```rust
use ssh_rs::ssh;
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
// this will generate some basic event logs
ssh::enable_log();
// this will generate verbose logs
ssh::debug()
// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than INFO (e.g, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::INFO)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
```

## Set timeout:

* Only global timeouts per r/w are currently supported.

```rust
use ssh_rs::ssh;
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

ssh::debug();
let _listener = TcpListener::bind("127.0.0.1:7777").unwrap();
Expand Down Expand Up @@ -159,14 +175,14 @@ match ssh::create_session()
* `ecdh-sha2-nistp256`
* `diffie-hellman-group14-sha256`
* `diffie-hellman-group14-sha1`
* `diffie-hellman-group1-sha1` (behind feature "dangerous-dh-group1-sha1")
* `diffie-hellman-group1-sha1` (behind feature "deprecated-dh-group1-sha1")

### 2. Server host key algorithms

* `ssh-ed25519`
* `rsa-sha2-256`
* `rsa-sha2-512`
* `rsa-sha` (behind feature "dangerous-rsa-sha1")
* `rsa-sha` (behind feature "deprecated-rsa-sha1")

### 3. Encryption algorithms (client to server)

Expand All @@ -179,6 +195,10 @@ match ssh::create_session()
* `aes128-ctr`
* `aes192-ctr`
* `aes256-ctr`
* `aes128-cbc` (behind feature "deprecated-aes-cbc")
* `aes192-cbc` (behind feature "deprecated-aes-cbc")
* `aes256-cbc` (behind feature "deprecated-aes-cbc")
* `3des-cbc` (behind feature "deprecated-des-cbc")

### 5. Mac algorithms (client to server)

Expand Down
21 changes: 19 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ fn main() {
### 启用全局日志:

```rust
ssh::debug();
use ssh;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
// this will generate some basic event logs
// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than INFO (e.g, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::INFO)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
```

### 设置超时时间:
Expand Down Expand Up @@ -82,14 +94,19 @@ ssh::create_session().timeout(Some(std::time::Duration::from_secs(5)));
* `ssh-ed25519`
* `rsa-sha2-512`
* `rsa-sha2-256`
* `rsa-sha` (features = ["dangerous-rsa-sha1"])
* `rsa-sha` (features = ["deprecated-rsa-sha1"])

#### 3. 加密算法(客户端到服务端)

* `chacha20-poly1305@openssh.com`
* `aes128-ctr`
* `aes192-ctr`
* `aes256-ctr`
* `aes128-cbc` (features = ["deprecated-aes-cbc"])
* `aes192-cbc` (features = ["deprecated-aes-cbc"])
* `aes256-cbc` (features = ["deprecated-aes-cbc"])
* `3des-cbc` (features = ["deprecated-des-cbc"])


#### 4. 加密算法(服务端到客户端)

Expand Down
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ fn main() {

println!("cargo:warning= current version: {current_version} last version: {last_version}");

// 替换lib.rs
// lib.rs
if replace_lib(&current_version, &last_version).is_err() {
return;
}
// 替换constant.rs
// constant.rs
if replace_constant(&current_version, &last_version).is_err() {
return;
}
// 替换Cargo.toml
// Cargo.toml
let _ = replace_cargo(&current_version, &last_version);
}

Expand Down
2 changes: 1 addition & 1 deletion build_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ echo done
echo
echo
echo cargo test
cargo test > /dev/null
cargo test --all-features -- --test-threads 1 > /dev/null
echo done
12 changes: 11 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
v0.4.0 (2023-09-16)
1. remove chinese comments
2. add RFC links
3. remove the self-implemented log, using tracing instead
4. move scp related function behind feature `scp'
5. re-implement the ssh-error to derive thiserror crate
6. rename the dangerous-related features to deprecated-*
7. add aes-128/192/256-cbc encryption modes (behind feature deprecated-aes-cbc)
7. add 3des-cbc encryption modes (behind feature deprecated-des-cbc)

v0.3.3 (2023-09-10)
1. fix hang when tcp connects to a non-existent host
2. refactor aes_ctr file
Expand All @@ -8,7 +18,7 @@ v0.3.3 (2023-09-10)

v0.3.2 (2023-01-10)
1. fix some error with hmac2
2. add aes-192-crtaes-256-ctr
2. add aes-192-crt, aes-256-ctr

v0.3.1 (2022-12-07)
fix some issues
Expand Down
4 changes: 3 additions & 1 deletion examples/bio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ssh-rs = { path = "../../" }
ssh-rs = { path = "../../" }
tracing = { version = "^0.1", features = ["log"] }
tracing-subscriber = { version = "^0.3" }
14 changes: 12 additions & 2 deletions examples/bio/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use ssh_rs::ssh;

use std::net::{TcpStream, ToSocketAddrs};
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

fn main() {
ssh::enable_log();
// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than INFO (e.g, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::INFO)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let bio = MyProxy::new("127.0.0.1:22");

Expand Down
4 changes: 3 additions & 1 deletion examples/customized_algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ssh-rs = { path="../../", features = ["dangerous-algorithms"]}
ssh-rs = { path="../../", features = ["deprecated-algorithms"]}
tracing = { version = "^0.1", features = ["log"] }
tracing-subscriber = { version = "^0.3" }
15 changes: 12 additions & 3 deletions examples/customized_algorithms/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use ssh_rs::algorithm;
use ssh_rs::ssh;
use ssh::algorithm;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

fn main() {
ssh::enable_log();
// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than INFO (e.g, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::INFO)
// completes the builder.
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let mut session = ssh::create_session_without_default()
.username("ubuntu")
Expand Down
4 changes: 3 additions & 1 deletion examples/exec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ssh-rs = { path = "../../" }
ssh-rs = { path = "../../" }
tracing = { version = "^0.1", features = ["log"] }
tracing-subscriber = { version = "^0.3" }
Loading

0 comments on commit fc7a520

Please sign in to comment.