abiz

package module
v0.1.0 Latest Latest
Warning

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

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

README

abiz-go

Go library and command-line tool for checking an ABIZ (Agentic Business Record) published by a domain. It implements the consumer side of ABIZ 1.1.

A domain publishes a _abiz DNS TXT record (v=abiz1;k=…;h=…;p=…) that points to a signed JSON business record served over HTTPS. This library finds that record, fetches it once and checks it. It gives the same status and error code as the hosted resolver at resolve.abizrecord.org.

  • Module: github.com/abiz-org/abiz-go, package abiz
  • Version: v0.1.0 (Go module tag)
  • Go: 1.24 or later
  • Licence: Apache-2.0 (the bundled schema/iso3166.json is LGPL-2.1; see below)
  • Homepage: https://abizrecord.org

Install

go get github.com/abiz-org/abiz-go@v0.1.0

To install the command-line tool:

go install github.com/abiz-org/abiz-go/cmd/abiz@v0.1.0

Example

res := abiz.Resolve(context.Background(), "example.com")
if res.Status != abiz.StatusResolved {
	fmt.Printf("%s: %s (%s)\n", res.Status, res.Code, res.Message)
	return
}
fmt.Println(res.Record["business_name"], res.Record["business_key"])
fmt.Println("found by", res.Discovery.Method, "at", res.Discovery.RecordURL)

From the shell:

abiz check example.com          # a short summary; exit status 0 only when the record resolved
abiz check example.com -json    # the full result as JSON
abiz check -website https://www.example.com/contact

What is checked

  1. Input. The domain is lower-cased, converted to A-labels (IDN) and stripped of one trailing dot. A URL, port, credentials or IP address is refused. A special-use or private-network name (.local, .internal, .example, .test and others) is refused. www. is never removed; when nothing is found at a www. name, a try_apex warning names the apex, which is not checked.
  2. DNS. One TXT query for _abiz.<domain>. NXDOMAIN and NODATA mean no record. A timeout or network failure is dns_timeout; SERVFAIL, REFUSED or a malformed answer is dns_failure. A failure is never treated as absence.
  3. The assertion. Exactly one TXT value starting v=abiz1 (two or more is multiple_txt). Its tags are parsed under SPEC §3.1–§3.3: h (the record host, with an optional path), k (an optional business key), and p (required: an Ed25519 public key in standard base64).
  4. The well-known file. Only when DNS answered with no v=abiz1 value, https://<domain>/.well-known/abiz.json is read in its place.
  5. The record. One GET of https://<h>?format=json. It is read only if it is JSON (or text/plain, with a warning), no larger than 64 KiB, nested no deeper than 16 levels, with at most 5,000 members and no repeated member names.
  6. Conformance. The bundled ABIZ 1.1 JSON Schema (Draft 2020-12, with formats asserted), then the rules a schema cannot express: country, region and jurisdiction codes, https URLs on public names, opening hours that do not overlap, unique ids, ratings within their scale, and so on.
  7. The link to DNS. identity_host must equal h; domains must include the queried domain; business_key must agree with k, country and registration_number; public_key must equal p.
  8. The signature. Ed25519 over the RFC 8785 (JCS) form of the record without its top-level signature.

The HTTPS fetch is guarded (SPEC §9). The library resolves the host itself and refuses to connect unless every address is public unicast. It then connects to the address it checked, so a second DNS answer cannot redirect it. The certificate is verified against the host name. The fetch never follows a redirect and ignores proxy environment variables. It gives up after 5 seconds and reads at most 64 KiB.

What is not checked

  • A resolved record is the publisher's own claim. It is signed with the key that the domain's DNS vouches for. That shows the record came from whoever controls the domain's DNS, and that it was not changed after signing. It does not show that the business facts in it are true.
  • No company register is consulted. The business key and registration number are checked only for their form and for agreement with each other.
  • mcp_server_url and every other URL in a record are never contacted. URLs are checked for their form only. The library makes at most one DNS TXT query and fetches at most two documents per resolution: the well-known file and the record.
  • DNSSEC is not validated.

