tokio-postgres-rustls-improved
NOTE: This is a fork; the original tokio-postgres-rustls repo appears to be unmaintained and has known bugs with virtually no test coverage or CI pipeline.
NOTE: Channel binding is not supported with Ed25519 certificates. This appears to be a limitation of Postgres, including Postgres 18.
Improvements over original tokio-postgres-rustls
:
0.15.2:
- Support for
ECDSA_WITH_SHA512
channel binding (i.e. ECDSA P-521, secp521r1, NIST P-521) NOTE: only supported byaws-lc-rs
(default); unsupported withring
crypto provider - Integration test matrix to validate Postgres 13 through 18 with rustc MSRV, stable, and nightly.
0.15.1:
- Removed unsafe code (thanks @conradludgate)
- Fixes SCRAM/SASL channel binding (was non-functional in all cases in original
tokio-postgres-rustls
) - Support for
aws-lc-rs
instead ofring
(defaults toaws-lc-rs
; consistent withrustls
defaults) - Comprehensive integration test suite that runs with both
ring
andaws-lc-rs
This is an integration between the rustls TLS stack and the tokio-postgres asynchronous PostgreSQL client library.
Use this crate directly:
With aws-lc-rs
(default for rustls
):
With ring
:
Have a 3rd-party dependency that relies on the original tokio-postgres-rustls
?
Patch in our fork that maintains the original crate name like this:
With aws-lc-rs
feature:
[]
= { = "https://github.com/khorsolutions/tokio-postgres-rustls-patch.git", = "aws-lc-rs" }
With ring
feature:
[]
= { = "https://github.com/khorsolutions/tokio-postgres-rustls-patch.git", = "ring" }
Example
See tests/integration.rs
for actual usage examples, including SASL/SCRAM using Channel Binding.
use ;
use MakeRustlsConnect;
// Build a [`rustls::RootCertStore`] and client certs
let roots = ;
let client_certs = todo!;
let client_key = todo!;
// Setup a `rustls::ClientConfig` (see Rustls docs for more info)
let tls_config = builder
.with_root_certificates
.with_client_auth_cert
.expect;
// MakeRustlsConnect is provided by this library; it wraps a `rustls::CLientConfig`
let tls = new;
// Connect as usual with `tokio-postgres`, providing our `MakeRustlsConnect` as the `tls` arg
let mut pg_config = new;
pg_config
.host
.port
.dbname
.user
.password
.ssl_mode
.channel_binding;
let = pg_config.connect.await.expect;
NOTE: please use proper error handling in production code, this is an excerpt from tests that are expected to panic in a failure
License
tokio-postgres-rustls-improved is distributed under the MIT license