Skip to content

Commit a0eed7f

Browse files
committed
fix: remove rustls-pemfile in favour of rustls-pki-types
See this security advisory: https://rustsec.org/advisories/RUSTSEC-2025-0134
1 parent 6f741ed commit a0eed7f

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,22 @@ rand = { version = "0.9.2", default-features = false }
6363
reqwest = { version = "0.12.22", default-features = false }
6464
ring = { version = "0.17.14", default-features = false }
6565
rustls = { version = "0.23.31", default-features = false }
66-
rustls-pemfile = { version = "2.2.0", default-features = false }
66+
rustls-pki-types = { version = "1.12.0", default-features = false }
6767
secrecy = { version = "0.10.3", default-features = false }
6868
sentry = { version = "0.42.0" }
6969
serde = { version = "1.0.219", default-features = false }
7070
serde_json = { version = "1.0.141", default-features = false }
7171
serde_yaml = { version = "0.9.34", default-features = false }
7272
sqlx = { version = "0.8.6", default-features = false }
7373
tempfile = { version = "3.23.0", default-features = false }
74-
thiserror = "2.0.12"
75-
tikv-jemalloc-ctl = { version = "0.6.0", default-features = false, features = ["stats"] }
76-
tikv-jemallocator = { version = "0.6.1", default-features = false, features = ["background_threads_runtime_support", "unprefixed_malloc_on_supported_platforms"] }
74+
thiserror = "2.0.12"
75+
tikv-jemalloc-ctl = { version = "0.6.0", default-features = false, features = [
76+
"stats",
77+
] }
78+
tikv-jemallocator = { version = "0.6.1", default-features = false, features = [
79+
"background_threads_runtime_support",
80+
"unprefixed_malloc_on_supported_platforms",
81+
] }
7782
tokio = { version = "1.47.0", default-features = false }
7883
tokio-postgres = { git = "https://github.com/MaterializeInc/rust-postgres", default-features = false, rev = "c4b473b478b3adfbf8667d2fbe895d8423f1290b" }
7984
tokio-rustls = { version = "0.26.2", default-features = false }

etl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pin-project-lite = { workspace = true }
2828
postgres-replication = { workspace = true }
2929
ring = { workspace = true, default-features = false }
3030
rustls = { workspace = true, features = ["aws-lc-rs", "logging"] }
31-
rustls-pemfile = { workspace = true, features = ["std"] }
31+
rustls-pki-types = { workspace = true, features = ["std"] }
3232
serde_json = { workspace = true, features = ["std"] }
3333
sqlx = { workspace = true, features = ["runtime-tokio-rustls", "postgres"] }
3434
tokio = { workspace = true, features = ["rt-multi-thread"] }

etl/src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,21 @@ impl From<rustls::Error> for EtlError {
913913
}
914914
}
915915

916+
/// Converts [`rustls_pki_types::pem::Error`] to [`EtlError`] with [`ErrorKind::EncryptionError`].
917+
impl From<rustls_pki_types::pem::Error> for EtlError {
918+
#[track_caller]
919+
fn from(err: rustls_pki_types::pem::Error) -> EtlError {
920+
let detail = err.to_string();
921+
let source = Arc::new(err);
922+
EtlError::from_components(
923+
ErrorKind::EncryptionError,
924+
Cow::Borrowed("Failed to parse PEM certificate"),
925+
Some(Cow::Owned(detail)),
926+
Some(source),
927+
)
928+
}
929+
}
930+
916931
/// Converts [`uuid::Error`] to [`EtlError`] with [`ErrorKind::InvalidData`].
917932
impl From<uuid::Error> for EtlError {
918933
#[track_caller]

etl/src/replication/client.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use etl_postgres::{below_version, requires_version};
1010
use pg_escape::{quote_identifier, quote_literal};
1111
use postgres_replication::LogicalReplicationStream;
1212
use rustls::ClientConfig;
13+
use rustls_pki_types::CertificateDer;
14+
use rustls_pki_types::pem::PemObject;
1315
use std::collections::HashMap;
1416
use std::fmt;
15-
use std::io::BufReader;
1617
use std::num::NonZeroI32;
1718
use std::sync::Arc;
1819

@@ -223,10 +224,11 @@ impl PgReplicationClient {
223224

224225
let mut root_store = rustls::RootCertStore::empty();
225226
if pg_connection_config.tls.enabled {
226-
let mut root_certs_reader =
227-
BufReader::new(pg_connection_config.tls.trusted_root_certs.as_bytes());
228-
for cert in rustls_pemfile::certs(&mut root_certs_reader) {
229-
let cert = cert?;
227+
let certs = CertificateDer::pem_slice_iter(
228+
pg_connection_config.tls.trusted_root_certs.as_bytes(),
229+
)
230+
.collect::<Result<Vec<_>, _>>()?;
231+
for cert in certs {
230232
root_store.add(cert)?;
231233
}
232234
};

0 commit comments

Comments
 (0)