Use "checked" when you describe a resolved record, not "verified".

API

Function What it does
Resolve(ctx, domain), (*Resolver).Resolve, ResolveWebsite, ResolveInput Resolves a domain or a website's host and returns a *Result
ParseAssertion(value) Parses one _abiz TXT value into an *Assertion (H, K, P, Unknown) or an *AssertionError with its code
CheckRecord(recordText, domain, assertion) Checks a record offline; returns "" or the first failing code, the problems and the parsed record
VerifySignature(record, p) "", public_key_mismatch or signature_invalid
Canonicalize(value), CanonicalizeJSON(text) RFC 8785 text
SignRecord(record, privateKey) Producer helper: returns the record with public_key and signature set
IsAssertion, IsPublicKey, IdentityParts, NormaliseInput, IsPublicAddress, ParseBusinessKey, ValidateSchema The individual rules

A Result has the following fields:

  • Status: resolved, invalid_input, not_found, conflict, invalid_record or unavailable.
  • Code: empty when resolved.
  • Message and Retryable.
  • Details: at most 25 path and message pairs.
  • Record: set only when resolved. Objects are map[string]any and numbers json.Number. RecordJSON holds the record's bytes exactly as served.
  • Discovery: the method (dns_txt or well_known), the owner name, the DNS value, the record URL and the state of the well-known file.
  • Warnings: content_type, or try_apex with its domain.

DNS and HTTPS sit behind two small interfaces, so you can supply DNS-over-HTTPS, a cache, a proxy or a test stub:

type TXTResolver interface { LookupTXT(ctx context.Context, name string) TXTResult }
type Fetcher interface     { Fetch(ctx context.Context, url string) FetchResult }

r := abiz.NewResolver(abiz.WithTXTResolver(myDNS), abiz.WithFetcher(myFetcher))

The default DNSResolver uses github.com/miekg/dns and the servers in /etc/resolv.conf. To use other servers, call NewDNSResolverWithServers("1.1.1.1"). The standard library's net.Resolver is not used for the TXT lookup because it cannot reliably tell NXDOMAIN, NODATA, SERVFAIL and a timeout apart, and ABIZ must not mistake a failure for absence. The default GuardedFetcher uses net/http, and net.DefaultResolver for the record host's addresses.

Conformance

The library passes every case in the shared ABIZ test vectors (format 1, ABIZ 1.1), run by go test ./... from testdata/test-vectors/:

File Cases
assertions.json 56
public-keys.json 13
hosts.json 52
addresses.json 36
jcs.json 13
signing.json 2 keys and 4 cases
records.json 65
resolution.json 60

The bundled files are byte-for-byte copies from abiz-org/abiz-agentic-business-record. A test checks each one against its pinned SHA-256:

  • schema/abiz-business-record-v1.1.schema.json: 3658f17f00c238b8c948fdfb447b509c5d055dd778ebd335495da05c3150ff24
  • schema/abiz-well-known-v1.1.schema.json: 5fe7da6fb5b6b262281402ab9dd9b46c018bf9df766203928e4e1a334cc3d741 (bundled for reference; the well-known file is checked by the assertion rules, as the hosted resolver does)
  • schema/iso3166.json: 0aa5112c46bc2b3efb254ea9536b3cf2977c73d48149aefcd8bc20df995e5527

Dependencies

  • github.com/miekg/dns v1.1.72: the DNS client.
  • github.com/santhosh-tekuri/jsonschema/v6 v6.0.3: JSON Schema 2020-12, with format assertion on.
  • golang.org/x/net v0.50.0: IDNA (idna).
  • Ed25519, TLS and HTTP come from the standard library. RFC 8785 is implemented here, with ECMAScript number formatting.

Licence

