rust-openssl

Safe, idiomatic Rust bindings to OpenSSL

Library
Cargo
v0.10.81
1,646 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
85 /100 Excellent
Development Activity 80
Maintenance 80
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 87
Code Quality 88
Innovation 65
Learning Curve 60

rust-openssl provides idiomatic, memory-safe Rust bindings to the OpenSSL cryptography library, covering TLS/SSL client and server connections, X.509 certificate parsing and generation, symmetric and asymmetric encryption, digital signatures, message digests/HMAC, and PKCS#7/CMS/PKCS#12 handling. The high-level openssl crate wraps the raw FFI declarations exposed by the lower-level openssl-sys crate, converting OpenSSL’s C API into safe Rust types with RAII-managed lifetimes, Result-based error handling, and Rust-native traits.

The workspace also includes openssl-macros (internal proc-macros for generating boilerplate wrapper types) and openssl-errors (structured error-code definitions). It supports building against a system-installed OpenSSL, a vendored/statically-built OpenSSL via the vendored feature, or alternative implementations like BoringSSL and AWS-LC through feature flags, making it the most widely used cryptography/TLS binding in the Rust ecosystem — it underlies major HTTP clients and servers that need OpenSSL-compatible TLS rather than a pure-Rust TLS stack.

What You Get

  • Safe wrappers for TLS/SSL client and server connections (SslConnector, SslAcceptor) built directly on OpenSSL’s SSL_CTX/SSL types
  • X.509 certificate parsing, generation, and verification, including certificate signing requests and extensions
  • Symmetric ciphers (AES, ChaCha20, etc.), asymmetric crypto (RSA, EC, Ed25519/X25519), message digests, and HMAC via a unified Cipher/MessageDigest API
  • PKCS#7/CMS and PKCS#12 support for signing, enveloping, and certificate-bundle handling
  • A vendored feature to statically build and link OpenSSL from source instead of depending on the system library, plus alternative-backend features for BoringSSL and AWS-LC
  • The lower-level openssl-sys crate for anyone who needs raw FFI access beyond the safe high-level API

Common Use Cases

  • Adding TLS support to a Rust HTTP client or server that needs OpenSSL-compatible behavior (cipher suite parity, corporate CA trust stores) rather than a pure-Rust TLS stack like rustls
  • Parsing, validating, or generating X.509 certificates as part of a PKI or certificate-management tool
  • Implementing application-level encryption or signing (message digests, HMAC, RSA/EC signatures) using OpenSSL’s audited cryptographic primitives
  • Statically bundling OpenSSL into a deployed binary via the vendored feature to avoid depending on the target system’s OpenSSL version

Under The Hood

Architecture - The workspace layers three main crates: openssl-sys declares raw unsafe extern "C" FFI bindings generated against OpenSSL’s C headers (with bindgen support for regenerating them); openssl wraps every FFI type in a safe Rust struct using RAII (Drop implementations call the matching _free function) and converts C-style error codes into Result<T, ErrorStack>; and openssl-macros supplies proc-macros that generate the repetitive foreign_type!-style boilerplate needed to wrap each OpenSSL opaque pointer type consistently. openssl-errors centralizes structured error-code-to-message mappings. systest is a workspace-internal crate that fuzzes the FFI layer against the real OpenSSL headers to catch signature drift. Tech Stack - Pure Rust (edition 2021, MSRV 1.80.0) with feature flags controlling the crypto backend: default builds link a system OpenSSL, vendored statically compiles OpenSSL from source via the openssl-src build dependency, and separate features swap in BoringSSL or AWS-LC (including AWS-LC’s FIPS-validated build) as drop-in alternatives to upstream OpenSSL. Code Quality - The openssl crate alone spans ~36,700 lines of Rust, reflecting the breadth of OpenSSL’s API surface it wraps; clippy.toml enforces linting workspace-wide, and the systest crate exists specifically to catch FFI signature mismatches between openssl-sys’s hand-maintained bindings and the actual OpenSSL headers — an unusual, deliberate quality safeguard for a crate whose correctness has direct security implications. API Design - Common operations like establishing a TLS connection or hashing data require only a few calls (SslConnector::builder(), MessageDigest::sha256()), with Rust idioms (builders, Result, RAII) replacing OpenSSL’s verbose C initialization/cleanup patterns; the trade-off is that some very low-level or version-specific OpenSSL behavior still requires dropping down to openssl-sys directly.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers