Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Dec 4, 2021
1 parent 37f8269 commit 43783a6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 22 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ Even if many attributes are not exposed, since not supported, there is anyway a

### Exposed attributes

- BindAddress: you can use this attribute to bind the socket to a certain address
- BindInterface: you can use this attribute to bind the socket to a certain network interface
- CASignatureAlgorithms: you can use this attribute to handle CA certificates
- CertificateFile: you can use this attribute to parse the certificate file in case is necessary
- Ciphers: you can use this attribute to set preferred methods with the session method `session.method_pref(MethodType::CryptCs, ...)` and `session.method_pref(MethodType::CryptSc, ...)`
- Compression: you can use this attribute to set whether compression is enabled with `session.set_compress(value)`
- ConnectionAttempts: you can use this attribute to cycle over connect in order to retry
- ConnectTimeout: you can use this attribute to set the connection timeout for the socket
- HostName: you can use this attribute to get the real name of the host to connect to
- KexAlgorithms: you can use this attribute to configure Key exchange methods with `session.method_pref(MethodType::Kex, algos.join(",").as_str())`
- MACs: you can use this attribute to configure the MAC algos with `session.method_pref(MethodType::MacCs, algos.join(",").as_str())` and `session.method_pref(MethodType::MacSc, algos.join(",").as_str())`
- Port: you can use this attribute to resolve the port to connect to
- PubkeyAuthentication: you can use this attribute to set whether to use the pubkey authentication
- RemoteForward: you can use this method to implement port forwarding with `session.channel_forward_listen()`
- ServerAliveInterval: you can use this method to implement keep alive message interval
- TcpKeepAlive: you can use this method to tell whether to send keep alive message
- User: you can use this method to resolve the user to use to log in as
- **BindAddress**: you can use this attribute to bind the socket to a certain address
- **BindInterface**: you can use this attribute to bind the socket to a certain network interface
- **CASignatureAlgorithms**: you can use this attribute to handle CA certificates
- **CertificateFile**: you can use this attribute to parse the certificate file in case is necessary
- **Ciphers**: you can use this attribute to set preferred methods with the session method `session.method_pref(MethodType::CryptCs, ...)` and `session.method_pref(MethodType::CryptSc, ...)`
- **Compression**: you can use this attribute to set whether compression is enabled with `session.set_compress(value)`
- **ConnectionAttempts**: you can use this attribute to cycle over connect in order to retry
- **ConnectTimeout**: you can use this attribute to set the connection timeout for the socket
- **HostName**: you can use this attribute to get the real name of the host to connect to
- **KexAlgorithms**: you can use this attribute to configure Key exchange methods with `session.method_pref(MethodType::Kex, algos.join(",").as_str())`
- **MACs**: you can use this attribute to configure the MAC algos with `session.method_pref(MethodType::MacCs, algos.join(",").as_str())` and `session.method_pref(MethodType::MacSc, algos.join(",").as_str())`
- **Port**: you can use this attribute to resolve the port to connect to
- **PubkeyAuthentication**: you can use this attribute to set whether to use the pubkey authentication
- **RemoteForward**: you can use this method to implement port forwarding with `session.channel_forward_listen()`
- **ServerAliveInterval**: you can use this method to implement keep alive message interval
- **TcpKeepAlive**: you can use this method to tell whether to send keep alive message
- **User**: you can use this method to resolve the user to use to log in as

### Missing features

Expand All @@ -122,12 +122,12 @@ ssh2-config = "^0.1.0"
then parse the configuration

```rust
use ssh2_config::{SshConfig, SshConfigParser};
use ssh2_config::{SshConfig};
use std::fs::File;
use std::io::BufReader;

let mut reader = BufReader::new(File::open(config_path).expect("Could not open configuration file"));
let config = SshConfigParser::default().parse(&mut reader).expect("Failed to parse configuration");
let config = SshConfig::default().parse(&mut reader).expect("Failed to parse configuration");

// Query attributes for a certain host
let params = config.query("192.168.1.2");
Expand Down
32 changes: 32 additions & 0 deletions assets/ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ssh config example

Compression yes
ConnectionAttempts 10
ConnectTimeout 60
ServerAliveInterval 40
TcpKeepAlive yes

Ciphers aes128-ctr,aes192-ctr,aes256-ctr
KexAlgorithms diffie-hellman-group-exchange-sha256
MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160

# Host configuration

Host 192.168.*.* 172.26.*.* !192.168.1.30
User omar
ForwardAgent yes
BindAddress 10.8.0.10
BindInterface tun0
Ciphers +aes128-cbc,aes192-cbc,aes256-cbc
Macs +hmac-sha1-etm@openssh.com

Host tostapane
User ciro-esposito
HostName 192.168.24.32
RemoteForward 88
Compression no
Port 2222

Host 192.168.1.30
User nutellaro
RemoteForward 123
36 changes: 33 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

//! # ssh2-config
//!
//! ssh2-config TODO:
//! ssh2-config a library which provides a parser for the SSH configuration file,
//! to be used in pair with the [ssh2](https://github.com/alexcrichton/ssh2-rs) crate.
//!
//! This library provides a method to parse the configuration file and returns the
//! configuration parsed into a structure.
//! The `SshConfig` structure provides all the attributes which **can** be used to configure the **ssh2 Session**
//! and to resolve the host, port and username.
//!
//! Once the configuration has been parsed you can use the `query(&str)`
//! method to query configuration for a certain host, based on the configured patterns.
//! Even if many attributes are not exposed, since not supported, there is anyway a validation of the configuration,
//! so invalid configuration will result in a parsing error.
//!
//! ## Get started
//!
Expand All @@ -13,11 +24,30 @@
//! ssh2-config = "^0.1.0"
//! ```
//!
//! ## Usage
//! ## Example
//!
//! Here is a basic usage example:
//! Here is a basic example:
//!
//! ```rust
//!
//! use ssh2::Session;
//! use ssh2_config::{HostParams, SshConfig};
//! use std::fs::File;
//! use std::io::BufReader;
//! use std::path::Path;
//!
//! let mut reader = BufReader::new(
//! File::open(Path::new("./assets/ssh.config"))
//! .expect("Could not open configuration file")
//! );
//!
//! let config = SshConfig::default().parse(&mut reader).expect("Failed to parse configuration");
//!
//! let default_params = config.default_params();
//! // Query parameters for your host
//! // If there's no rule for your host, default params are returned
//! let params = config.query("192.168.1.2");
//!
//! ```
//!

Expand Down

0 comments on commit 43783a6

Please sign in to comment.