Apache License 2.0; see LICENSE and NOTICE. schema/iso3166.json holds codes extracted from the Debian iso-codes data and is distributed under the GNU LGPL 2.1, not Apache-2.0; see schema/ISO3166-README.md and NOTICE.

Documentation

Overview

Package abiz is the consumer side of ABIZ (Agentic Business Record), revision 1.1.

Given a domain, it reads the domain's _abiz DNS TXT assertion (or, when DNS answers with no v=abiz1 value, https://<domain>/.well-known/abiz.json), fetches the one business record the assertion points to, and checks it: the pinned JSON Schema, the semantic rules JSON Schema cannot express, the link between DNS and the record, and the record's Ed25519 signature. Results carry the same status and error code as the hosted resolver at resolve.abizrecord.org.

A resolved record is the publisher's own claim, signed with the key its DNS vouches for. This package never checks a company register and never contacts mcp_server_url or any other URL a record carries.

DNS and HTTPS sit behind the TXTResolver and Fetcher interfaces. NewResolver with no options uses DNSResolver (github.com/miekg/dns) and GuardedFetcher (net/http with the SPEC §9 fetch guard).

Example

The README example. It is compiled, not run: it needs the network.

package main

import (
	"context"
	"fmt"

	abiz "github.com/abiz-org/abiz-go"
)

func main() {
	res := abiz.Resolve(context.Background(), "example.com")
	if res.Status != abiz.StatusResolved {
		fmt.Printf("%s: %s (%s)\n", res.Status, res.Code, res.Message)
		return
	}
	fmt.Println(res.Record["business_name"], res.Record["business_key"])
	fmt.Println("found by", res.Discovery.Method, "at", res.Discovery.RecordURL)
}

Index

Examples

Constants

View Source
const (
	MaxRecordBytes = 65536 // the largest record or well-known file read
	MaxRecordDepth = 16    // the deepest nesting of objects and arrays
	MaxRecordKeys  = 5000  // the most object members in one document
	MaxDetails     = 25    // the most problems a Result carries
)

Limits (SPEC §9 and the hosted resolver).

View Source
const (
	BusinessRecordSchemaSHA256 = "3658f17f00c238b8c948fdfb447b509c5d055dd778ebd335495da05c3150ff24"
	WellKnownSchemaSHA256      = "5fe7da6fb5b6b262281402ab9dd9b46c018bf9df766203928e4e1a334cc3d741"
	ISO3166SHA256              = "0aa5112c46bc2b3efb254ea9536b3cf2977c73d48149aefcd8bc20df995e5527"
)

SHA-256 of the bundled files, as test-vectors/README.md lists them.

View Source
const (
	DNSReasonTimeout   = "timeout"
	DNSReasonNetwork   = "network"
	DNSReasonServfail  = "servfail"
	DNSReasonRefused   = "refused"
	DNSReasonMalformed = "malformed"
)

DNS failure reasons. timeout and network give dns_timeout; servfail, refused and malformed give dns_failure.

View Source
const BusinessKeyMax = 128

BusinessKeyMax is the longest business key (SPEC §4.2).

View Source
const DNSTimeLimit = 2500 * time.Millisecond

DNSTimeLimit is the time a TXT lookup may take, across every server tried.

View Source
const FetchTimeLimit = 5 * time.Second

FetchTimeLimit is the time one HTTPS fetch may take, connection and body included.

View Source
const SchemaID = "https://abizrecord.org/schema/abiz-business-record-v1.1.schema.json"

SchemaID is the $id of the bundled business record schema.

View Source
const SpecRevision = "1.1"

SpecRevision is the ABIZ revision this library implements.

View Source
const UserAgent = "abiz-go/" + Version + " (+https://abizrecord.org)"

UserAgent is sent on every HTTPS request.

View Source
const Version = "0.1.0"

Version is this library's version.

Variables

