Skip to content

Commit

Permalink
Verify Transport is TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Feb 24, 2025
1 parent 3b868e5 commit cf9eb7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ pub enum Error {
/// Attempt to connect to a CONNECT proxy failed.
ConnectProxyFailed(String),

/// The protocol requires TLS (https), but the connector did not
/// create a TLS secured transport.
///
/// This typically indicates a fault in bespoke `Connector` chains.
TlsRequired,

/// hoot made no progress and there is no more input to read.
///
/// We should never see this value.
Expand Down Expand Up @@ -230,6 +236,7 @@ impl fmt::Display for Error {
#[cfg(feature = "json")]
Error::Json(v) => write!(f, "json: {}", v),
Error::ConnectProxyFailed(v) => write!(f, "CONNECT proxy failed: {}", v),
Error::TlsRequired => write!(f, "TLS required, but transport is unsecured"),
Error::BodyStalled => write!(f, "body data reading stalled"),
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl Connection {
pool.purge(now);
}

pub fn is_tls(&self) -> bool {
self.transport.is_tls()
}

fn age(&self, now: Instant) -> Duration {
now.duration_since(now)
}
Expand Down
4 changes: 4 additions & 0 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ fn connect(

let connection = agent.pool.connect(&details, config.max_idle_age().into())?;

if details.needs_tls() && !connection.is_tls() {
return Err(Error::TlsRequired);
}

timings.record_time(Timeout::Connect);

Ok(connection)
Expand Down
4 changes: 4 additions & 0 deletions src/unversioned/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,8 @@ where
fn is_open(&mut self) -> bool {
(**self).is_open()
}

fn is_tls(&self) -> bool {
(**self).is_tls()
}
}

0 comments on commit cf9eb7a

Please sign in to comment.