X509 Client
X509 Client is an async X509 certificate transport and deserializer for Rust.
Synopsis
Supported transports:
- HTTP/S
- File
Supported encoding formats:
- CER - single DER-encoded certificate
- PEM - stack of one or more PEM-encoded certificates
- PKCS7 - DER-encoded PKCS7 certificate bundle
Usage
The RustCrypto-based DefaultX509Iterator implementation is available by default.
[dependencies]
x509_client = { version = "1" }
Enable the openssl feature for access to the provided OpenSSL-based OpenSSLX509Iterator deserializer.
[dependencies]
x509_client = { version = "1", features = ["openssl"] }
The X509 Client is data-model agnostic. When constructing the client, use the turbofish expression to choose the deserializer implementation.
use ;
use DefaultX509Iterator;
async
Example
Transfer and parse a single certificate and multiple certificates, using the default DefaultX509Iterator implementation.
use Certificate;
use ;
use DefaultX509Iterator;
use ClientBuilder;
async
async
Instantiation and Configuration
A default X509 Client can be instantiated with the crate::X509Client::default trait implementation.
let client = X509Client::<DefaultX509Iterator>::default();
The X509 Client can be configured by passing the X509ClientConfiguration to the client crate::X509Client::new constructor:
let client = X509Client::<DefaultX509Iterator>::new(config);
The X509ClientConfiguration struct is defined as:
// Default configuration
X509ClientConfiguration ;
Transfer and Deserialize
The X509Client::get method transfers and parses the first certificate, returning an error on empty.
The X509Client::get_all method transfers and parses all certificates.
Deserialization
The client will attempt to determine the encoding of the remote certificate before parsing.
If strict configuration is enabled, the client will only attempt to parse once. The client will return an error immediately if the encoding type cannot be determined.
If strict configuration is disabled (default), the client will attempt to parse all known formats (starting with its best guess) before returning an error.
Some deserialization implementations may return an empty iterator. The text encoding specification for PKIX (PEM) RFC 7468 states that:
Parsers MUST handle non-conforming data gracefully.
And:
Files MAY contain multiple textual encoding instances. This is used, for example, when a file contains several certificates.
Implying an "empty" PEM file is valid. For this reason, the X509 Client always attempts to parse PEM last when strict is disabled.
For HTTP transport, certificate type is determined by the Content-Type http header:
- application/pkix-cert : CER
- application/pem-certificate-chain : PEM
- application/pkcs7-mime : PKCS7
For File scheme, certificate type is determined by the filename extension (.ext):
- .cer : CER
- .pem : PEM
- .p7c : PKCS7
API
The X509 Client is data-model agnostic - the X509Iterator trait is used to define the deserializer interface.
use ;
/// X509 Deserializer API
/// Error type bounds
Error Handling
An X509Iterator implementation can return any error type defined by the X509Iterator::X509IteratorError associated type, bound by the X509IteratorError trait. The X509IteratorError trait itself is bound only by Display + Debug.
Iterator errors will be surfaced to the caller in the X509ClientError::X509IteratorError variant.
Error conversion is implemented as:
use ;
use X509ClientError;
use X509IteratorError;
;
Implementations
Default
The RustCrypto-based DefaultX509Iterator implementation is available if default features are enabled.
OpenSSL
The OpenSSL-based implementation OpenSSLX509Iterator is available if the openssl feature is enabled.
Debug
The debug implementation DebugX509Iterator is always available. It copies the bytes returned by server into a Once<bytes::Bytes> iterator.