tls-helpers
A Rust library that simplifies working with TLS certificates and keys in base64 format. This library provides convenient utilities for creating TLS acceptors and connectors from base64-encoded certificates and private keys.
Features
- Load certificates and private keys from base64-encoded strings
- Create TLS connectors with custom CA certificates
- Create TLS acceptors with support for HTTP/1.x and HTTP/2
- Built on top of
rustls
for robust TLS implementation - Zero-copy certificate handling where possible
- ALPN protocol negotiation support
Usage
Loading Certificates and Keys
use ;
// Load certificates from base64
let certs = certs_from_base64?;
// Load private key from base64
let private_key = privkey_from_base64?;
Creating a TLS Connector (Client)
use tls_connector_from_base64;
// Create a TLS connector with custom CA certificate
let connector = tls_connector_from_base64?;
// Use the connector with a TLS connection
let stream = connector.connect.await?;
Creating a TLS Acceptor (Server)
use tls_acceptor_from_base64;
// Create a TLS acceptor with HTTP/1.1 and HTTP/2 support
let acceptor = tls_acceptor_from_base64?;
// Use the acceptor with incoming connections
let tls_stream = acceptor.accept.await?;
Raw Base64 Decoding
use from_base64_raw;
// Decode raw base64 data
let raw_bytes = from_base64_raw?;
Error Handling
The library uses standard Rust error handling patterns:
- Functions return
io::Result<T>
for basic operations - More complex operations return
Result<T, Box<dyn std::error::Error>>
orResult<T, Box<dyn std::error::Error + Send + Sync>>
- Detailed error messages are provided for common failure cases
Security Notes
- The library uses
rustls
instead of OpenSSL for improved memory safety - Private keys are expected to be in PKCS8 format
- Supports modern TLS versions through
rustls
- No support for legacy or insecure protocols
- Memory containing private keys is zeroed when dropped
Performance
- Zero-copy operations where possible
- Efficient base64 decoding using the
base64
crate - Single-allocation certificate chain building
- Shared configurations through
Arc
for multiple connections
Examples
Complete Server Setup
use tls_acceptor_from_base64;
use TcpListener;
async
Complete Client Setup
use tls_connector_from_base64;
use TcpStream;
async
License
MIT