| Crates.io | rkik-nts |
| lib.rs | rkik-nts |
| version | 0.4.0 |
| created_at | 2025-11-05 13:12:00.137234+00 |
| updated_at | 2026-01-23 11:01:17.613317+00 |
| description | High-level NTS (Network Time Security) Client library based on ntpd-rs |
| homepage | |
| repository | https://github.com/aguacero7/rkik-nts |
| max_upload_size | |
| id | 1917973 |
| size | 186,241 |
A high-level NTS (Network Time Security) Client library for Rust, based on ntpd-rs from the Pendulum Project.
This library provides a simple, safe, and ergonomic API for querying time from NTS-secured NTP servers. It handles the complexity of NTS key exchange and authenticated time synchronization, making it easy to integrate secure time synchronization into your applications.
Add to your Cargo.toml:
[dependencies]
rkik-nts = "0.4"
tokio = { version = "1", features = ["full"] }
Basic usage:
use rkik_nts::{NtsClient, NtsClientConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client configuration
let config = NtsClientConfig::new("time.cloudflare.com");
// Create and connect the client
let mut client = NtsClient::new(config);
client.connect().await?;
// Query the current time
let time = client.get_time().await?;
println!("Network time: {:?}", time.network_time);
println!("Offset (ms): {} ms", time.offset_signed());
println!("Authenticated: {}", time.authenticated);
Ok(())
}
cargo run --example simple_client --features tracing-subscriber
cargo run --example nts_end_to_end --features tracing-subscriber
Access TLS certificate information from the NTS-KE handshake:
use rkik_nts::{NtsClient, NtsClientConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = NtsClientConfig::new("time.cloudflare.com");
let mut client = NtsClient::new(config);
client.connect().await?;
// Access certificate information
if let Some(ke_result) = client.nts_ke_info() {
if let Some(cert) = &ke_result.certificate {
println!("Certificate Subject: {}", cert.subject);
println!("Certificate Issuer: {}", cert.issuer);
println!("Valid from: {} to {}", cert.valid_from, cert.valid_until);
println!("SHA-256 Fingerprint: {}", cert.fingerprint_sha256);
println!("Self-signed: {}", cert.is_self_signed);
}
}
Ok(())
}
Run the certificate example:
cargo run --example test_certificate --features tracing-subscriber
use rkik_nts::{NtsClient, NtsClientConfig};
use std::time::Duration;
let config = NtsClientConfig::new("time.cloudflare.com")
.with_port(4460)
.with_timeout(Duration::from_secs(5))
.with_max_retries(3);
let mut client = NtsClient::new(config);
client.connect().await?;
let time = client.get_time().await?;
See the examples/ directory for more detailed examples.
For debugging and network analysis, you can capture TLS session keys for Wireshark decryption:
# Set environment variable to enable keylog
export SSLKEYLOGFILE=/tmp/sslkeylog.txt
# Run your application or example
cargo run --example test_certificate --features tracing-subscriber
# Use the keylog file in Wireshark:
# Edit → Preferences → Protocols → TLS → (Pre)-Master-Secret log filename
This allows you to decrypt and analyze the NTS-KE TLS traffic in Wireshark for troubleshooting.
Here are some public NTS servers you can use for testing:
time.cloudflare.com - Cloudflarents.ntp.se - Netnod (Sweden)ntppool1.time.nl - NLnet Labs (Netherlands)time.txryan.com - Ryan Sleevints.ntp.org.au - Australian NTP PoolThis library is designed for seamless integration with rkik, but can also be used as a standalone NTS client library. The API is intentionally kept simple and focused on the core functionality of NTS time synchronization.
The library is structured into several modules:
client: High-level NTS client implementationconfig: Configuration types and builderserror: Error types and result aliasesnts_ke: NTS Key Exchange protocol implementationtypes: Common types (TimeSnapshot, NtsKeResult, etc.)Network Time Security (NTS) is a security extension for NTP that provides:
The protocol works in two phases:
This library handles both phases transparently.
# Build the library
cargo build
# Run tests
cargo test
# Run examples
cargo run --example simple_client --features tracing-subscriber
# Build documentation
cargo doc --open
See CONTRIBUTING.md for development guidelines.
This library is built on top of ntpd-rs, a memory-safe NTP implementation developed by the Pendulum Project. The ntpd-rs project is maintained by Tweede golf and was originally funded by ISRG's Prossimo project.
Contributions are welcome! Please see CONTRIBUTING.md for details.