Skip to content

Commit

Permalink
Fix incorrect shutdown of tls streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 committed Mar 13, 2024
1 parent b77707b commit c8a7a67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion statime-linux/src/ke/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{error::Error, io, sync::Arc};

use rustls::{pki_types::ServerName, ClientConfig};
use tokio::{io::AsyncReadExt, net::TcpStream};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::TcpStream,
};
use tokio_rustls::TlsConnector;

use super::record::{AssociationMode, NextProtocols, PtpKeyRequestMessage, PtpKeyResponseMessage};
Expand All @@ -27,6 +30,7 @@ pub async fn fetch_data(
let mut stream = connector.connect(dnsname, stream).await?;

request.write(&mut stream).await?;
stream.flush().await?;

// we expect the to receive messages to be smaller than data_buf
let mut data_buf = vec![0; 4096];
Expand All @@ -47,6 +51,8 @@ pub async fn fetch_data(
}
};

stream.shutdown().await?;

let records: Vec<_> = records.into_iter().map(|r| r.into_owned()).collect();

Ok(records.try_into()?)
Expand Down
5 changes: 3 additions & 2 deletions statime-linux/src/ke/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use log::{debug, info, warn, LevelFilter};
use rustls::ServerConfig;
use tokio::{
io::AsyncReadExt,
io::{AsyncReadExt, AsyncWriteExt},
net::{TcpListener, TcpStream},
sync::RwLock,
time::Instant,
Expand Down Expand Up @@ -214,7 +214,8 @@ async fn handle_connection(

let keyset = store.read().await;
let resp = respond(records, &keyset, ke_config).await?;
resp.write(stream).await?;
resp.write(&mut stream).await?;
stream.shutdown().await?;
Ok(())
}

Expand Down

0 comments on commit c8a7a67

Please sign in to comment.