View Source
var (
	//go:embed schema/abiz-business-record-v1.1.schema.json
	BusinessRecordSchema []byte
	//go:embed schema/abiz-well-known-v1.1.schema.json
	WellKnownSchema []byte
	//go:embed schema/iso3166.json
	ISO3166 []byte
)

The bundled files, copied unchanged from abiz-org/abiz-agentic-business-record (see schema/ISO3166-README.md and test-vectors/README.md for their SHA-256).

View Source
var ErrNotIJSON = errors.New("abiz: value is not I-JSON")

ErrNotIJSON is returned by Canonicalize for a value RFC 8785 cannot canonicalise: a string that is not valid Unicode (a lone surrogate), a number that is NaN or infinite, or a Go value that is not JSON.

Functions

func Canonicalize

func Canonicalize(value any) ([]byte, error)

Canonicalize returns the RFC 8785 (JCS) form of a JSON value: no whitespace, object members sorted by the UTF-16 code units of their names, ECMAScript number and string serialisation. It accepts map[string]any, []any, string, json.Number, float64, float32, the integer types, bool and nil.

func CanonicalizeJSON

func CanonicalizeJSON(text []byte) ([]byte, error)

CanonicalizeJSON parses JSON text strictly and returns its RFC 8785 form.

func CheckRecord

func CheckRecord(recordText []byte, domain string, assertion *Assertion) (ErrorCode, []Problem, map[string]any)

CheckRecord checks a record's text offline against the queried domain and the assertion, in the hosted resolver's order: record_too_large and not_json (including repeated member names), schema_invalid (JSON Schema, then the semantic checks), identity_host_mismatch, domain_not_claimed, business_key_mismatch, public_key_mismatch, signature_invalid. It returns "" and the parsed record when the record is accepted, else the first failing code and its problems.

func FormatNumber

func FormatNumber(f float64) string

FormatNumber serialises a finite float64 as ECMAScript's Number::toString does (RFC 8785 §3.2.2.3): the shortest digits that round-trip, plain notation for exponents from -7 to 20, otherwise d.ddde±n; -0 is written 0.

func IdentityParts

func IdentityParts(value string) string

IdentityParts returns the canonical form of an h= value or an identity_host (host lower case, one trailing dot dropped, path as written), or "" when the value is not a host name with an optional path: no scheme, credentials, port, query, fragment, or "." or ".." path segment.

func IsAssertion

func IsAssertion(value string) bool

IsAssertion reports whether a TXT value counts as an ABIZ assertion: its first tag is exactly v=abiz1 (SPEC §3.1.1). V=ABIZ1, v=abiz1x and h=…;v=abiz1 do not count.

func IsAssignedCountry

func IsAssignedCountry(code string) bool

IsAssignedCountry reports whether code is an assigned ISO 3166-1 alpha-2 code, in any case.

func IsNonPublicHost

func IsNonPublicHost(host string) bool

IsNonPublicHost reports whether host ends in a special-use or private-network name (or an all-digit top-level label). Such a domain is never queried and such a record host never fetched.

func IsPublicAddr

func IsPublicAddr(addr netip.Addr) bool

IsPublicAddr is IsPublicAddress for a parsed address.

func IsPublicAddress

func IsPublicAddress(address string) bool

IsPublicAddress reports whether address (an IPv4 or IPv6 literal, optionally in brackets) is one a fetch may connect to. Anything that does not parse is refused.

func IsPublicKey

func IsPublicKey(value string) bool

IsPublicKey reports whether value is an ABIZ 1.1 p key (SPEC §3.3.2): 44 characters of standard base64 ending in one "=", decoding to 32 bytes, and canonical.

func IsSafeHTTPSURL

func IsSafeHTTPSURL(value string) bool

IsSafeHTTPSURL reports whether value is an https URL with a public DNS host name, no credentials, no fragment and no port (SPEC §4.7.1). Such URLs are checked, never fetched.

func IsSafeHost

func IsSafeHost(raw string) bool

