From 3a4852ae8c733a6dfcfa3188dee5cae9f0a2931c Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 13 Nov 2023 12:00:23 +0100 Subject: [PATCH] correct supported protocols 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 --- ntp-proto/src/nts_record.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/ntp-proto/src/nts_record.rs b/ntp-proto/src/nts_record.rs index 4db7a7d1a..719cff0d8 100644 --- a/ntp-proto/src/nts_record.rs +++ b/ntp-proto/src/nts_record.rs @@ -759,6 +759,9 @@ struct KeyExchangeResultDecoder { #[cfg(feature = "nts-pool")] keep_alive: bool, + + #[cfg(feature = "nts-pool")] + supported_protocols: Vec<(AeadAlgorithm, u16)>, } impl KeyExchangeResultDecoder { @@ -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")] @@ -1044,7 +1059,7 @@ struct KeyExchangeServerDecoder { #[cfg(feature = "nts-pool")] keep_alive: Option, #[cfg(feature = "nts-pool")] - supported_protocols: Option>, + send_supported_protocols: bool, #[cfg(feature = "nts-pool")] fixed_key_request: Option<(Vec, Vec)>, #[cfg(feature = "nts-pool")] @@ -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) }