roughtime/lib.rs
1//! A [no_std]-capable client for the [Roughtime] secure time synchronization protocol.
2//!
3//! Roughtime lets a client obtain the current time from a set of untrusted servers while
4//! being able to cryptographically prove, after the fact, that any server which lied about
5//! the time can be caught (via Ed25519 signatures over a Merkle tree of recent requests).
6//! This crate implements the **client** side only: building requests, parsing and verifying
7//! responses, and (optionally) querying real servers over the network.
8//!
9//! [no_std]: https://docs.rust-embedded.org/book/intro/no-std.html
10//! [Roughtime]: https://blog.cloudflare.com/roughtime/
11//!
12//! # Feature flags
13//!
14//! Exactly one crypto backend feature must be enabled:
15//!
16//! - `rustcrypto` — pure-Rust [`ed25519-dalek`] + [`sha2`], `no_std`-capable.
17//! - `aws-lc-rs` — [`aws-lc-rs`], the default.
18//! - `aws-lc-rs-fips` — `aws-lc-rs` built in FIPS mode.
19//!
20//! Layered on top:
21//!
22//! - `std` (default) — enables the networking clients and the Linux `os-clock` backend.
23//! - `tokio-client` (default) — an async, concurrent multi-server query client.
24//! - `blocking-client` — a synchronous [`std::net::UdpSocket`]-based client.
25//! - `os-clock` — an opt-in Linux [`SystemClock`](clock::SystemClock) implementation that can
26//! set the OS wall clock forward to the verified time floor.
27//! - `dnscrypt` (default) — resolves well-known Roughtime server hostnames via [`dnscrypt`],
28//! an authenticated, encrypted DNS transport, instead of the OS's plaintext, unauthenticated
29//! resolver. This closes the one remaining plaintext, unauthenticated hop in an otherwise
30//! end-to-end-verified time-sync flow, and means callers no longer have to resolve/pin server
31//! IPs by hand. See [`resolve::resolve_servers`]/[`resolve::resolve_servers_async`] and
32//! [`client::TokioClient::query_well_known`]/[`client::BlockingClient::query_well_known`].
33//! - `build-time-floor` — opt-in, **not** in `default`. Ratchets the anti-rollback floor
34//! forward to the build day using the build machine's wall clock. Leave this disabled for
35//! reproducible builds (e.g. attested boot images); see [`floor`] for details.
36//!
37//! [`dnscrypt`]: https://docs.rs/dnscrypt
38//!
39//! A `no_std` consumer (e.g. a kernel or bootloader) should build with
40//! `--no-default-features --features rustcrypto` to get the wire-format, request-building,
41//! and response-verification primitives with no networking or OS dependency — supplying its
42//! own I/O and randomness.
43//!
44//! # Requirement: a global allocator
45//!
46//! This crate always uses `alloc` (for `Vec`-backed message parsing), even in `no_std` builds.
47//! `no_std` consumers must provide a global allocator.
48//!
49//! # Security posture
50//!
51//! This is a client-only crate: it never holds Ed25519 *private* key material, only verifies
52//! server-supplied public keys and signatures. The one client-generated secret-like value is
53//! the 64-byte nonce, which is zeroized on drop (see [`request::Nonce`]). Raw response bytes
54//! and extracted public keys are intentionally **not** zeroized — they are bulk public-protocol
55//! data, and scrubbing them would cost real performance for no confidentiality benefit.
56
57#![no_std]
58#![doc(html_root_url = "https://docs.rs/roughtime")]
59
60extern crate alloc;
61
62#[cfg(feature = "std")]
63extern crate std;
64
65pub mod clock;
66pub mod date;
67pub mod error;
68pub mod floor;
69pub mod request;
70pub mod servers;
71pub mod tags;
72pub mod verify;
73pub mod wire;
74
75mod crypto;
76
77#[cfg(test)]
78mod test_fixtures;
79
80#[cfg(feature = "std")]
81pub mod client;
82
83#[cfg(feature = "os-clock")]
84pub mod os_clock;
85
86#[cfg(feature = "dnscrypt")]
87pub mod resolve;
88
89pub use error::Error;
90pub use request::{Nonce, build_request};
91pub use servers::{ROUGHTIME_SERVERS, RoughtimeServer};
92pub use verify::{VerifiedTime, verify_response};
93
94#[cfg(feature = "dnscrypt")]
95pub use resolve::resolve_servers;
96#[cfg(all(feature = "dnscrypt", feature = "tokio-client"))]
97pub use resolve::resolve_servers_async;