hyper-custom-cert
A reusable HTTP client builder API with clear, security‑focused feature flags for selecting your TLS backend and security posture.
This crate is derived from a reference implementation in this repository (under reference-implementation/
), but is designed as a reusable library with a more robust and explicit configuration surface. Networking internals are intentionally abstracted for now; the focus is on a secure, ergonomic API.
Features and TLS strategy
-
Default:
native-tls
- Uses the operating system trust store via
hyper-tls
/native-tls
. - Secure default for connecting to standard, publicly trusted endpoints.
- Uses the operating system trust store via
-
Optional:
rustls
- Uses
hyper-rustls
. - Activates the
with_root_ca_pem
method on the builder, allowing you to trust a custom Root CA (recommended approach for custom/private CAs).
- Uses
-
Optional:
insecure-dangerous
- Unlocks
insecure_accept_invalid_certs(true)
andHttpClient::with_self_signed_certs()
. - IMPORTANT: This is for local development/testing only and must NEVER be used in production.
- Unlocks
See SECURITY.md for a thorough discussion of these modes and when to use them.
Quick start
-
Default (native-tls):
-
With rustls (custom Root CA support):
-
Insecure (dangerous, dev only):
# With native-tls # With rustls
Builder API overview
use HttpClient;
use Duration;
use HashMap;
let mut headers = new;
headers.insert;
let mut builder = builder
.with_timeout
.with_default_headers;
// When the `rustls` feature is enabled, you can add a custom Root CA:
let client = builder.build;
// During local development only:
Selecting features
-
Native TLS (default):
cargo add hyper-custom-cert
(or no extra flags if in this workspace)cargo build
-
Rustls:
cargo build --no-default-features --features rustls
-
Insecure (dangerous, dev only):
- With native TLS:
cargo build --features insecure-dangerous
- With rustls:
cargo build --no-default-features --features rustls,insecure-dangerous
- With native TLS:
WASM Support
This library's WASM build is primarily intended for edge runtime environments such as Cloudflare Workers, Deno Deploy, Vercel Edge Functions, and similar serverless edge computing platforms.
Edge Runtime Usage (Primary Use Case)
Edge runtimes provide a more capable WASM environment compared to browsers, often supporting custom certificate configuration and advanced TLS features:
Capabilities in Edge Runtimes:
- Custom Root CA Support: Methods like
with_root_ca_pem()
andwith_root_ca_file()
are typically supported - Certificate Pinning: The
with_pinned_cert_sha256()
method may be available depending on the runtime - Flexible TLS Configuration: Full control over certificate validation and TLS settings
- No Same-Origin Policy: Direct network access without browser security restrictions
Recommended Approach for Edge Runtimes:
Popular Edge Runtime Platforms:
- Cloudflare Workers: Full WASM support with network capabilities
- Deno Deploy: TypeScript/JavaScript runtime with WASM modules
- Vercel Edge Functions: Next.js edge runtime environment
- Fastly Compute@Edge: High-performance edge computing platform
- AWS Lambda@Edge: Serverless edge functions
Browser Usage (Limited Support)
When running in browser environments, WASM operates under significant security restrictions:
Browser Limitations:
- No Custom Root CA Support: Methods like
with_root_ca_pem()
andwith_root_ca_file()
may returnWasmNotImplemented
errors - No Certificate Pinning: The
with_pinned_cert_sha256()
method is not available in browser environments - Browser-Controlled Trust: All certificate validation is handled by the browser's built-in certificate store
- Same-Origin Policy: Cross-origin requests are subject to CORS policies and browser security models
Browser Development Guidance:
For development with self-signed certificates in browsers, you'll need to install certificates in the browser's certificate store rather than configuring them programmatically.
Environment Detection
To handle both edge runtime and browser environments gracefully:
Production Considerations
For Edge Runtimes:
- Leverage full TLS configuration capabilities available in your edge platform
- Use custom CAs and certificate pinning for enhanced security
- Test certificate handling across different edge runtime providers
- Consider platform-specific TLS optimizations
For Browser Applications:
- Always use proper SSL/TLS certificates from trusted CAs
- Consider using Let's Encrypt or other automated certificate management solutions
- Document any certificate requirements clearly for end users
- Plan for browser security policy limitations
Security Notes
- Prefer the default
native-tls
or therustls
feature for production. - The
insecure-dangerous
feature must never be enabled in production; it bypasses certificate validation and exposes you to active MITM risk. - On WASM platforms, certificate handling varies by environment: edge runtimes typically support full custom CA configuration, while browser environments manage certificate validation through built-in certificate stores.