IsSafeHost reports whether raw is a DNS host name as the reference validator accepts it: lower case after folding, at least two labels of 1 to 63 letters, digits and hyphens, no IP literal.

func ParseAssertion

func ParseAssertion(value string) (*Assertion, *AssertionError)

ParseAssertion parses one v=abiz1 value under ABIZ 1.1 (SPEC §3.1.1–§3.3.7): the tag-list syntax, recognised tags (v, h, k, p; case-sensitive) at most once, h required and a safe host with an optional path, k a business key, and p required and an Ed25519 public key in standard base64. Unknown tags are ignored, repeats included.

func ParseJSON

func ParseJSON(text []byte) (any, error)

ParseJSON parses JSON text strictly into map[string]any, []any, string, json.Number, bool and nil. A repeated member name is an error.

func ParseRecordJSON

func ParseRecordJSON(text []byte) (any, ErrorCode, []Problem)

ParseRecordJSON parses a record or well-known file as the hosted resolver does: the nesting and member limits first (record_too_large), then strict JSON (not_json), then repeated member names (not_json). On success it returns the parsed value; the code is empty.

func RecordURL

func RecordURL(h string) string

RecordURL is where a record is fetched: https://<h>?format=json (SPEC §4.5).

func SameBusinessKey

func SameBusinessKey(a, b string) bool

SameBusinessKey reports whether two business keys match ignoring ASCII case (SPEC §4.2.4).

func SignRecord

func SignRecord(record map[string]any, privateKey ed25519.PrivateKey) (map[string]any, error)

SignRecord is a producer helper: it returns a copy of record with public_key set to the key's public half (standard base64) and signature set to its Ed25519 signature over the RFC 8785 form of the record without signature. The input map is not changed.

func SigningInput

func SigningInput(record map[string]any) ([]byte, error)

SigningInput returns the bytes a record's signature signs: the RFC 8785 form of the record without its top-level signature member. It fails with ErrNotIJSON for a record JCS cannot canonicalise.

func VerifySignature

func VerifySignature(record map[string]any, p string) (ErrorCode, *Problem)

VerifySignature checks a record against the DNS assertion's p: public_key equal to p, then the signature. It returns "" when both hold, else public_key_mismatch or signature_invalid with the problem.

func WellKnownURL

func WellKnownURL(domain string) string

WellKnownURL is the well-known file on the queried domain (SPEC §3.4.1).

Types

type AddressResolver

type AddressResolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

AddressResolver looks up a host's A and AAAA addresses. *net.Resolver satisfies it.

type Assertion

type Assertion struct {
	H       string            `json:"h"`           // the canonical record host (host lower case, path as published)
	K       string            `json:"k,omitempty"` // the business key, as published; empty when absent
	HasK    bool              `json:"-"`
	P       string            `json:"p"`                 // the Ed25519 public key, standard base64
	Unknown map[string]string `json:"unknown,omitempty"` // tags the specification does not define (first value of each)
}

Assertion is a parsed _abiz assertion.

type AssertionError

type AssertionError struct {
	Code    ErrorCode // bad_pointer, duplicate_tag, missing_h, unsafe_host or invalid_key
	Message string
}

AssertionError is why an assertion did not parse.

func (*AssertionError) Error

func (e *AssertionError) Error() string

type BusinessKey

type BusinessKey struct {
	Country     string
	Subdivision string
	Number      string
	Canonical   string
}

BusinessKey is a parsed business key in canonical form (lowercase country and subdivision, uppercase number).

func ParseBusinessKey

func ParseBusinessKey(value string) (BusinessKey, error)

ParseBusinessKey parses a business key under SPEC §4.2.1–§4.2.2.

type DNSResolver

type DNSResolver struct {
	// Servers are "host:port" addresses of recursive resolvers, tried in order while one times out
	// or cannot be reached.
	Servers []string
	// Timeout bounds the whole lookup (DNSTimeLimit when zero).
	Timeout time.Duration
}

