x509util

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootPrograms = map[string]RemoteBundle{
	"mozilla": {Url: "https://ccadb.my.salesforce-sites.com/mozilla/IncludedRootsPEMTxt?TrustBitsInclude=Websites", Format: "pem", Parser: parseMozilla},
}

Microsoft has a *.cab file in a well-known location, but it only contains a list of thumbprints that doesn't entirely overlap with Mozilla's list. Chrome's list can be retrieved with a bit of HTML-stripping and parsing of a couple of files in chromium's source, but that is brittle. Apple provides an unhelpful list of CAs in a webpage. For now, we'll just support Mozilla. robstradling has already solved all of this. We can periodically reconstruct trust stores by using the public postgres db from crt.sh.

Functions

func ExtractLeafAndIntermediates

func ExtractLeafAndIntermediates(certs []*x509.Certificate) (*x509.Certificate, *x509.CertPool, error)

Given a certificate chain, separate into the leaf and the intermediates

func GetSubjectKeyID

func GetSubjectKeyID(pubKey interface{}) ([]byte, error)

GetSubjectKeyID calculates a subject key identifier by doing a SHA-1 hash over the ASN.1 encoding of the public key.

func IsPem

func IsPem(data []byte) bool

func LoadPKCS12CertPool

func LoadPKCS12CertPool(p12data []byte, password string) (*x509.CertPool, error)

func NewCertPool

func NewCertPool(certs ...*x509.Certificate) *x509.CertPool

func NewSerialNumber

func NewSerialNumber() (*big.Int, error)

NewSerialNumber creates a random certificate serial number according to CA/Browser forum spec Section 7.1: "Effective September 30, 2016, CAs SHALL generate non-sequential Certificate serial numbers greater than zero (0) containing at least 64 bits of output from a CSPRNG"

func ParseCaBundleFromFile

func ParseCaBundleFromFile(filePath string, password string, format string) (*x509.CertPool, error)

The main difference with ReadCertificatesFromFile is that this returns a CertPool, which gets passed into the verification function. It also handles Java KeyStores and PKCS#12 files.

func ParseRemoteBundle

func ParseRemoteBundle(remoteBundle RemoteBundle) (*x509.CertPool, error)

Downloads a remote bundle to a temporary file and then calls ParseCaBundleFromFile

func ReadCertificatesFromEndpoint

func ReadCertificatesFromEndpoint(client HTTPClient, url *url.URL) ([]*x509.Certificate, error)

Pulls the certificate chain from an HTTPs endpoint

func ReadCertificatesFromFile

func ReadCertificatesFromFile(filename string, format string, password string) ([]*x509.Certificate, error)

Reads a certificate chain from a file

Types

type HTTPClient

type HTTPClient interface {
	GetPeerCertificates(url *url.URL) ([]*x509.Certificate, error)
}

type RealHTTPClient

type RealHTTPClient struct {
	Client *http.Client
}

func (*RealHTTPClient) GetPeerCertificates

func (c *RealHTTPClient) GetPeerCertificates(url *url.URL) ([]*x509.Certificate, error)

type RemoteBundle

type RemoteBundle struct {
	Url    string
	Base64 bool
	Format string
	Parser func(*http.Response) (io.Reader, error)
}

Jump to

Keyboard shortcuts

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