Skip to content

Commit

Permalink
Forced TLS 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 authored and rnijveld committed Jul 18, 2024
1 parent 3e98fa8 commit bd4858d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 10 additions & 5 deletions ntpd/src/daemon/keyexchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use libc::{ECONNABORTED, EMFILE, ENFILE, ENOBUFS, ENOMEM};
use ntp_proto::{
KeyExchangeClient, KeyExchangeError, KeyExchangeResult, KeyExchangeServer, KeySet,
};
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
use rustls::{
pki_types::{CertificateDer, PrivateKeyDer},
version::TLS13,
};
use tokio::{
io::{AsyncRead, AsyncWrite, ReadBuf},
net::TcpListener,
Expand Down Expand Up @@ -42,9 +45,11 @@ async fn build_client_config(
.map_err(KeyExchangeError::Certificate)?;
}

Ok(rustls::ClientConfig::builder()
.with_root_certificates(roots)
.with_no_client_auth())
Ok(
rustls::ClientConfig::builder_with_protocol_versions(&[&TLS13])
.with_root_certificates(roots)
.with_no_client_auth(),
)
}

pub(crate) async fn key_exchange_client(
Expand Down Expand Up @@ -149,7 +154,7 @@ fn build_server_config(
certificate_chain: Vec<CertificateDer<'static>>,
private_key: PrivateKeyDer<'static>,
) -> std::io::Result<Arc<rustls::ServerConfig>> {
let mut config = rustls::ServerConfig::builder()
let mut config = rustls::ServerConfig::builder_with_protocol_versions(&[&TLS13])
.with_client_cert_verifier(Arc::new(
#[cfg(not(feature = "unstable_nts-pool"))]
rustls::server::NoClientAuth,
Expand Down
9 changes: 6 additions & 3 deletions nts-pool-ke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use ntp_proto::{
AeadAlgorithm, ClientToPoolData, KeyExchangeError, NtsRecord, PoolToServerData,
PoolToServerDecoder, SupportedAlgorithmsDecoder,
};
use rustls::pki_types::{CertificateDer, ServerName};
use rustls::{
pki_types::{CertificateDer, ServerName},
version::TLS13,
};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::{TcpListener, ToSocketAddrs},
Expand Down Expand Up @@ -179,7 +182,7 @@ async fn pool_key_exchange_server(
) -> std::io::Result<()> {
let listener = TcpListener::bind(address).await?;

let mut config = rustls::ServerConfig::builder()
let mut config = rustls::ServerConfig::builder_with_protocol_versions(&[&TLS13])
.with_no_client_auth()
.with_single_cert(certificate_chain.clone(), private_key.clone_key())
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))?;
Expand Down Expand Up @@ -459,7 +462,7 @@ fn pool_to_server_connector(
.map_err(KeyExchangeError::Certificate)?;
}

let config = rustls::ClientConfig::builder()
let config = rustls::ClientConfig::builder_with_protocol_versions(&[&TLS13])
.with_root_certificates(roots)
.with_client_auth_cert(certificate_chain, private_key)
.unwrap();
Expand Down

0 comments on commit bd4858d

Please sign in to comment.