Expand description
dnscrypt — an asynchronous (Tokio-backed) DNSCrypt v2 client library.
§Overview
This library implements the DNSCrypt v2 protocol for encrypted, authenticated
DNS resolution. X25519, Ed25519, constant-time comparison, and randomness are
backed by aws-lc-rs; the certificate’s ES version selects between
XChaCha20-Poly1305 and XSalsa20-Poly1305 (neither supported by
aws-lc-rs), provided by the pure-Rust chacha20/salsa20/poly1305
crates.
It ships two primary abstractions:
- Manual API — call
resolveor work step-by-step withestablish_dnscrypt_session+resolve_domain_via_dnscrypt_session. - Reqwest drop-in — plug
DnscryptResolverinto anyreqwest::Clientvia.dns_resolver(...)to transparently route all hostname lookups throughDNSCrypt.
You can also supply your own custom static list of DNSCrypt resolvers, bypassing
the built-in defaults.
§Cryptography
| Primitive | Purpose |
|---|---|
| X25519 DH | Per-session key agreement with the resolver |
HChaCha20 / HSalsa20 | Key derivation from the raw DH shared secret |
| XChaCha20-Poly1305 / XSalsa20-Poly1305 | Authenticated encryption of DNS queries/responses |
| Ed25519 | Resolver certificate signature verification |
All resolvers are hardcoded with their Ed25519 public keys pinned at compile time, preventing MITM via CA compromise.
§Quick Start
use dnscrypt::{resolve, Error, HARDCODED_RESOLVERS};
let ips = resolve(HARDCODED_RESOLVERS, "github.com").await?;
println!("github.com => {:?}", ips);§Reqwest integration
use dnscrypt::DnscryptResolver;
use std::sync::Arc;
// Build a reqwest client that resolves every hostname through DNSCrypt.
let client = reqwest::Client::builder()
.dns_resolver(Arc::new(DnscryptResolver::new()))
.build()
.unwrap();Re-exports§
pub use error::Error;pub use reqwest_resolver::DnscryptResolver;pub use resolver::DnscryptClientState;pub use resolver::HARDCODED_RESOLVERS;pub use resolver::HardcodedResolver;pub use resolver::establish_dnscrypt_session;pub use resolver::resolve;pub use resolver::resolve_domain_via_dnscrypt_session;
Modules§
- cert
DNSCryptv2 certificate parsing and Ed25519 signature verification.- crypto
- Raw
XSalsa20-Poly1305/XChaCha20-Poly1305AEAD andHSalsa20/HChaCha20key derivation. - error
- Unified error type for
dnscrypto. - net
- Asynchronous UDP/TCP transport for raw DNS packets.
- packet
- DNS packet building, parsing, and padding utilities.
- reqwest_
resolver reqwestdrop-in DNS resolver backed byDNSCrypt.- resolver
- Core
DNSCryptv2 session management and resolution logic.