secure_dns

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 16 Imported by: 0

README

secure_dns

secure_dns is a secure, decentralized DNS-over-QUIC (DoQ) implementation tailored for zero-trust mesh networks. It enforces strict mutual TLS (mTLS) authentication for all peer connections, frames DNS traffic over stream-oriented QUIC transport using a 2-byte length prefix (compliant with stream-based DNS standards), and integrates with a cryptographic data verification engine to protect against domain spoofing and malicious ingress.


Features

  • DNS-over-QUIC (DoQ): Replaces traditional untrusted UDP communication with robust, stream-oriented QUIC connections.
  • Strict Mutual TLS (mTLS): Enforces peer identity verification via x509 client certificates, ensuring only pre-authorized nodes can query or inject zone records.
  • Decentralized Swarm Mesh Resolution: Coordinates local zone file resolution with network-wide peer broadcasts using a custom peer routing layer.
  • Cryptographic Data Lineage Verification: Leverages a secure data validation engine to audit the authenticity and configuration validity of resource records.
  • Authoritative Persistence Layer: Plugs into atomic, fast, local memory-page persistence for quick lookups and secure transactions.

Architecture & Transport Framing

Unlike UDP-based DNS alternatives, secure_dns relies on reliable, ordered stream byte delivery via quic-go. To handle query boundaries over continuous streams accurately, all packet transactions prepend a 2-byte big-endian length prefix.

When a query is received, the node evaluates the peer's certificate, establishes the streaming context, parses the structural DNS labels sequentially, and checks local tables. If an entry is missing or expired, it falls back to a network broadcast to find the record within the trusted swarm mesh.


Prerequisites

Ensure your environment includes a modern version of quic-go which manages connection handlers via the concrete pointer (*quic.Conn) architecture.

go get github.com/quic-go/quic-go


General Application Server Integration

To integrate secure_dns into a modular application server architecture or framework, instantiate the coordinator during your platform's startup lifecycle once the database and network layers are operational.

Implementation Template
package main

import (
	"crypto/tls"
	"log"

	"github.com/0TrustCloud/secure_dns"
)

// Assume your environment has pre-existing components for storage and networking
type ApplicationServer struct {
	DB        *YourDatabaseType
	Router    *YourRouterType
	Engine    *YourCryptoEngineType
	PublicKey []byte
}

func (s *ApplicationServer) StartDNSWorker(bindAddr string, tlsConf *tls.Config) {
	// 1. Initialize the SecureDNS instance with your platform's core dependencies
	sdns := secure_dns.NewSecureDNS(s.Router, s.Engine, s.PublicKey, s.DB)

	// 2. Ensure the TLS configuration enforces strict peer verification
	tlsConf.ClientAuth = tls.RequireAndVerifyClientCert
	tlsConf.NextProtos = []string{"doq"}

	// 3. Spin up the listener loop inside a background execution routine
	go func() {
		log.Printf("[DNS Core] Launching mTLS DNS-over-QUIC loop on %s...", bindAddr)
		if err := sdns.ServeWireProtocol(bindAddr, tlsConf); err != nil {
			log.Printf("[DNS Core] Listener closed or exited: %v", err)
		}
	}()
}

Managing Domain Zone Modifications

You can manage authoritative domain bindings programmatically by executing zone registration commands through your application handlers or administrative API endpoints:

// Bind an authoritative A record to the underlying database page
err := sdns.RegisterDomain("node-alpha.mesh", "A", "10.0.0.5", 3600)
if err != nil {
    log.Printf("Failed to bind domain authority: %v", err)
}


Running Tests

The test suite validates connection streams, mTLS handshake constraints, and proper packet framing by generating ephemeral in-memory Certificate Authorities and cross-signing connection endpoints at runtime.

To execute the unit tests, use:

go test -v ./...

Documentation

Index

Constants

