Skip to content

Commit

Permalink
use the denied_servers list to deny servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Folkert de Vries committed Dec 7, 2023
1 parent e1fa0d7 commit 09c5543
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions nts-pool-ke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,13 @@ async fn pick_nts_ke_servers<'a>(
connector: &TlsConnector,
servers: &'a [config::KeyExchangeServer],
selected_algorithm: AeadAlgorithm,
denied_servers: &[String],
) -> Result<(&'a str, u16, ServerName), KeyExchangeError> {
for server in servers {
if denied_servers.contains(&server.domain) {
continue;
}

match pick_nts_ke_server(connector, server, selected_algorithm).await {
Ok(x) => return Ok(x),
Err(e) => match e {
Expand Down Expand Up @@ -299,36 +304,43 @@ async fn handle_client(
// next we should pick a server that satisfies the algorithm used and is not denied by the
// client.
let connector = pool_to_server_connector(&certificate_authority)?;
let (server_name, port, domain) =
match pick_nts_ke_servers(&connector, &servers, client_data.algorithm).await {
Ok(x) => x,
Err(e) => {
// for now, just send back to the client that its algorithms were invalid
// AeadAlgorithm::AeadAesSivCmac256 should always be supported by servers and clients
info!(?e, "could not find a valid KE server");

let records = [
NtsRecord::NextProtocol {
protocol_ids: vec![0],
},
NtsRecord::Error {
errorcode: e.to_error_code(),
},
NtsRecord::EndOfMessage,
];

// now we just forward the response
let mut buffer = Vec::with_capacity(1024);
for record in records {
record.write(&mut buffer)?;
}

client_stream.write_all(&buffer).await?;
client_stream.shutdown().await?;
let pick = pick_nts_ke_servers(
&connector,
&servers,
client_data.algorithm,
&client_data.denied_servers,
)
.await;

return Ok(());
let (server_name, port, domain) = match pick {
Ok(x) => x,
Err(e) => {
// for now, just send back to the client that its algorithms were invalid
// AeadAlgorithm::AeadAesSivCmac256 should always be supported by servers and clients
info!(?e, "could not find a valid KE server");

let records = [
NtsRecord::NextProtocol {
protocol_ids: vec![0],
},
NtsRecord::Error {
errorcode: e.to_error_code(),
},
NtsRecord::EndOfMessage,
];

// now we just forward the response
let mut buffer = Vec::with_capacity(1024);
for record in records {
record.write(&mut buffer)?;
}
};

client_stream.write_all(&buffer).await?;
client_stream.shutdown().await?;

return Ok(());
}
};

// this is inefficient of course, but spec-compliant: the TLS connection is closed when the server
// receives a EndOfMessage record, so we have to establish a new one. re-using the TCP
Expand Down

0 comments on commit 09c5543

Please sign in to comment.