DNSResolver is the default TXTResolver: a plain DNS client (github.com/miekg/dns) that asks the configured recursive servers directly, so that it can tell NXDOMAIN, NODATA, SERVFAIL, REFUSED, a malformed answer and a timeout apart. The standard library's net.Resolver folds several of these together (and the cgo resolver reports them differently again), and ABIZ must never treat a failure as absence.

func NewDNSResolver

func NewDNSResolver() *DNSResolver

NewDNSResolver returns a DNSResolver using the servers in /etc/resolv.conf. When that file cannot be read it has no servers, and every lookup fails as dns_timeout: give servers with NewDNSResolverWithServers (for example 1.1.1.1:53) on systems without resolv.conf.

func NewDNSResolverWithServers

func NewDNSResolverWithServers(servers ...string) *DNSResolver

NewDNSResolverWithServers returns a DNSResolver asking the given servers ("host:port", or a bare host for port 53).

func (*DNSResolver) LookupTXT

func (r *DNSResolver) LookupTXT(ctx context.Context, name string) TXTResult

LookupTXT implements TXTResolver.

type Discovery

type Discovery struct {
	Method       string   `json:"method"` // "dns_txt" or "well_known"
	Owner        string   `json:"owner"`  // _abiz.<domain>
	DNSValue     string   `json:"dns_value,omitempty"`
	DNSValues    []string `json:"dns_values,omitempty"` // every v=abiz1 value, on multiple_txt
	DNSTTL       *int     `json:"dns_ttl_seconds,omitempty"`
	WellKnown    string   `json:"well_known"` // not_checked, absent, invalid, unavailable, used
	WellKnownURL string   `json:"well_known_url,omitempty"`
	RecordURL    string   `json:"record_url,omitempty"`
}

Discovery says how the assertion was found and where the record was fetched from.

type ErrorCode

type ErrorCode string

ErrorCode names why a resolution or a check failed. The empty code means no error.

const (
	CodeMissingInput         ErrorCode = "missing_input"
	CodeBothInputs           ErrorCode = "both_inputs"
	CodeInvalidDomain        ErrorCode = "invalid_domain"
	CodeInvalidWebsite       ErrorCode = "invalid_website"
	CodeNonPublicDomain      ErrorCode = "non_public_domain"
	CodeMissingTXT           ErrorCode = "missing_txt"
	CodeMultipleTXT          ErrorCode = "multiple_txt"
	CodeBadPointer           ErrorCode = "bad_pointer"
	CodeDuplicateTag         ErrorCode = "duplicate_tag"
	CodeMissingH             ErrorCode = "missing_h"
	CodeUnsafeHost           ErrorCode = "unsafe_host"
	CodeInvalidKey           ErrorCode = "invalid_key"
	CodeFetchFailed          ErrorCode = "fetch_failed"
	CodeRecordTooLarge       ErrorCode = "record_too_large"
	CodeNotJSON              ErrorCode = "not_json"
	CodeSchemaInvalid        ErrorCode = "schema_invalid"
	CodeIdentityHostMismatch ErrorCode = "identity_host_mismatch"
	CodeDomainNotClaimed     ErrorCode = "domain_not_claimed"
	CodeBusinessKeyMismatch  ErrorCode = "business_key_mismatch"
	CodePublicKeyMismatch    ErrorCode = "public_key_mismatch"
	CodeSignatureInvalid     ErrorCode = "signature_invalid"
	CodeDNSTimeout           ErrorCode = "dns_timeout"
	CodeDNSFailure           ErrorCode = "dns_failure"
	CodeUpstreamTimeout      ErrorCode = "upstream_timeout"
	CodeOriginUnavailable    ErrorCode = "origin_unavailable"
)

Error codes, as the hosted resolver reports them.

func DomainFromWebsite

func DomainFromWebsite(raw string) (string, ErrorCode, string)