View Source
const (
	DNSPageID ultimate_db.PageID = 53
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthoritativeServer added in v1.0.3

type AuthoritativeServer struct {

	// Recurse, if set, handles names not in the local zone (public internet).
	// Private mesh names that miss stay NXDOMAIN and do not recurse.
	Recurse func(query []byte, domain string) []byte
	// IsPrivate reports whether domain is a mesh private-zone name.
	IsPrivate func(domain string) bool
	// contains filtered or unexported fields
}

AuthoritativeServer serves standard DNS wire queries from an in-memory zone table. Optional Recurse allows full-system DNS when clients point at this IP (e.g. Windows).

func NewAuthoritativeServer added in v1.0.3

func NewAuthoritativeServer(host string) *AuthoritativeServer

func (*AuthoritativeServer) AnswerPacket added in v1.0.3

func (a *AuthoritativeServer) AnswerPacket(buffer []byte) []byte

AnswerPacket builds a wire response from the in-memory zone (same path as UDP :53). Used by DoH so browser Secure DNS matches dig @ns.

func (*AuthoritativeServer) Host added in v1.0.3

func (a *AuthoritativeServer) Host() string

Host returns the configured authoritative host label (e.g. ns.0trust.cloud).

func (*AuthoritativeServer) LoadSnapshot added in v1.0.3

func (a *AuthoritativeServer) LoadSnapshot(snap ZoneSnapshot)

LoadSnapshot replaces the in-memory zone table.

func (*AuthoritativeServer) RecordCount added in v1.0.3

func (a *AuthoritativeServer) RecordCount() int

RecordCount returns the number of active records.

func (*AuthoritativeServer) ServeTCP added in v1.0.3

func (a *AuthoritativeServer) ServeTCP(bindAddr string) error

ServeTCP listens for DNS wire queries on the given TCP address (e.g. :53).

func (*AuthoritativeServer) ServeUDP added in v1.0.3

func (a *AuthoritativeServer) ServeUDP(bindAddr string) error

ServeUDP listens for DNS wire queries on the given UDP address (e.g. :53).

func (*AuthoritativeServer) Shutdown added in v1.0.3

func (a *AuthoritativeServer) Shutdown()

func (*AuthoritativeServer) UpsertRecord added in v1.0.3

func (a *AuthoritativeServer) UpsertRecord(domain, recType, value string, ttl int)

UpsertRecord inserts or replaces a single RR without wiping the zone. Used by edge failover cutover so ns.0trust.services can answer while cloud is down.

type DNSQueryPayload

type DNSQueryPayload struct {
	QueryID string `json:"query_id"`
	Domain  string `json:"domain"`
	Type    string `json:"type"`
}

type DNSRecord

type DNSRecord struct {
	Domain string    `json:"domain"`
	Type   string    `json:"type"` // "A", "AAAA", "PTR", "TXT"
	Value  string    `json:"value"`
	TTL    int       `json:"ttl"`
	Expiry time.Time `json:"expiry"`
}

type DNSResponsePayload

type DNSResponsePayload struct {
	QueryID  string      `json:"query_id"`
	Records  []DNSRecord `json:"records"`
	SdfProof string      `json:"sdf_proof"`
}

type SecureDNS

type SecureDNS struct {
	// contains filtered or unexported fields
}

func NewSecureDNS

func NewSecureDNS(pr *secure_network.PeerRoute, sdf *secure_data_format.SecureDataEngine, localPub []byte, database *ultimate_db.DB) *SecureDNS

func (*SecureDNS) AnswerWireQuery added in v1.0.3

func (s *SecureDNS) AnswerWireQuery(packet []byte) ([]byte, error)

AnswerWireQuery resolves a standard DNS wire query from local storage (then mesh).

func (*SecureDNS) BuildSnapshot added in v1.0.3

func (s *SecureDNS) BuildSnapshot(host string) (ZoneSnapshot, error)

BuildSnapshot exports all non-expired DNS records from the local authoritative store.

func (*SecureDNS) DeleteDomain added in v1.0.3

func (s *SecureDNS) DeleteDomain(domain, recordType, value string) error

func (*SecureDNS) DeleteZoneType added in v1.0.3

func (s *SecureDNS) DeleteZoneType(domain, recordType string) error

DeleteZoneType removes every record of a type under domain (used to refresh glue).

func (*SecureDNS) ListRecords added in v1.0.3

func (s *SecureDNS) ListRecords(domain string) ([]DNSRecord, error)

func (*SecureDNS) RegisterDomain

func (s *SecureDNS) RegisterDomain(domain, recordType, value string, ttl int) error

func (*SecureDNS) RegisterGlueRecord added in v1.0.3

func (s *SecureDNS) RegisterGlueRecord(domain, recordType, value string, ttl int) error

RegisterGlueRecord stores a platform bootstrap/glue RR that does not expire locally.

func (*SecureDNS) ReplaceZoneType added in v1.0.3

func (s *SecureDNS) ReplaceZoneType(domain, recordType, value string, ttl int) error

ReplaceZoneType removes all records of a type under domain and stores a single value. Uses non-expiring glue storage so product apex A records survive restarts cleanly.

func (*SecureDNS) ResolveLocal

func (s *SecureDNS) ResolveLocal(domain, recordType string) ([]DNSRecord, error)

func (*SecureDNS) ResolveMesh

func (s *SecureDNS) ResolveMesh(ctx context.Context, domain, recordType string, timeout time.Duration) ([]DNSRecord, error)

func (*SecureDNS) ResolveWire added in v1.0.3

func (s *SecureDNS) ResolveWire(domain, recordType string) ([]DNSRecord, error)

ResolveWire answers authoritative wire queries from local storage without mesh/SDF.

func (*SecureDNS) ServeWireProtocol

func (s *SecureDNS) ServeWireProtocol(bindAddr string) error

func (*SecureDNS) Shutdown

func (s *SecureDNS) Shutdown()

func (*SecureDNS) SnapshotJSON added in v1.0.3

func (s *SecureDNS) SnapshotJSON(host string) ([]byte, error)

SnapshotJSON returns a JSON-encoded zone snapshot.

type ZoneSnapshot added in v1.0.3

type ZoneSnapshot struct {
	Version   int64       `json:"version"`
	Host      string      `json:"host"`
	Records   []DNSRecord `json:"records"`
	UpdatedAt time.Time   `json:"updated_at"`
	// PrivateSuffixes lists active private TLD suffixes (e.g. ".mesh", ".factory").
	// Open namespace: any non-ICANN TLD registered on the control plane appears here
	// so edges and split resolvers stay in sync without a fixed allowlist.
	PrivateSuffixes []string `json:"private_suffixes,omitempty"`
}

ZoneSnapshot is the authoritative zone bundle replicated cloud → edge NS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL