badkeys

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: BSD-2-Clause, BSD-3-Clause, MIT, + 1 more Imports: 33 Imported by: 0

README

Bad Keys

This is a partial Go implementation of Hanno Böck's badkeys project.

The major differences include:

  • This project does not implement weak prime detection.

  • This project is missing other badkeys detections:

    • Fermat
    • Patterns
    • ROCA
    • RSA Invalid
    • RSA Warnings
    • Shared Primes
    • Small Factors
    • XZ Backdoor

Documentation

Index

Constants

View Source
const BadKeysMetaURL = "https://update.badkeys.info/v0/badkeysdata.json"
View Source
const BlockHashPrefix = 15
View Source
const BlockLength = 16
View Source
const CacheFileBlocklist = "blocklist.dat"
View Source
const CacheFileLookup = "lookup.txt"
View Source
const CacheFileMetadata = "badkeysdata.json"
View Source
const HTTPDataDownloadTimeout = time.Hour
View Source
const HTTPMetaDownloadTimeout = time.Second * 30
View Source
const MaxLookupLine = 4096
View Source
const MaxResponseSize = 1024 * 1024 * 512 // Adjust if the block list becomes larger

Variables

This section is empty.

Functions

func GetExecutableDir added in v0.0.2

func GetExecutableDir() string

GetExecutableDir returns the full path to the running binary's directory

func GetExecutablePath added in v0.0.2

func GetExecutablePath() string

GetExecutablePath returns the full path to the running binary

func PrefixFromPublicKey

func PrefixFromPublicKey(pub any) ([]byte, error)

PrefixFromPublicKey implements the badkeys `blocklistmaker` hashing method

Types

type Blocklist added in v0.0.2

type Blocklist struct {
	Meta          *Meta
	Blocks        []byte
	Repos         Repos
	LookupMap     map[uint64][]int
	LookupStrings []string
	Error         error
}

func NewBlocklist added in v0.0.2

func NewBlocklist() *Blocklist

func (*Blocklist) FindBlock added in v0.0.2

func (tset *Blocklist) FindBlock(k []byte) ([]byte, error)

func (*Blocklist) LookupPrefix added in v0.0.2

func (tset *Blocklist) LookupPrefix(sum []byte) (*Result, error)

type Cache added in v0.0.2

type Cache struct {
	sync.Mutex
	Blocklist *Blocklist
	LoadError error
	// contains filtered or unexported fields
}

func NewCache added in v0.0.2

func NewCache(lgr *logrus.Logger) *Cache

func (*Cache) CreateFile added in v0.0.2

func (cache *Cache) CreateFile(path string) (io.WriteCloser, error)

CreateFile returns a writer for the given cache file name

func (*Cache) CurrentMetadata added in v0.0.2

func (cache *Cache) CurrentMetadata() (*Meta, error)

func (*Cache) DownloadAndValidateXZ added in v0.0.2

func (cache *Cache) DownloadAndValidateXZ(u string, hash string, path string) error

func (*Cache) GetCacheDir added in v0.0.2

func (cache *Cache) GetCacheDir() string

GetCacheDir returns the location of the badkeys block tables

func (*Cache) LoadBlocklist added in v0.0.2

func (cache *Cache) LoadBlocklist() (*Blocklist, error)

LoadBlocklist loads the blocklist from disk if necessary

func (*Cache) OpenFile added in v0.0.2

func (cache *Cache) OpenFile(path string) (io.ReadCloser, error)

OpenFile returns a reader for the given cache file name

func (*Cache) RemoveFile added in v0.0.2

func (cache *Cache) RemoveFile(path string) error

RemoveFile deletes a file from the cache

func (*Cache) RenameFile added in v0.0.2

func (cache *Cache) RenameFile(src string, dst string) error

RenameFile replaces one file with another in the caache

func (*Cache) SetCacheDir added in v0.0.2

func (cache *Cache) SetCacheDir(s string)

SetCacheDir sets the location of the badkeys block tables

func (*Cache) Update added in v0.0.2

func (cache *Cache) Update() (string, string, error)

type Dirs

type Dirs []string

type Meta

type Meta struct {
	BKFormat        int    `json:"bkformat,omitempty"`
	Date            string `json:"date,omitempty"`
	BlocklistURL    string `json:"blocklist_url,omitempty"`
	BlocklistSHA256 string `json:"blocklist_sha256,omitempty"`
	LookupURL       string `json:"lookup_url,omitempty"`
	LookupSHA256    string `json:"lookup_sha256,omitempty"`
	Blocklists      []Repo `json:"blocklists,omitempty"`
}

func ReadBadKeysManifest added in v0.0.2

func ReadBadKeysManifest(r io.Reader) (*Meta, error)

type Paths

type Paths []string

type Repo

type Repo struct {
	ID   int    `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
	Type string `json:"type,omitempty"`
	Repo string `json:"repo,omitempty"`
	Path string `json:"path,omitempty"`
}

type Repos

type Repos map[int]Repo

type Result

type Result struct {
	Repo     string
	RepoID   int8
	RepoType string
	RepoPath string
	RepoName string
	KeyPath  string
	Private  bool
	Hash     string
}

func (*Result) GetID added in v0.2.0

func (r *Result) GetID() string

func (*Result) GetURL added in v0.2.0

func (r *Result) GetURL() string

Jump to

Keyboard shortcuts

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