DomainFromWebsite takes the host of an http or https website address and normalises it as NormaliseDomain does. The path is ignored.

func NormaliseDomain

func NormaliseDomain(raw string) (string, ErrorCode, string)

NormaliseDomain checks and normalises a domain given as a host name.

func NormaliseInput

func NormaliseInput(in Input) (domain string, code ErrorCode, message string)

NormaliseInput reduces an Input to the domain that is queried: lower case, IDN to A-labels, one trailing dot dropped. www. is never stripped. On failure it returns the error code (missing_input, both_inputs, invalid_domain, invalid_website or non_public_domain) and a message.

func (ErrorCode) Message

func (c ErrorCode) Message() string

Message is the standard English message for a code.

func (ErrorCode) Retryable

func (c ErrorCode) Retryable() bool

Retryable reports whether trying again later may give a different answer.

func (ErrorCode) Status

func (c ErrorCode) Status() Status

Status is the resolution status a code belongs to.

type FetchKind

type FetchKind int

FetchKind is the kind of outcome a fetch had.

const (
	FetchResponse  FetchKind = iota // an HTTP response (Status, ContentType, Body)
	FetchBlocked                    // the fetch guard refused the URL or the host's addresses
	FetchNoAddress                  // the host has no A or AAAA address
	FetchDNSError                   // the host's addresses could not be looked up
	FetchTimeout                    // the request did not complete within the time limit
	FetchNetwork                    // the connection or TLS failed
)

The fetch outcomes.

type FetchResult

type FetchResult struct {
	Kind        FetchKind
	Status      int
	ContentType string // "" when the response had none
	Body        []byte
	// TooLarge is set when the body was larger than MaxRecordBytes; Body is then nil.
	TooLarge bool
	Message  string // why FetchBlocked refused
}

FetchResult is a fetch's outcome.

type Fetcher

type Fetcher interface {
	Fetch(ctx context.Context, url string) FetchResult
}

Fetcher makes one HTTPS GET with Accept: application/json, never following a redirect, within the size and time limits, behind the SPEC §9 fetch guard.

type GuardedFetcher

type GuardedFetcher struct {
	// Resolver looks up addresses (net.DefaultResolver when nil).
	Resolver AddressResolver
	// contains filtered or unexported fields
}

GuardedFetcher is the default Fetcher: net/http behind the SPEC §9 fetch guard. It resolves the host itself, refuses unless every address is public (IsPublicAddr), and then connects to a checked address, never to the name again, so there is no DNS rebinding window. TLS is verified against the host name (SNI and Host are the name). It sends Accept: application/json and User-Agent, never follows a redirect, ignores proxy environment variables, gives up after FetchTimeLimit and reads at most MaxRecordBytes of the body.

func NewGuardedFetcher

func NewGuardedFetcher() *GuardedFetcher

NewGuardedFetcher returns a GuardedFetcher using net.DefaultResolver.

func (*GuardedFetcher) Fetch

func (f *GuardedFetcher) Fetch(ctx context.Context, rawURL string) FetchResult

Fetch implements Fetcher.

type Input

type Input struct {
	Domain  string
	Website string
}

Input is what Resolve accepts: exactly one of a domain and a website address.

type Option

type Option func(*Resolver)

Option configures a Resolver.

func WithFetcher

func WithFetcher(f Fetcher) Option

WithFetcher replaces the HTTPS adapter.

func WithTXTResolver

func WithTXTResolver(r TXTResolver) Option

WithTXTResolver replaces the DNS adapter.

type Problem

type Problem struct {
	Path    string `json:"path"`
	Message string `json:"message"`
}

Problem is one reason a check failed: a JSON Pointer into the record (or "$", or a DNS name or URL for problems outside the record) and a message.

func ValidateSchema

func ValidateSchema(record any) []Problem

ValidateSchema checks a parsed record against the bundled JSON Schema and returns its problems (none when it conforms). The record's objects must be map[string]any and its numbers json.Number or float64, as ParseRecordJSON returns them.

