badkeys

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package badkeys implements DNSKEY vulnerability checks and blocklist management.

Index

Constants

View Source
const (
	// UpdateURL is the upstream badkeys metadata endpoint.
	UpdateURL = "https://update.badkeys.info/v0/badkeysdata.json"
)

Variables

This section is empty.

Functions

func BKHASH120

func BKHASH120(val *big.Int) [15]byte

BKHASH120 computes the badkeys truncated hash for a key's numeric value. The value is encoded as big-endian bytes without leading zeros, SHA-256 hashed, and truncated to 15 bytes (120 bits).

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir returns the default user data directory for badkeys files. On Linux/macOS: ~/.local/share/gonemaster/badkeys On other platforms: ~/.gonemaster/badkeys

func Update

func Update(outputDir string, w io.Writer) error

Update downloads the badkeys blocklist to outputDir. It returns nil on success. Progress messages are written to w.

Types

type Blocklist

type Blocklist struct {
	Data    []byte         // raw blocklist.dat content (sorted 16-byte blocks)
	Sources map[int]string // source ID → blocklist name
	Entries int            // number of 16-byte blocks
}

Blocklist holds the loaded blocklist data and metadata.

func LoadBlocklist

func LoadBlocklist(profilePath string) (*Blocklist, error)

LoadBlocklist finds and loads the blocklist using the search path:

  1. profilePath (from badkeys.path profile key / --badkeys-path CLI flag)
  2. XDG user data directory (~/.local/share/gonemaster/badkeys/)
  3. Embedded data (if compiled with badkeys_embed build tag)

Returns nil, nil if no blocklist is available anywhere.

func (*Blocklist) Check

func (bl *Blocklist) Check(val *big.Int) *CheckResult

Check looks up a key's numeric value in the blocklist. Returns nil if the key is not found.

type BlocklistError

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

BlocklistError is returned for blocklist format issues.

func (*BlocklistError) Error

func (e *BlocklistError) Error() string

type CheckResult

type CheckResult struct {
	SourceID   int
	SourceName string
}

CheckResult holds the result of a blocklist lookup.

type Finding

type Finding struct {
	// Check is the check name: "fermat", "pattern", "roca", "rsainvalid",
	// "smallfactors", "smalld", or "blocklist".
	Check string
	// BlocklistName is the blocklist source name (only for "blocklist" check).
	BlocklistName string
}

Finding represents a single detected vulnerability or blocklist match.

func CheckDNSKEY

func CheckDNSKEY(algo uint8, keyData []byte, bl *Blocklist) ([]Finding, error)

CheckDNSKEY parses a DNSKEY record and runs all applicable badkeys checks.

algo is the DNSKEY algorithm number. keyData is the raw public key bytes (after the 4-byte DNSKEY RDATA header: flags, protocol, algorithm). bl is the loaded blocklist (may be nil to skip blocklist checks).

Returns a list of findings (empty if the key passes all checks).

type KeyType

type KeyType int

KeyType identifies the cryptographic key family.

const (
	KeyTypeRSA   KeyType = iota // Algorithms 1, 5, 7, 8, 10
	KeyTypeDSA                  // Algorithms 3, 6
	KeyTypeECDSA                // Algorithms 13, 14
	KeyTypeEdDSA                // Algorithms 15, 16
)

type Metadata

type Metadata struct {
	BKFormat        int    `json:"bkformat"`
	Deprecated      any    `json:"deprecated,omitempty"`
	BlocklistURL    string `json:"blocklist_url"`
	BlocklistSHA256 string `json:"blocklist_sha256"`
}

Metadata is the subset of badkeysdata.json needed for blocklist management.

type ParsedKey

type ParsedKey struct {
	Type KeyType
	// N is the RSA modulus (RSA only).
	N *big.Int
	// E is the RSA public exponent (RSA only).
	E *big.Int
	// Val is the primary numeric value used for BKHASH and blocklist checks:
	//   RSA: N, DSA: Y, ECDSA: X coordinate, EdDSA: raw key as integer.
	Val *big.Int
	// Bits is the key size in bits (RSA: N.BitLen(), DSA: 512+t*64).
	Bits int
}

ParsedKey holds the extracted numeric values from a DNSKEY wire-format key.

func ParseDNSKEY

func ParseDNSKEY(algo uint8, keyData []byte) (*ParsedKey, error)

ParseDNSKEY parses the DNSKEY RDATA key material (the public key bytes after the 4-byte DNSKEY header: flags, protocol, algorithm).

algo is the DNSKEY algorithm number. keyData is the raw public key bytes.

Wire format references:

Jump to

Keyboard shortcuts

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