| Crates.io | mtls-core |
| lib.rs | mtls-core |
| version | 0.1.0 |
| created_at | 2026-01-01 15:36:59.35176+00 |
| updated_at | 2026-01-01 15:36:59.35176+00 |
| description | Core mTLS authentication library with IP whitelisting for Rust applications |
| homepage | |
| repository | https://github.com/Crellsin/mtls-rs |
| max_upload_size | |
| id | 2016346 |
| size | 109,497 |
Core mTLS authentication library with IP whitelisting for Rust applications.
mtls-core provides a robust, async-first library for mutual TLS (mTLS) authentication with built-in IP whitelisting capabilities. It's designed to be framework-agnostic and can be used with various Rust web frameworks and network protocols.
Add to your Cargo.toml:
[dependencies]
mtls-core = "0.1.0"
use mtls_core::validator::ConnectionValidator;
use mtls_core::config::ServerConfig;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server_config = ServerConfig::new(
Path::new("certs/server.crt"),
Path::new("certs/server.key"),
Path::new("certs/ca.crt"),
);
let validator = ConnectionValidator::create_for_server(server_config)?;
// Use validator to validate incoming connections
// (See TCP adapter or framework-specific adapters for complete examples)
Ok(())
}
use mtls_core::validator::ConnectionValidator;
use mtls_core::config::ClientConfig;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client_config = ClientConfig::new(
Path::new("certs/client.crt"),
Path::new("certs/client.key"),
)
.with_ca_cert_path(Path::new("certs/ca.crt"));
let validator = ConnectionValidator::create_for_client(client_config)?;
// Validate outgoing connection
let result = validator.validate_outgoing("example.com", 443).await?;
if result.is_valid {
println!("Connection validated successfully!");
} else {
eprintln!("Connection validation failed: {:?}", result.failure_reason);
}
Ok(())
}
For framework-specific integration, see:
mtls-actix: Actix Web middlewaremtls-rocket: Rocket fairingmtls-tcp: Raw TCP adaptermtls-grpc: gRPC (tonic) adapteruse mtls_core::config::ServerConfig;
use ipnetwork::IpNetwork;
let config = ServerConfig::new(
Path::new("server.crt"),
Path::new("server.key"),
Path::new("ca.crt"),
)
.with_client_ipv4_whitelist(vec![
IpNetwork::new("192.168.1.0".parse()?, 24)?,
IpNetwork::new("10.0.0.0".parse()?, 8)?,
])
.with_require_client_auth(true);
use mtls_core::config::ClientConfig;
let config = ClientConfig::new(
Path::new("client.crt"),
Path::new("client.key"),
)
.with_ca_cert_path(Path::new("ca.crt"))
.with_verify_server(true);
The library uses a comprehensive error type MtlsError that covers all possible failure modes:
Run the test suite:
cargo test --workspace
The project includes comprehensive integration tests with pre-generated test certificates.
Dual-licensed under either:
at your option.
Contributions are welcome! Please see the main project repository for contribution guidelines.