hyper-custom-cert
A small, ergonomic HTTP client wrapper around hyper with optional support for custom Root CAs and a dev-only insecure mode for self-signed certificates.
Features
- Secure by Default: Uses the operating system's native trust store via
native-tls
- Custom CA Support: Optional
rustls
feature for connecting to services with custom Certificate Authorities - Development Mode: Optional
insecure-dangerous
feature for testing with self-signed certificates (⚠️ NEVER use in production) - WebAssembly Compatible: Proper WASM support with appropriate security constraints
- Certificate Pinning: Advanced security feature for production environments
- Builder Pattern: Ergonomic configuration with sensible defaults
Quick Start
cargo add hyper-custom-cert
Basic Usage (Secure Default)
use HttpClient;
async
Custom Root CA (Production)
For connecting to services with custom/private Certificate Authorities:
[]
= { = "0.1.0", = ["rustls"] }
use HttpClient;
async
Certificate Pinning (Enhanced Security)
For high-security environments where you want to pin specific certificates:
use HttpClient;
async
Development/Testing Only (⚠️ Dangerous)
WARNING: This mode disables certificate validation. Only use for local development and testing.
[]
= { = "0.1.0", = ["insecure-dangerous"] }
use HttpClient;
async
Configuration Options
Builder Methods
use HttpClient;
use Duration;
use HashMap;
let mut headers = new;
headers.insert;
let client = builder
.with_timeout
.with_default_headers
.with_root_ca_file // Requires 'rustls' feature
.build;
Available Methods
Method | Feature Required | Description |
---|---|---|
new() |
None | Creates client with OS trust store (secure default) |
builder() |
None | Returns a builder for custom configuration |
with_timeout(Duration) |
None | Sets request timeout |
with_default_headers(HashMap) |
None | Sets default headers for all requests |
with_root_ca_pem(&[u8]) |
rustls |
Adds custom CA from PEM bytes |
with_root_ca_file(Path) |
rustls |
Adds custom CA from PEM file |
with_pinned_cert_sha256(Vec<[u8; 32]>) |
rustls |
Enables certificate pinning |
insecure_accept_invalid_certs(bool) |
insecure-dangerous |
⚠️ Disables certificate validation |
with_self_signed_certs() |
insecure-dangerous |
⚠️ Convenience for self-signed certs |
Feature Flags
native-tls
(Default)
- Default: ✅ Enabled
- Security: ✅ Secure - Uses OS trust store
- Use Case: Public HTTPS endpoints with standard certificates
- Dependencies:
hyper-tls
,native-tls
rustls
- Default: ❌ Disabled
- Security: ✅ Secure - Custom CA validation
- Use Case: Private/custom Certificate Authorities
- Dependencies:
hyper-rustls
,rustls-pemfile
- Enables:
with_root_ca_pem()
,with_root_ca_file()
,with_pinned_cert_sha256()
insecure-dangerous
- Default: ❌ Disabled
- Security: ❌ EXTREMELY DANGEROUS
- Use Case: Development/testing ONLY
- Warning: NEVER enable in production
- Enables:
insecure_accept_invalid_certs()
,with_self_signed_certs()
WebAssembly (WASM) Support
This crate supports WebAssembly targets with important security considerations:
// WASM builds will compile, but certain operations are restricted
WASM Limitations:
- Custom Root CA installation requires browser/OS-level certificate management
- Some TLS configuration options may not be available
- Certificate pinning may be limited by browser security policies
Browser Certificate Installation:
- Download your organization's Root CA certificate
- Install it in your browser's certificate store
- Mark it as trusted for websites
- Your WASM application will then trust endpoints signed by that CA
Error Handling
use ;
match client.request.await
Security Best Practices
Production Recommendations
- Use Default Mode: Stick with
native-tls
for public endpoints - Custom CA Only When Needed: Only use
rustls
feature when connecting to private CAs - Never Use
insecure-dangerous
: This feature should never be enabled in production - Keep Dependencies Updated: Monitor for security advisories
- Certificate Pinning: Consider pinning for high-security applications
Development vs Production
// ✅ GOOD: Production configuration
let client = new; // Uses OS trust store
// ✅ GOOD: Development configuration
let client = builder
.insecure_accept_invalid_certs // Only in debug builds
.build;
Examples
See the examples/
directory for complete working examples:
examples/self-signed-certs/
- Comprehensive examples for all modes- Example of connecting to public endpoints (default mode)
- Example of using custom Root CA for private services
- Example of development mode with self-signed certificates
Testing
# Test with default features
# Test with rustls features
# Test with all features (for development)
# Test WASM compatibility
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass:
cargo test --all-features
- Submit a pull request
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Security Policy
For security vulnerabilities, please see SECURITY.md for our responsible disclosure policy.
Remember: This library prioritizes security by default. The insecure-dangerous
feature exists solely for development convenience and should never be used in production environments.