Skip to content

Commit

Permalink
fix: Fix default TLS configuration hostname not set (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 authored Jan 1, 2025
1 parent 772bcc5 commit 44b8216
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/tls/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl Default for HttpsLayerSettings {
skip_session_ticket: false,
application_settings: false,
enable_ech_grease: false,
verify_hostname: false,
tls_sni: false,
verify_hostname: true,
tls_sni: true,
alpn_protos: HttpVersionPref::All,
}
}
Expand Down Expand Up @@ -95,13 +95,13 @@ impl HttpsLayerSettingsBuilder {
self
}

/// Sets whether to enable TLS SNI. Defaults to `false`.
/// Sets whether to enable TLS SNI. Defaults to `true`.
pub fn tls_sni(mut self, enable: bool) -> Self {
self.0.tls_sni = enable;
self
}

/// Sets whether to enable hostname verification. Defaults to `false`.
/// Sets whether to enable hostname verification. Defaults to `true`.
pub fn verify_hostname(mut self, enable: bool) -> Self {
self.0.verify_hostname = enable;
self
Expand Down
24 changes: 15 additions & 9 deletions src/tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
mod conn;
mod ext;

pub use crate::mimic::Impersonate;
use crate::{impl_debug, tls::cert_compression::CertCompressionAlgorithm, HttpVersionPref};
use boring::{
error::ErrorStack,
ssl::{SslConnector, SslMethod, SslOptions, SslVersion},
};
pub use conn::{HttpsConnector, MaybeHttpsStream};
use boring::{ssl::SslCurve, x509::store::X509Store};
use conn::{HttpsLayer, HttpsLayerSettings};
use std::borrow::Cow;
use typed_builder::TypedBuilder;

pub use crate::mimic::Impersonate;
pub use conn::{HttpsConnector, MaybeHttpsStream};
pub use ext::{cert_compression, TlsBuilderExtension, TlsConnectExtension};

type TlsResult<T> = Result<T, ErrorStack>;
Expand Down Expand Up @@ -116,13 +121,13 @@ impl BoringTlsConnector {

// Create the `HttpsLayerSettings` with the default session cache capacity.
let settings = HttpsLayerSettings::builder()
.session_cache_capacity(8)
.session_cache(settings.pre_shared_key)
.skip_session_ticket(settings.psk_skip_session_ticket)
.alpn_protos(settings.alpn_protos)
.application_settings(settings.application_settings)
.enable_ech_grease(settings.enable_ech_grease)
.tls_sni(settings.tls_sni)
.verify_hostname(settings.verify_hostname)
.build();

Ok(Self(HttpsLayer::with_connector_and_settings(
Expand Down Expand Up @@ -162,11 +167,6 @@ impl TlsInfo {
}
}

use crate::{impl_debug, tls::cert_compression::CertCompressionAlgorithm, HttpVersionPref};
use boring::{ssl::SslCurve, x509::store::X509Store};
use std::borrow::Cow;
use typed_builder::TypedBuilder;

#[derive(Default)]
pub enum RootCertsStore {
Owned(X509Store),
Expand Down Expand Up @@ -224,7 +224,7 @@ where
}
}

#[derive(TypedBuilder, Default)]
#[derive(TypedBuilder)]
pub struct TlsSettings {
#[builder(default)]
pub root_certs_store: RootCertsStore,
Expand Down Expand Up @@ -299,6 +299,12 @@ pub struct TlsSettings {
pub extension_permutation_indices: Option<Cow<'static, [u8]>>,
}

impl Default for TlsSettings {
fn default() -> Self {
Self::builder().build()
}
}

impl_debug!(
TlsSettings,
{
Expand Down

0 comments on commit 44b8216

Please sign in to comment.