Skip to content

Commit

Permalink
correct supported protocols
Browse files Browse the repository at this point in the history
clients can receive this message (and then it will have a payload). servers can also receive this message, but then the body should be empty
  • Loading branch information
folkertdev committed Nov 16, 2023
1 parent 79ab66f commit 3a4852a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions ntp-proto/src/nts_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ struct KeyExchangeResultDecoder {

#[cfg(feature = "nts-pool")]
keep_alive: bool,

#[cfg(feature = "nts-pool")]
supported_protocols: Vec<(AeadAlgorithm, u16)>,
}

impl KeyExchangeResultDecoder {
Expand Down Expand Up @@ -861,9 +864,21 @@ impl KeyExchangeResultDecoder {
Continue(state)
}
#[cfg(feature = "nts-pool")]
SupportedProtocolList { .. } => {
// a client should never receive a SupportedProtocolList
tracing::warn!("Unexpected supported protocol list");
SupportedProtocolList {
supported_protocols,
} => {
use self::AeadAlgorithm;

let supported_protocols = supported_protocols
.into_iter()
.filter_map(|(aead_protocol_id, key_length)| {
let aead_algorithm = AeadAlgorithm::try_deserialize(aead_protocol_id)?;
Some((aead_algorithm, key_length))
})
.collect();

state.supported_protocols = supported_protocols;

Continue(state)
}
#[cfg(feature = "nts-pool")]
Expand Down Expand Up @@ -1044,7 +1059,7 @@ struct KeyExchangeServerDecoder {
#[cfg(feature = "nts-pool")]
keep_alive: Option<bool>,
#[cfg(feature = "nts-pool")]
supported_protocols: Option<Vec<(AeadAlgorithm, u16)>>,
send_supported_protocols: bool,
#[cfg(feature = "nts-pool")]
fixed_key_request: Option<(Vec<u8>, Vec<u8>)>,
#[cfg(feature = "nts-pool")]
Expand Down Expand Up @@ -1186,17 +1201,9 @@ impl KeyExchangeServerDecoder {
SupportedProtocolList {
supported_protocols,
} => {
use self::AeadAlgorithm;

let supported_protocols = supported_protocols
.into_iter()
.filter_map(|(aead_protocol_id, key_length)| {
let aead_algorithm = AeadAlgorithm::try_deserialize(aead_protocol_id)?;
Some((aead_algorithm, key_length))
})
.collect();
debug_assert_eq!(supported_protocols, &[]);

state.supported_protocols = Some(supported_protocols);
state.send_supported_protocols = true;

Continue(state)
}
Expand Down

0 comments on commit 3a4852a

Please sign in to comment.