rkik-nts
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.
Features
- Secure: Full NTS (Network Time Security) support for authenticated time queries
- Certificate Diagnostics: TLS certificate information capture for security auditing and diagnostics
- TLS Debugging: SSLKEYLOGFILE support for Wireshark traffic analysis
- Simple API: Easy-to-use client interface with sensible defaults
- Async: Built on Tokio for efficient async I/O
- Configurable: Flexible configuration options for advanced use cases
- Battle-tested: Based on ntpd-rs from Project Pendulum
- Integration-ready: Designed for seamless integration with rkik
Quick Start
Add to your Cargo.toml:
[]
= "0.4"
= { = "1", = ["full"] }
Basic usage:
use ;
async
Examples
Simple Client
End-to-End NTS Validation
Certificate Information (New in v0.3.0)
Access TLS certificate information from the NTS-KE handshake:
use ;
async
Run the certificate example:
Custom Configuration
use ;
use Duration;
let config = new
.with_port
.with_timeout
.with_max_retries;
let mut client = new;
client.connect.await?;
let time = client.get_time.await?;
See the examples/ directory for more detailed examples.
Advanced Features
TLS Traffic Analysis with SSLKEYLOGFILE
For debugging and network analysis, you can capture TLS session keys for Wireshark decryption:
# Set environment variable to enable keylog
# Run your application or example
# 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.
Public NTS Servers
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 Pool
Integration with rkik
This 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.
Architecture
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.)
How NTS Works
Network Time Security (NTS) is a security extension for NTP that provides:
- Authentication: Cryptographic verification that time data comes from the expected server
- Encryption: Protection of time synchronization traffic
- Resistance to replay attacks: Each query uses unique authentication cookies
The protocol works in two phases:
- NTS-KE (Key Exchange): TLS connection to exchange keys and cookies
- NTP with NTS: UDP-based time queries using the negotiated keys
This library handles both phases transparently.
Requirements
- Rust 1.70 or later
- Tokio runtime
Development
# Build the library
# Run tests
# Run examples
# Build documentation
See CONTRIBUTING.md for development guidelines.
Based on ntpd-rs
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.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Acknowledgments
- The Pendulum Project for ntpd-rs
- Tweede golf for maintaining ntpd-rs