Skip to content

Commit 7e0267b

Browse files
authored
Merge pull request #208 from talves-forked/main
[Update] examples to use rustls-platform-verifier
2 parents c7569a5 + fe841a5 commit 7e0267b

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed

examples/postgres/pooled-with-rustls/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ diesel = { version = "2.2.0", default-features = false, features = ["postgres"]
1010
diesel-async = { version = "0.5.0", path = "../../../", features = ["bb8", "postgres"] }
1111
futures-util = "0.3.21"
1212
rustls = "0.23.8"
13-
rustls-native-certs = "0.7.1"
13+
rustls-platform-verifier = "0.5.0"
1414
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
1515
tokio-postgres = "0.7.7"
16-
tokio-postgres-rustls = "0.12.0"
16+
tokio-postgres-rustls = "0.13.0"

examples/postgres/pooled-with-rustls/src/main.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use diesel_async::pooled_connection::ManagerConfig;
55
use diesel_async::AsyncPgConnection;
66
use futures_util::future::BoxFuture;
77
use futures_util::FutureExt;
8+
use rustls::ClientConfig;
9+
use rustls_platform_verifier::ConfigVerifierExt;
810
use std::time::Duration;
911

1012
#[tokio::main]
@@ -42,9 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4244
fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConnection>> {
4345
let fut = async {
4446
// We first set up the way we want rustls to work.
45-
let rustls_config = rustls::ClientConfig::builder()
46-
.with_root_certificates(root_certs())
47-
.with_no_client_auth();
47+
let rustls_config = ClientConfig::with_platform_verifier();
4848
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
4949
let (client, conn) = tokio_postgres::connect(config, tls)
5050
.await
@@ -54,10 +54,3 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
5454
};
5555
fut.boxed()
5656
}
57-
58-
fn root_certs() -> rustls::RootCertStore {
59-
let mut roots = rustls::RootCertStore::empty();
60-
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
61-
roots.add_parsable_certificates(certs);
62-
roots
63-
}

examples/postgres/run-pending-migrations-with-rustls/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ diesel = { version = "2.2.0", default-features = false, features = ["postgres"]
1010
diesel-async = { version = "0.5.0", path = "../../../", features = ["bb8", "postgres", "async-connection-wrapper"] }
1111
diesel_migrations = "2.2.0"
1212
futures-util = "0.3.21"
13-
rustls = "0.23.10"
14-
rustls-native-certs = "0.7.1"
13+
rustls = "0.23.8"
14+
rustls-platform-verifier = "0.5.0"
1515
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt-multi-thread"] }
1616
tokio-postgres = "0.7.7"
17-
tokio-postgres-rustls = "0.12.0"
17+
tokio-postgres-rustls = "0.13.0"

examples/postgres/run-pending-migrations-with-rustls/src/main.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use diesel_async::AsyncPgConnection;
44
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
55
use futures_util::future::BoxFuture;
66
use futures_util::FutureExt;
7+
use rustls::ClientConfig;
8+
use rustls_platform_verifier::ConfigVerifierExt;
79

810
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
911

@@ -28,9 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2830
fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConnection>> {
2931
let fut = async {
3032
// We first set up the way we want rustls to work.
31-
let rustls_config = rustls::ClientConfig::builder()
32-
.with_root_certificates(root_certs())
33-
.with_no_client_auth();
33+
let rustls_config = ClientConfig::with_platform_verifier();
3434
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config);
3535
let (client, conn) = tokio_postgres::connect(config, tls)
3636
.await
@@ -39,10 +39,3 @@ fn establish_connection(config: &str) -> BoxFuture<ConnectionResult<AsyncPgConne
3939
};
4040
fut.boxed()
4141
}
42-
43-
fn root_certs() -> rustls::RootCertStore {
44-
let mut roots = rustls::RootCertStore::empty();
45-
let certs = rustls_native_certs::load_native_certs().expect("Certs not loadable!");
46-
roots.add_parsable_certificates(certs);
47-
roots
48-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy