Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snmp2"
version = "0.4.14"
version = "0.4.15"
edition = "2021"
description = "SNMP v1/v2/v3 sync/async client library with traps and MIB support"
authors = ["Serhij S. <div@altertech.com>"]
Expand All @@ -21,12 +21,29 @@ snmptools = { version = "^0.1.2", optional = true }
tokio = { version = "1.47", features = ["net"], optional = true }
openssl = { version = "0.10", optional = true }

md-5 = { version = "0.10", optional = true }
sha1 = { version = "0.10", optional = true }
digest = { version = "0.10", optional = true }
sha2 = { version = "0.10", optional = true }
aes = { version = "0.8", optional = true }
cipher = { version = "0.4", optional = true }
des = { version = "0.8", optional = true }
hmac = { version = "0.12", optional = true }
cbc = { version = "0.1", optional = true }
cfb-mode = { version = "0.8", optional = true }
rand = { version = "0.9", optional = true }

[dev-dependencies]
tokio = { version = "=1.47" }
tokio = { version = "1" }

[features]
default = ["tokio", "v3_rust"]

mibs = ["dep:snmptools"]
tokio = ["dep:tokio"]
v3 = ["openssl"]
v3 = []
heap_buffers = []
full = ["mibs", "tokio", "v3"]
full = ["mibs", "tokio", "v3_rust"]

v3_openssl = ["v3", "openssl"]
v3_rust = ["v3", "md-5", "sha1", "digest", "sha2", "aes", "cipher", "des", "hmac", "cbc", "cfb-mode", "rand"]
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Supports:
- Synchronous/Asynchronous requests
- UDP transport
- MIBs (with `mibs` feature, requires `libnetsnmp`)
- SNMP v3 (requires `v3` feature)
- SNMP v3 (enable `v3_openssl` or `v3_rust` feature)

# Examples

Expand Down Expand Up @@ -139,7 +139,7 @@ let socket = UdpSocket::bind("0.0.0.0:1161").unwrap();
socket.send_to(&bytes, target_addr).unwrap();
```

### With SNMPv3 (requires `v3` feature)
### With SNMPv3 (enable `v3_openssl` or `v3_rust`)

When using SNMPv3, you need to provide the security context to convert the PDU to bytes:

Expand Down Expand Up @@ -210,9 +210,13 @@ assert_eq!(snmp_oid, snmp_oid2);

# SNMPv3

- Requires `v3` crate feature.
- Requires enabling one of the features: `v3_openssl` or `v3_rust`.
- `v3_openssl`: uses OpenSSL for hashing/HMAC and symmetric encryption.
- `v3_rust`: uses pure Rust crypto crates for hashing/HMAC and encryption.

- All cryptographic algorithms are provided by [openssl](https://www.openssl.org/).
- Cryptographic algorithms are provided by the selected backend:
- `v3_openssl`: [openssl](https://www.openssl.org/)
- `v3_rust`: pure Rust crates [Rust Crypto](https://github.com/RustCrypto): (`md-5`, `sha1`, `sha2`, `hmac`, `aes`, `des`, etc.)

- For authentication, supports: MD5 (RFC3414), SHA1 (RFC3414) and non-standard
SHA224, SHA256, SHA384, SHA512.
Expand All @@ -221,8 +225,22 @@ assert_eq!(snmp_oid, snmp_oid2);
AES192-CFB, AES256-CFB. Additional/different AES modes are not supported and
may require patching the crate.

Note: DES legacy encryption may be disabled in openssl by default or even not
supported at all. Refer to the library documentation how to enable it.
Note: For `v3_openssl`, DES legacy encryption may be disabled in OpenSSL by default
or not supported at all. Refer to the library documentation how to enable it.

### Feature selection examples

Pure Rust backend:

```shell
cargo add snmp2 --features v3_rust
```

OpenSSL backend (Windows-friendly vendored build):

```shell
cargo add snmp2 --features "v3_openssl,openssl/vendored"
```

## Example

Expand Down Expand Up @@ -261,21 +279,22 @@ loop {
}
```

## Building
## Building (`v3_openssl`)

In case of problems (e.g. with [cross-rs](https://github.com/cross-rs/cross)),
add `openssl` with `vendored` feature:
When using the `v3_openssl` backend, in case of problems (e.g. with
[cross-rs](https://github.com/cross-rs/cross)), add `openssl` with `vendored` feature:

```shell
cargo add openssl --features vendored
```

## FIPS-140 support
## FIPS-140 support (`v3_openssl`)

The crate uses openssl cryptography only and becomes FIPS-140 compliant as soon
When using the `v3_openssl` backend, the crate becomes FIPS-140 compliant as soon
as FIPS mode is activated in `openssl`. Refer to the
[openssl crate](https://docs.rs/openssl) crate and
[openssl library](https://www.openssl.org/) documentation for more details.
The `v3_rust` backend does not rely on OpenSSL and is not FIPS-certified.

## MSRV

Expand Down
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
let has_v3 = std::env::var("CARGO_FEATURE_V3").is_ok();
let has_v3_openssl = std::env::var("CARGO_FEATURE_V3_OPENSSL").is_ok();
let has_v3_rust = std::env::var("CARGO_FEATURE_V3_RUST").is_ok();

match (has_v3_openssl, has_v3_rust) {
(true, false) | (false, true) => {} // OK
(true, true) => panic!("feature_v3_openssl and feature_v3_rust are mutually exclusive!"),
(false, false) => {
if has_v3 {
panic!("feature_v3_openssl or feature_v3_rust is required")
}
}
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod snmp;
mod syncsession;
#[cfg(feature = "v3")]
pub mod v3;
#[cfg(feature = "v3")]
#[cfg(feature = "v3_openssl")]
pub use openssl;
pub use syncsession::SyncSession;
#[cfg(feature = "tokio")]
Expand Down Expand Up @@ -141,7 +141,7 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "v3")]
#[cfg(feature = "v3_openssl")]
impl From<openssl::error::ErrorStack> for Error {
fn from(err: openssl::error::ErrorStack) -> Error {
Error::Crypto(err.to_string())
Expand Down
Loading