Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSelfSigned ¶ added in v0.99.0
func IsSelfSigned(cert *x509.Certificate) bool
IsSelfSigned checks for a self-signed certificate.
func IsSignedBy ¶ added in v0.99.0
func IsSignedBy(cert, root *x509.Certificate) (ok bool)
IsSignedBy does a check if cert is signed by root. Do not ever use this function for any other purpose than sorting, as it's skipping a lot of important steps from 5280 such as verifying basic constraints, validity or path depths (since we're only interested in sorting certificates).
func KeyBelongsTo ¶ added in v0.99.0
func KeyBelongsTo(cert *x509.Certificate, key interface{}) (ok bool)
KeyBelongsTo checks if the cert is signed by the key. The key can be any supported public or private key. See PrivateKeyBelongsTo for how private keys are handled.
func PrivateKeyBelongTo ¶ added in v0.99.0
func PrivateKeyBelongTo(cert *x509.Certificate, key interface{}) (ok bool)
PrivateKeyBelongTo is like KeyBelongsTo, but only for private keys. Note that we're just comparing public key parts of the passed key. There are no checks performed to see if the public key part of the private key is actually valid (since we should only be using this function for sorting).
Types ¶
type CertPool ¶
type CertPool struct {
// contains filtered or unexported fields
}
CertPool is a set of certificates.
func SystemCertPool ¶
SystemCertPool returns a copy of the system cert pool.
Any mutations to the returned pool are not written to disk and do not affect any other pool.
New changes in the the system cert pool might not be reflected in subsequent calls.
func (*CertPool) AddCert ¶
func (pool *CertPool) AddCert(cert *x509.Certificate)
AddCert adds a certificate to a pool.
func (*CertPool) AppendCertsFromPEM ¶
AppendCertsFromPEM attempts to parse a series of PEM encoded certificates. It appends any certificates found to s and reports whether any certificates were successfully parsed.
On many Linux systems, /etc/ssl/cert.pem will contain the system wide set of root CAs in a format suitable for this function.
type Sorter ¶ added in v0.99.0
type Sorter struct { // Blocks are our PEM blocks. Blocks []*pem.Block // Roots are our trusted root certificates. Roots *CertPool // Order of our blocks. Order []string // contains filtered or unexported fields }
Sorter can help sort slices of PEM blocks. You can use this struct directly, but the certificate resolution won't be cached, if you wish to use a cached version of the Sorter, invoke New.
The sorter deploys the following sorting strategy: * Compare the block types A and B:
- If A and B are certificates:
- If A is an invalid certificate, sort after
- If B is an invalid certificate, sort before
- If A is signed by B, sort before
- If B is signed by A, sort after
- If either one of A and B are a certificate and the other a private key:
- If key A belongs to certificate B, reverse sort against Order list
- If key B belongs to certificate A, forward sort against Order list
* Lookup the block type of A and B against the Order list, then:
- If A is unknown, sort after
- If B is unknown, sort before
- Compare if A is before B in the order list
func (*Sorter) ExcludeRoots ¶ added in v0.99.0
ExcludeRoots checks if the blocks in sorter are a root certificate, and if they are, they will be removed.
func (*Sorter) ResolveRoots ¶ added in v0.99.0
ResolveRoots checks if the blocks in sorter have a root certificate and if they do not, it will attempt to resolve the root certificate for the passed certificates.