cutoververify

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cutoververify checks a domain that is being moved onto this server and answers with one verdict per aspect (DNS, proxy, redirect, certificate, HSTS, response, www/apex pair) plus the next step for each. It is read only: it looks names up and makes plain GET requests, nothing else.

Index

Constants

View Source
const (
	ClassDNSFailed      = "dns_failed"
	ClassConnectRefused = "connect_refused"
	ClassTimeout        = "timeout"
	ClassTLSFailed      = "tls_failed"
	ClassBlocked        = "blocked_address"
	ClassConnectFailed  = "connect_failed"
	ClassRequestFailed  = "request_failed"
)

Error classes shown in reports instead of raw Go error text, which can carry resolved addresses and internal detail.

View Source
const (
	LineDNS         = "dns"
	LineProxy       = "proxy"
	LineRedirect    = "redirect"
	LineCertificate = "certificate"
	LineHSTS        = "hsts"
	LineResponse    = "response"
	LinePair        = "pair"
)

Line ids, in report order.

Variables

View Source
var ErrNonPublicAddress = errors.New("address is not public")

ErrNonPublicAddress is returned when a probe would connect to an address that is not on the public internet.

Functions

func Classify

func Classify(err error) string

Classify maps err to one stable class name.

func IsPublicAddr

func IsPublicAddr(ip netip.Addr) bool

IsPublicAddr reports whether ip may be probed: not loopback, private (RFC1918 and ULA), link-local (which covers the 169.254.169.254 metadata address), unspecified, multicast or reserved. Documentation ranges count as public.

func IsPublicIP

func IsPublicIP(s string) bool

IsPublicIP is IsPublicAddr for a textual address; unparsable text is not public.

Types

type CertInfo

type CertInfo struct {
	Issuer   string
	NotAfter time.Time
	Trusted  bool
}

CertInfo is what the served certificate showed.

type Deps

type Deps struct {
	Resolver Resolver
	Prober   Prober
	// IsProxyIP reports whether an address belongs to a known proxy network.
	IsProxyIP func(ip string) bool
	Now       func() time.Time
}

Deps are the seams tests replace.

type HTTPResult

type HTTPResult struct {
	Status   int
	Location string
	// Header holds the response headers with canonical keys.
	Header map[string]string
	TTFB   time.Duration
}

HTTPResult is one plain GET, redirects not followed.

type Line

type Line struct {
	ID      string  `json:"id"`
	Verdict Verdict `json:"verdict"`
	Title   string  `json:"title"`
	Detail  string  `json:"detail"`
	Next    string  `json:"next"`
}

Line is one verified aspect.

type NetProber

type NetProber struct {
	// Timeout bounds each request; it must be set by the caller.
	Timeout time.Duration
	// HTTPSPort is the port the TLS probes use, 443 when zero.
	HTTPSPort int
	// contains filtered or unexported fields
}

NetProber probes over the public name with the standard library. Every connection goes to one of the addresses the caller passes in, so the address that was checked is the address that is dialed.

func (NetProber) Cert

func (p NetProber) Cert(ctx context.Context, host string, addrs []string) (CertInfo, error)

Cert reads the leaf certificate served by addrs and checks it against the system roots.

func (NetProber) HTTP

func (p NetProber) HTTP(ctx context.Context, rawURL string, addrs []string) (HTTPResult, error)

HTTP makes one GET to addrs and does not follow redirects.

type Options

type Options struct {
	CertWarnDays int
	CertFailDays int
	// SlowTTFB is the time to first byte above which the response line warns.
	SlowTTFB time.Duration
	// HSTSMinAge is the smallest max-age (seconds) that counts as enabled.
	HSTSMinAge int
}

Options are the thresholds, read from env by the caller.

type Prober

type Prober interface {
	HTTP(ctx context.Context, rawURL string, addrs []string) (HTTPResult, error)
	Cert(ctx context.Context, host string, addrs []string) (CertInfo, error)
}

Prober makes the requests. Implementations must connect only to addrs, the set DNS answered once, while keeping the name for SNI and the Host header.

type Report

type Report struct {
	Domain    string    `json:"domain"`
	Verdict   Verdict   `json:"verdict"`
	Summary   string    `json:"summary"`
	ServerIPs []string  `json:"server_ips"`
	Resolved  []string  `json:"resolved,omitempty"`
	CNAME     string    `json:"cname,omitempty"`
	Proxy     string    `json:"proxy,omitempty"`
	Lines     []Line    `json:"lines"`
	CheckedAt time.Time `json:"checked_at"`
}

Report is the whole answer for one domain.

func Verify

func Verify(ctx context.Context, d Deps, domain string, serverIPs []string, o Options) Report

Verify runs every line for domain against serverIPs (this host's public addresses).

type Resolver

type Resolver interface {
	LookupHost(ctx context.Context, name string) ([]string, error)
	LookupCNAME(ctx context.Context, name string) (string, error)
}

Resolver is the DNS surface the verifier needs.

type Verdict

type Verdict string

Verdict is the outcome of one line or of the whole report.

const (
	Pass Verdict = "PASS"
	Warn Verdict = "WARN"
	Fail Verdict = "FAIL"
)

Verdict values, worst last.

Jump to

Keyboard shortcuts

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