Documentation
¶
Overview ¶
Package sniscan looks for REALITY targets among the neighbours of a node: sites in the same /24 that answer on TCP 443 with TLS 1.3 and X25519MLKEM768 and a certificate that holds for their name (agent.proto "NEIGHBOR SITES").
This is outgoing traffic from the node to addresses that are not the owner's, so the package is built not to be a scanner of anything else:
- The only input is an address, and it must be a public IPv4 address that is assigned to one of this host's own interfaces. The range is that address's /24 and nothing else; the panel cannot name another one (ErrNotMyAddress).
- The port is 443. Addresses of this host are left out.
- The limits are constants: at most MaxPerSecond new connections a second for the whole scan, MaxParallel at a time, Budget in all (what was done by then is returned as partial), short timeouts per step, at most MaxNames names and two connections per address after the first.
- What comes back from a neighbour is reduced at once to host names from its certificate and a few flags (names.go); no other data of a response leaves the package, and the body of a response is never read.
Everything that touches the outside is a field of Scanner (Dial, Resolve, Roots, Self, Now, Sleep), so the tests run against servers in the process and a fake clock, never against a network.
Index ¶
Constants ¶
const ( // Port is the only port the scan connects to. Port = 443 // MaxPerSecond is the most new TCP connections a second for the whole scan, whatever the number of workers. MaxPerSecond = 10 // MaxParallel is the most addresses handled at the same time. MaxParallel = 16 // MaxNames is the most names tried per address: one more connection each. MaxNames = 2 // Budget is the longest a scan runs; what is done by then is returned, marked partial. Budget = 50 * time.Second // MaxCandidates is the most candidates returned. MaxCandidates = 20 // MinDaysLeft is how long a certificate must still hold for its site to be a candidate. MinDaysLeft = 14 // MaxHeader bounds what is read of an HTTP response: its head. The body is never read. MaxHeader = 16 << 10 )
The limits. Constants on purpose: the owner cannot widen them from the panel.
const ( DNSHere = "here" // the name has this very address DNSSubnet = "subnet" // another address of the same /24 DNSElsewhere = "elsewhere" // somewhere else: a CDN or a balancer in front, usually DNSNone = "none" // no IPv4 answer )
DNS answers about where a candidate's name leads.
Variables ¶
var ( // ErrNotMyAddress: the address is not a public IPv4 address of one of this host's interfaces (a name behind a CDN, // a stale DNS record, a NAT: the scan would not start from that address). ErrNotMyAddress = errors.New("not_my_address") // ErrNoRoots: this host has no CA roots, so no certificate can be judged; an empty list would be a wrong answer. ErrNoRoots = errors.New("no_roots") // ErrBadAddress: not an IPv4 address. ErrBadAddress = errors.New("bad_params") )
Functions ¶
This section is empty.
Types ¶
type Candidate ¶
type Candidate struct {
IP string `json:"ip"`
Name string `json:"name"`
DNS string `json:"dns"`
H2 bool `json:"h2"`
SingleSite bool `json:"single_site"`
// HTTP is the status of GET / (redirects not followed), 0 = no answer.
HTTP int `json:"http"`
// Ms is the TLS handshake in milliseconds.
Ms int `json:"ms"`
// Days is the days the certificate still holds.
Days int `json:"days"`
// contains filtered or unexported fields
}
Candidate is one site that can serve as a REALITY target.
type Result ¶
type Result struct {
Addresses, Open, TLS13, MLKEM, Valid int
// Partial: the budget ran out before every address was done.
Partial bool
Candidates []Candidate
}
Result is what a scan found. The counters count addresses: how many were looked at, how many answered on 443, how many of those speak TLS 1.3, how many have a name whose handshake picked X25519MLKEM768, and how many of those are good candidates.
type Scanner ¶
type Scanner struct {
// Dial opens a TCP connection to remote from the local address.
Dial func(ctx context.Context, local netip.Addr, remote netip.AddrPort) (net.Conn, error)
// Resolve returns the IPv4 addresses of a name, with this host's resolver.
Resolve func(ctx context.Context, host string) ([]netip.Addr, error)
// Roots are the CA roots a certificate must lead to.
Roots func() (*x509.CertPool, error)
// Self lists the addresses assigned to this host's interfaces.
Self func() ([]netip.Addr, error)
// Now is the clock; Sleep waits until a time or until ctx ends.
Now func() time.Time
Sleep func(ctx context.Context, until time.Time) error
// contains filtered or unexported fields
}
Scanner runs scans. Create it with New; tests replace the fields.