type Resolver

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

Resolver resolves domains to checked ABIZ records. The zero value is not usable: use NewResolver.

func NewResolver

func NewResolver(opts ...Option) *Resolver

NewResolver returns a Resolver. By default it reads DNS with NewDNSResolver() (the system's resolv.conf servers) and fetches with NewGuardedFetcher().

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, domain string) *Result

Resolve resolves a domain given as a host name.

func (*Resolver) ResolveInput

func (r *Resolver) ResolveInput(ctx context.Context, in Input) *Result

ResolveInput resolves exactly one of a domain and a website address.

func (*Resolver) ResolveWebsite

func (r *Resolver) ResolveWebsite(ctx context.Context, website string) *Result

ResolveWebsite resolves the host of a website address. The apex is never tried in place of a www. host; it is only suggested (a try_apex warning).

type Result

type Result struct {
	Status    Status     `json:"status"`
	Code      ErrorCode  `json:"code"` // empty when resolved
	Message   string     `json:"message,omitempty"`
	Retryable bool       `json:"retryable"`
	Details   []Problem  `json:"details,omitempty"` // at most MaxDetails
	Truncated bool       `json:"truncated,omitempty"`
	Domain    string     `json:"domain,omitempty"`  // the queried domain (the input as given when it was refused)
	Website   string     `json:"website,omitempty"` // the website input, when one was given
	Discovery *Discovery `json:"discovery,omitempty"`
	Warnings  []Warning  `json:"warnings"`
	// Record is the checked record, only when Status is resolved. Objects are map[string]any,
	// numbers json.Number.
	Record map[string]any `json:"record,omitempty"`
	// RecordJSON is the record exactly as served, only when Status is resolved.
	RecordJSON []byte `json:"-"`
}

Result is the outcome of Resolve.

func Resolve

func Resolve(ctx context.Context, domain string) *Result

Resolve resolves a domain with a default Resolver.

type Status

type Status string

Status is the outcome of a resolution.

const (
	StatusResolved      Status = "resolved"
	StatusInvalidInput  Status = "invalid_input"
	StatusNotFound      Status = "not_found"
	StatusConflict      Status = "conflict"
	StatusInvalidRecord Status = "invalid_record"
	StatusUnavailable   Status = "unavailable"
)

The statuses a Result can have.

type TXTKind

type TXTKind int

TXTKind is the kind of answer a TXT lookup gave.

const (
	TXTAnswer   TXTKind = iota // the name has TXT records (Values)
	TXTNXDomain                // the name does not exist
	TXTNoData                  // the name exists with no TXT record
	TXTError                   // the lookup failed (Reason)
)

The TXT lookup outcomes. Absence (NXDOMAIN, NODATA) and failure are different things.

type TXTResolver

type TXTResolver interface {
	LookupTXT(ctx context.Context, name string) TXTResult
}

TXTResolver looks up the TXT records at a name. An implementation may use DNS-over-HTTPS, a cache or a test stub.

type TXTResult

type TXTResult struct {
	Kind TXTKind
	// Values holds one string per TXT record, its character-strings joined with nothing between
	// them and unescaped.
	Values []string
	// TTL is the answer's TTL in seconds, or -1 when unknown.
	TTL    int
	Reason string // for TXTError
}

TXTResult is a TXT lookup's outcome.

type Warning

type Warning struct {
	// Code is "content_type" (the record was served without a JSON content type and read anyway)
	// or "try_apex" (nothing at a www. name; Domain is the apex, which was not checked).
	Code    string `json:"code"`
	Domain  string `json:"domain,omitempty"`
	Message string `json:"message"`
}

Warning is advice that does not change the status.

Directories

Path Synopsis
cmd
abiz command
Command abiz checks a domain's ABIZ record.
Command abiz checks a domain's ABIZ record.

Jump to

Keyboard shortcuts

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