Help us shape the future of Go! Take the 2026 Go Developer Survey

ct

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ct monitors Certificate Transparency for watched domains through CT search services (Cert Spotter, crt.sh). It never mirrors CT logs: only issuances matching watched names are fetched and stored.

Index

Constants

View Source
const (
	StatusKnown      = "known"      // the certificate or its key is in the inventory
	StatusNew        = "new"        // not in the inventory, from an issuer already used for these names
	StatusChanged    = "changed"    // same names as a stored certificate, different certificate
	StatusUnexpected = "unexpected" // not in the inventory and from an issuer not seen before
	StatusExpired    = "expired"
)

Observation statuses. Unknown certificates are never called malicious: "unexpected" only means the issuance does not fit what is known.

Variables

View Source
var ErrNoWatches = errors.New("no CT watches configured; add one with 'sslknife ct watch example.com'")

ErrNoWatches is returned by commands when nothing is watched.

View Source
var ErrNotWatched = errors.New("domain is not watched")

ErrNotWatched is returned when a domain filter matches no watch.

View Source
var ErrRateLimited = errors.New("CT provider rate limit reached; try again later")

ErrRateLimited is returned when the service asks us to slow down.

Functions

func AutoWatch

func AutoWatch(ctx context.Context, db *database.DB, idx *database.CertIndex) (int, error)

AutoWatch adds watches for DNS SANs of stored certificates (wildcards become subdomain watches). It returns the number of watches added.

func Classify

func Classify(is Issuance, idx *database.CertIndex, seenIssuers map[string]bool, now time.Time) (status, reason, certID string)

Classify assigns a status to an issuance using the inventory index and issuers already seen for the watch.

func NormalizePattern

func NormalizePattern(p string, subdomains bool) (string, bool, error)

NormalizePattern turns "example.com" or "*.example.com" into a domain and subdomain flag.

Types

type CertSpotter

type CertSpotter struct {
	Client   *http.Client
	Token    string // optional API key; raises the rate limit
	BaseURL  string
	MaxPages int
}

CertSpotter queries SSLMate's Cert Spotter API, which de-duplicates precertificates and supports incremental polling with "after".

func (*CertSpotter) Name

func (*CertSpotter) Name() string

func (*CertSpotter) Search

func (c *CertSpotter) Search(ctx context.Context, q Query) ([]Issuance, string, error)

Search pages through issuances after q.Cursor.

type CheckResult

type CheckResult struct {
	Watch   database.CTWatch         `json:"-"`
	Pattern string                   `json:"watch"`
	Fetched int                      `json:"fetched"`
	Added   []database.CTObservation `json:"new_observations"`
	Error   string                   `json:"error,omitempty"`
}

CheckResult reports one watch poll.

func RunAll

func RunAll(ctx context.Context, db *database.DB, chk *Checker, domain string, autoWatch bool) ([]CheckResult, int, error)

RunAll polls every watch (or those for domain), optionally adding watches for stored certificate names first. It returns the per-watch results and the number of watches added automatically.

type Checker

type Checker struct {
	DB       *database.DB
	Provider Provider
	Now      func() time.Time
}

Checker polls providers and stores observations.

func (*Checker) Check

Check polls one watch.

type CrtSh

type CrtSh struct {
	Client  *http.Client
	BaseURL string
}

CrtSh queries crt.sh. It has no incremental cursor; results are de-duplicated by issuer and serial number.

func (*CrtSh) Name

func (*CrtSh) Name() string

func (*CrtSh) Search

func (c *CrtSh) Search(ctx context.Context, q Query) ([]Issuance, string, error)

type Issuance

type Issuance struct {
	Provider     string    `json:"provider"`
	ID           string    `json:"id"`
	Identity     string    `json:"identity"` // de-duplicates precertificate/certificate pairs
	CertSHA256   string    `json:"cert_sha256,omitempty"`
	PubkeySHA256 string    `json:"pubkey_sha256,omitempty"`
	Serial       string    `json:"serial,omitempty"`
	Issuer       string    `json:"issuer"`
	IssuerName   string    `json:"issuer_name,omitempty"`
	DNSNames     []string  `json:"dns_names"`
	NotBefore    time.Time `json:"not_before"`
	NotAfter     time.Time `json:"not_after"`
	Revoked      *bool     `json:"revoked,omitempty"`
}

Issuance is one certificate (or precertificate) found in CT.

type Provider

type Provider interface {
	Name() string
	// Search returns issuances after the cursor and the new cursor.
	Search(ctx context.Context, q Query) ([]Issuance, string, error)
}

Provider searches a CT aggregation service.

func NewProvider

func NewProvider(name string, d netdial.Dialer, token string) (Provider, error)

NewProvider returns a provider by name.

type Query

type Query struct {
	Domain            string
	IncludeSubdomains bool
	Cursor            string // provider-specific position from the previous poll
}

Query describes what to search for.

Jump to

Keyboard shortcuts

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