ntpsec-rs 0.3.2

Umbrella crate for ntpsec-rs — forensic Rust reconstruction of NTPsec
Documentation

ntpsec-rs

crates.io License Repository

ntpsec-rs is a forensic Rust reconstruction of NTPsec — a secure, modern, full-featured implementation of the Network Time Protocol. The entire NTPsec ecosystem — daemon, query tools, monitoring utilities, and supporting libraries — is being rebuilt in safe, idiomatic Rust, organized as a Cargo workspace of focused sub-crates.


Table of Contents


Project Overview

NTPsec is a hardened, security-focused fork of the classic NTP reference implementation. ntpsec-rs reimplements the NTPsec codebase in Rust, leveraging Rust's safety guarantees, modern tooling (Cargo, crates.io), and ecosystem libraries to produce a reliable, memory-safe NTP implementation.

The workspace follows a modular design:

  • Core libraries — protocol encoding/decoding, state machines, authentication, NTS
  • I/O layer — system clock interaction, network sockets, drift-file persistence
  • Daemon — the ntpd replacement (ntpd-rs)
  • Tooling — query clients (ntpq-rs, ntpdig-rs), diagnostics, monitoring, visualization
  • Utilities — key generation, leap-second fetching, configuration manipulation

Architecture

                        ┌──────────────────────────────────────────┐
                        │              ntpsec-rs                   │
                        │         (umbrella facade)                │
                        └───────────┬──────────────────────────────┘
                                    │
             ┌──────────────────────┼──────────────────────┐
             ▼                      ▼                      ▼
   ┌─────────────────┐   ┌──────────────────┐   ┌────────────────────┐
   │  ntpsec-rs-core  │   │   ntpsec-rs-io   │   │   Binaries / Tools │
   │  (no_std-ready)  │   │  (std required)  │   │   (14 crates)      │
   │                  │   │                  │   │                    │
   │ • Wire codec     │   │ • System clock   │   │ • ntpd-rs          │
   │ • Mode 6 control │   │ • UDP sockets    │   │ • ntpq-rs          │
   │ • Auth (MD5/SHA) │   │ • State store    │   │ • ntpdig-rs        │
   │ • NTS            │   │ • Refclock I/O   │   │ • ...              │
   │ • Refclocks      │   │                  │   │                    │
   │ • Engine         │   │                  │   │                    │
   └─────────────────┘   └──────────────────┘   └────────────────────┘
  • ntpsec-rs-core — Pure protocol logic. Deterministic engine, wire format codec (NTP v4), Mode 6 control protocol, symmetric-key and NTS (Network Time Security) authentication, reference clock drivers. Designed to be no_std compatible where possible.
  • ntpsec-rs-io — Real-world I/O. System clock access (clock_gettime/settimeofday), UDP sockets, drift-file and state persistence.
  • Tooling crates — Each provides a standalone binary, building on top of core and io.

Crates

The workspace publishes 18 crates to crates.io. All are prefixed ntpsec-rs-*.

Core Libraries

Crate Description crates.io
ntpsec-rs-core Deterministic engine, wire codec, Mode 6 control, authentication, refclocks, NTS crates.io
ntpsec-rs-io Real I/O layer (system clock, network sockets, state store) crates.io

Daemon and Facade

Crate Description crates.io
ntpsec-rs Umbrella facade crate re-exporting all public APIs crates.io
ntpsec-rs-d ntpd-rs — NTP daemon binary crates.io

Query Tools

Crate Description crates.io
ntpsec-rs-query ntpq-rs — Mode 6 control query client crates.io
ntpsec-rs-dig ntpdig-rs — NTP mode 3 query tool crates.io
ntpsec-rs-time Single-shot time query tool crates.io
ntpsec-rs-sweep Sweep through servers collecting stats crates.io

Monitoring and Diagnostics

Crate Description crates.io
ntpsec-rs-mon Real-time NTP monitoring tool crates.io
ntpsec-rs-trace NTP path trace tool crates.io
ntpsec-rs-snmpd SNMP monitoring daemon crates.io
ntpsec-rs-viz NTP data visualization crates.io

Utilities

Crate Description crates.io
ntpsec-rs-keygen NTP symmetric key generation crates.io
ntpsec-rs-leapfetch Leap second file fetcher crates.io
ntpsec-rs-wait Wait until NTP server reachable crates.io
ntpsec-rs-frob NTP configuration manipulator crates.io

Data Logging

Crate Description crates.io
ntpsec-rs-loggps GPS reference clock logging crates.io
ntpsec-rs-logtemp System temperature logging crates.io

Building

Prerequisites

  • Rust 1.75+ (stable toolchain)
  • Cargo (included with Rust)
  • Linux (primary target; other Unix-likes may work)

Build the entire workspace

git clone https://github.com/infinityabundance/ntpsec-rs.git
cd ntpsec-rs
cargo build --workspace

Build a specific crate

cargo build -p ntpsec-rs-core
cargo build -p ntpsec-rs-d

Release build

cargo build --workspace --release

Release binaries will be placed in target/release/. Notable binaries include:

Binary Crate Purpose
ntpd-rs ntpsec-rs-d NTP daemon
ntpq-rs ntpsec-rs-query Query client
ntpdig-rs ntpsec-rs-dig Query tool
ntpkeygen ntpsec-rs-keygen Key generation
ntpleapfetch ntpsec-rs-leapfetch Leap second fetcher
ntpmon ntpsec-rs-mon Monitor tool
ntptrace ntpsec-rs-trace Trace tool
ntpwait ntpsec-rs-wait Wait tool
ntpviz ntpsec-rs-viz Visualization
ntpfrob ntpsec-rs-frob Config manipulator
ntpsnmpd ntpsec-rs-snmpd SNMP daemon
ntptime ntpsec-rs-time Time query
ntpsweep ntpsec-rs-sweep Sweep tool
ntploggps ntpsec-rs-loggps GPS logging
ntplogtemp ntpsec-rs-logtemp Temperature logging

Cross-compilation

The ntpsec-rs-core crate is designed to be no_std compatible where practical, enabling its use in embedded environments.


Running

Start the daemon

sudo ./target/release/ntpd-rs -c /etc/ntp.conf

Query the daemon

./target/release/ntpq-rs -c peers
./target/release/ntpq-rs -c associations

Check time offset

./target/release/ntpdig-rs pool.ntp.org

Project Status

This is an active forensic reconstruction project. The crate structure and public API may change as development progresses. Key milestones:

  • ☑ Core protocol codec (NTP v4 wire format, Mode 6 control)
  • ☑ Authentication (MD5, SHA-1, SHA-256/384/512)
  • ☑ NTS (Network Time Security) basic support
  • ☑ Reference clock framework
  • ☑ Deterministic engine (clock filter, selection, combining, discipline)
  • ☑ I/O layer (system clock, UDP sockets, state store)
  • ☑ Daemon skeleton
  • ☐ Full daemon integration and lifecycle management
  • ☐ Comprehensive test suite
  • ☐ Fuzz testing and security audit
  • ☐ Production readiness

License

This project is distributed under the same license as NTPsec. See the LICENSE file for details.


Links