Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 committed Nov 9, 2023
1 parent 070dd7d commit cab12a3
Show file tree
Hide file tree
Showing 9 changed files with 617 additions and 46 deletions.
139 changes: 139 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ rustls-native-certs = "0.6.0"
# crypto
aead = "0.5.0"
aes-siv = "0.7.0"
ed25519-dalek = { version = "2.0.0", features = ["rand_core"] }
# Note: md5 is needed to calculate ReferenceIDs for IPv6 addresses per RFC5905
md-5 = "0.10.0"
zeroize = "1.5"
Expand Down
1 change: 1 addition & 0 deletions ntp-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ thiserror.workspace = true
aead.workspace = true
aes-siv.workspace = true
zeroize.workspace = true
ed25519-dalek.workspace = true

[dev-dependencies]
rustls-pemfile.workspace = true
5 changes: 4 additions & 1 deletion ntp-proto/src/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
AesSivCmac256, AesSivCmac512, Cipher, CipherHolder, CipherProvider, CipherType,
DecryptError, EncryptResult, ExtensionField,
},
NtpTimestamp,
};

pub struct DecodedServerCookie {
Expand Down Expand Up @@ -210,7 +211,7 @@ impl KeySet {

let nonce = &cookie[6..22];
let ciphertext = cookie[22..].get(..cipher_text_length).ok_or(DecryptError)?;
let plaintext = key.decrypt(nonce, ciphertext, &[])?;
let plaintext = key.decrypt(nonce, ciphertext, &[], NtpTimestamp::default())?;

let [b0, b1, ref key_bytes @ ..] = plaintext[..] else {
return Err(DecryptError);
Expand Down Expand Up @@ -266,6 +267,7 @@ impl KeySet {
impl CipherProvider for KeySet {
fn get(&self, etype: CipherType, context: &[ExtensionField<'_>]) -> Option<CipherHolder<'_>> {
match etype {
CipherType::None => None,
CipherType::Nts => {
let mut decoded = None;

Expand All @@ -281,6 +283,7 @@ impl CipherProvider for KeySet {

decoded.map(CipherHolder::DecodedServerCookie)
}
CipherType::Ed25519 => None,
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions ntp-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ mod exports {
#[cfg(feature = "__internal-fuzz")]
pub use super::packet::ExtensionField;
pub use super::packet::{
Cipher, CipherProvider, EncryptResult, ExtensionHeaderVersion, NoCipher,
NtpAssociationMode, NtpLeapIndicator, NtpPacket, PacketParsingError,
Cipher, CipherProvider, Ed25519Private, Ed25519Public, EncryptResult,
ExtensionHeaderVersion, NoCipher, NtpAssociationMode, NtpLeapIndicator, NtpPacket,
PacketParsingError,
};
#[cfg(feature = "__internal-fuzz")]
pub use super::peer::fuzz_measurement_from_packet;
Expand Down
Loading

0 comments on commit cab12a3

Please sign in to comment.