Overview
Package x509 parses X.509-encoded keys and certificates.
On UNIX systems the environment variables SSL_CERT_FILE and SSL_CERT_DIR can be
used to override the system default locations for the SSL certificate file and
SSL certificate files directory, respectively.
Index
- Variables
- func CreateCertificateRequest(rand io.Reader, template *CertificateRequest, priv interface{}) (csr []byte, err error)
- func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, alg PEMCipher) (*pem.Block, error)
- func MarshalECPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)
- func MarshalPKCS1PublicKey(key *rsa.PublicKey) []byte
- func MarshalPKIXPublicKey(pub interface{}) ([]byte, error)
- func ParseCertificates(asn1Data []byte) ([]*Certificate, error)
- func ParseECPrivateKey(der []byte) (*ecdsa.PrivateKey, error)
- func ParsePKCS1PublicKey(der []byte) (*rsa.PublicKey, error)
- func ParsePKIXPublicKey(derBytes []byte) (pub interface{}, err error)
- func ParseCertificate(asn1Data []byte) (*Certificate, error)
- func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature []byte) error
- func (c *Certificate) CreateCRL(rand io.Reader, priv interface{}, revokedCerts []pkix.RevokedCertificate, now, expiry time.Time) (crlBytes []byte, err error)
- func (c Certificate) Verify(opts VerifyOptions) (chains [][]Certificate, err error)
- type CertificateInvalidError
- type CertificateRequest
- type HostnameError
- type InsecureAlgorithmError
- type InvalidReason
- type PEMCipher
Package files
pem_decrypt.go pkcs8.go root_linux.go sec1.go x509.go
Variables
ErrUnsupportedAlgorithm results from attempting to perform an operation that
involves algorithms that are not currently implemented.
- var IncorrectPasswordError = .New("x509: decryption password incorrect")
IncorrectPasswordError is returned when an incorrect password is detected.
func
¶
CreateCertificate creates a new X.509v3 certificate based on a template. The
following members of template are used: AuthorityKeyId, BasicConstraintsValid,
DNSNames, ExcludedDNSDomains, ExtKeyUsage, IsCA, KeyUsage, MaxPathLen,
MaxPathLenZero, NotAfter, NotBefore, PermittedDNSDomains,
PermittedDNSDomainsCritical, SerialNumber, SignatureAlgorithm, Subject,
SubjectKeyId, and UnknownExtKeyUsage.
The certificate is signed by parent. If parent is equal to template then the
certificate is self-signed. The parameter pub is the public key of the signee
and priv is the private key of the signer.
The returned slice is the certificate in DER encoding.
All keys types that are implemented via crypto.Signer are supported (This
includes rsa.PublicKey and ecdsa.PublicKey.)
The AuthorityKeyId will be taken from the SubjectKeyId of parent, if any, unless
the resulting certificate is self-signed. Otherwise the value from template will
be used.
func CreateCertificateRequest
- func CreateCertificateRequest(rand io., template *CertificateRequest, priv interface{}) (csr [], err error)
CreateCertificateRequest creates a new certificate request based on a template.
The following members of template are used: Attributes, DNSNames,
EmailAddresses, ExtraExtensions, IPAddresses, URIs, SignatureAlgorithm, and
Subject. The private key is the private key of the signer.
The returned slice is the certificate request in DER encoding.
All keys types that are implemented via crypto.Signer are supported (This
includes rsa.PublicKey and ecdsa.PublicKey.)
func
¶
DecryptPEMBlock takes a password encrypted PEM block and the password used to
encrypt it and returns a slice of decrypted DER encoded bytes. It inspects the
DEK-Info header to determine the algorithm used for decryption. If no DEK-Info
header is present, an error is returned. If an incorrect password is detected an
IncorrectPasswordError is returned. Because of deficiencies in the encrypted-PEM
format, it’s not always possible to detect an incorrect password. In these cases
no error will be returned but the decrypted DER bytes will be random noise.
func EncryptPEMBlock
EncryptPEMBlock returns a PEM block of the specified type holding the given
DER-encoded data encrypted with the specified algorithm and password.
func IsEncryptedPEMBlock
IsEncryptedPEMBlock returns if the PEM block is password encrypted.
func
¶
- func MarshalECPrivateKey(key *.PrivateKey) ([], error)
MarshalECPrivateKey marshals an EC private key into ASN.1, DER format.
func
¶
- func MarshalPKCS1PrivateKey(key *.PrivateKey) []
MarshalPKCS1PrivateKey converts a private key to ASN.1 DER encoded form.
func MarshalPKCS1PublicKey
MarshalPKCS1PublicKey converts an RSA public key to PKCS#1, ASN.1 DER form.
func
¶
- func MarshalPKCS8PrivateKey(key interface{}) ([], error)
MarshalPKCS8PrivateKey converts a private key to PKCS#8 encoded form. The
following key types are supported: rsa.PrivateKey, ecdsa.PublicKey.
Unsupported key types result in an error.
See RFC 5208.
- func MarshalPKIXPublicKey(pub interface{}) ([], error)
MarshalPKIXPublicKey serialises a public key to DER-encoded PKIX format.
func
¶
ParseCRL parses a CRL from the given bytes. It’s often the case that PEM encoded
CRLs will appear where they should be DER encoded, so this function will
transparently handle PEM encoding as long as there isn’t any leading garbage.
func
¶
- func ParseCertificates(asn1Data []) ([]*Certificate, )
ParseCertificates parses one or more certificates from the given ASN.1 DER data.
The certificates must be concatenated with no intermediate padding.
func ParseDERCRL
- func ParseDERCRL(derBytes []byte) (*.CertificateList, )
ParseDERCRL parses a DER encoded CRL from the given bytes.
func ParseECPrivateKey
- func ParseECPrivateKey(der []byte) (*.PrivateKey, )
ParseECPrivateKey parses an ASN.1 Elliptic Curve Private Key Structure.
func ParsePKCS1PrivateKey
- func ParsePKCS1PrivateKey(der []byte) (*.PrivateKey, )
ParsePKCS1PrivateKey returns an RSA private key from its ASN.1 PKCS#1 DER
encoded form.
func ParsePKCS1PublicKey
ParsePKCS1PublicKey parses a PKCS#1 public key in ASN.1 DER form.
func ParsePKCS8PrivateKey
- func ParsePKCS8PrivateKey(der []byte) (key interface{}, err )
ParsePKCS8PrivateKey parses an unencrypted, PKCS#8 private key. See RFC 5208.
func ParsePKIXPublicKey
- func ParsePKIXPublicKey(derBytes []byte) (pub interface{}, err )
ParsePKIXPublicKey parses a DER encoded public key. These values are typically
found in PEM blocks with “BEGIN PUBLIC KEY”.
Supported key types include RSA, DSA, and ECDSA. Unknown key types result in an
error.
On success, pub will be of type rsa.PublicKey, dsa.PublicKey, or
*ecdsa.PublicKey.
const pubPEM = `
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAlRuRnThUjU8/prwYxbty
WPT9pURI3lbsKMiB6Fn/VHOKE13p4D8xgOCADpdRagdT6n4etr9atzDKUSvpMtR3
CP5noNc97WiNCggBjVWhs7szEe8ugyqF23XwpHQ6uV1LKH50m92MbOWfCtjU9p/x
qhNpQQ1AZhqNy5Gevap5k8XzRmjSldNAFZMY7Yv3Gi+nyCwGwpVtBUwhuLzgNFK/
yDtw2WcWmUU7NuC8Q6MWvPebxVtCfVp/iQU6q60yyt6aGOBkhAX0LpKAEhKidixY
nP9PNVBvxgu3XZ4P36gZV6+ummKdBVnc3NqwBLu5+CcdRdusmHPHd5pHf4/38Z3/
6qU2a/fPvWzceVTEgZ47QjFMTCTmCwNt29cvi7zZeQzjtwQgn4ipN9NibRH/Ax/q
TbIzHfrJ1xa2RteWSdFjwtxi9C20HUkjXSeI4YlzQMH0fPX6KCE7aVePTOnB69I/
a9/q96DiXZajwlpq3wFctrs1oXqBp5DVrCIj8hU2wNgB7LtQ1mCtsYz//heai0K9
PhE4X6hiE0YmeAZjR0uHl8M/5aW9xCoJ72+12kKpWAa0SFRWLy6FejNYCYpkupVJ
yecLk/4L1W0l6jQQZnWErXZYe0PNFcmwGXy1Rep83kfBRNKRy5tvocalLlwXLdUk
AIU+2GKjyT3iMuzZxxFxPFMCAwEAAQ==
-----END PUBLIC KEY-----`
block, _ := pem.Decode([]byte(pubPEM))
if block == nil {
panic("failed to parse PEM block containing the public key")
}
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
panic("failed to parse DER encoded public key: " + err.Error())
}
switch pub := pub.(type) {
case *rsa.PublicKey:
fmt.Println("pub is of type RSA:", pub)
case *dsa.PublicKey:
fmt.Println("pub is of type DSA:", pub)
case *ecdsa.PublicKey:
fmt.Println("pub is of type ECDSA:", pub)
default:
panic("unknown type of public key")
}
type
¶
- type CertPool struct {
- // contains filtered or unexported fields
- }
CertPool is a set of certificates.
func
¶
- func NewCertPool() *
NewCertPool returns a new, empty CertPool.
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.
func (*CertPool) AddCert
- func (s *CertPool) AddCert(cert *)
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.
func (*CertPool)
¶
- func (s *) Subjects() [][]byte
Subjects returns a list of the DER-encoded subjects of all of the certificates
in the pool.
type
¶
- type Certificate struct {
- Raw [] // Complete ASN.1 DER content (certificate, signature algorithm and signature).
- RawTBSCertificate []byte // Certificate part of raw ASN.1 DER content.
- RawSubjectPublicKeyInfo [] // DER encoded SubjectPublicKeyInfo.
- RawSubject []byte // DER encoded Subject
- RawIssuer [] // DER encoded Issuer
- Signature []byte
- SignatureAlgorithm
- PublicKeyAlgorithm PublicKeyAlgorithm
- PublicKey interface{}
- Version
- SerialNumber *big.
- Issuer pkix.
- Subject pkix.
- NotBefore, NotAfter time. // Validity bounds.
- KeyUsage KeyUsage
- // Extensions contains raw X.509 extensions. When parsing certificates,
- // this can be used to extract non-critical extensions that are not
- // parsed by this package. When marshaling certificates, the Extensions
- // field is ignored, see ExtraExtensions.
- Extensions [].Extension
- // ExtraExtensions contains extensions to be copied, raw, into any
- // marshaled certificates. Values override any extensions that would
- // otherwise be produced based on the other fields. The ExtraExtensions
- // field is not populated when parsing certificates, see Extensions.
- ExtraExtensions [].Extension
- // UnhandledCriticalExtensions contains a list of extension IDs that
- // were not (fully) processed when parsing. Verify will fail if this
- // slice is non-empty, unless verification is delegated to an OS
- // library which understands all the critical extensions.
- // Users can access these extensions using Extensions and can remove
- // elements from this slice if they believe that they have been
- // handled.
- UnhandledCriticalExtensions [].ObjectIdentifier
- ExtKeyUsage [] // Sequence of extended key usages.
- UnknownExtKeyUsage []asn1. // Encountered extended key usages unknown to this package.
- // BasicConstraintsValid indicates whether IsCA, MaxPathLen,
- // and MaxPathLenZero are valid.
- BasicConstraintsValid bool
- IsCA
- // MaxPathLen and MaxPathLenZero indicate the presence and
- // value of the BasicConstraints' "pathLenConstraint".
- //
- // When parsing a certificate, a positive non-zero MaxPathLen
- // means that the field was specified, -1 means it was unset,
- // and MaxPathLenZero being true mean that the field was
- // explicitly set to zero. The case of MaxPathLen==0 with MaxPathLenZero==false
- // should be treated equivalent to -1 (unset).
- //
- // When generating a certificate, an unset pathLenConstraint
- // can be requested with either MaxPathLen == -1 or using the
- // zero value for both MaxPathLen and MaxPathLenZero.
- MaxPathLen int
- // MaxPathLenZero indicates that BasicConstraintsValid==true
- // and MaxPathLen==0 should be interpreted as an actual
- // maximum path length of zero. Otherwise, that combination is
- // interpreted as MaxPathLen not being set.
- MaxPathLenZero
- SubjectKeyId []byte
- AuthorityKeyId []
- // RFC 5280, 4.2.2.1 (Authority Information Access)
- OCSPServer []string
- IssuingCertificateURL []
- // Subject Alternate Name values
- DNSNames []string
- EmailAddresses []
- IPAddresses []net.
- URIs []*url.
- // Name constraints
- PermittedDNSDomainsCritical bool // if true then the name constraints are marked critical.
- PermittedDNSDomains []
- ExcludedDNSDomains []string
- PermittedIPRanges []*.IPNet
- ExcludedIPRanges []*.IPNet
- PermittedEmailAddresses []
- ExcludedEmailAddresses []string
- PermittedURIDomains []
- ExcludedURIDomains []string
- // CRL Distribution Points
- CRLDistributionPoints []
- PolicyIdentifiers []asn1.
- }
A Certificate represents an X.509 certificate.
func ParseCertificate
ParseCertificate parses a single certificate from the given ASN.1 DER data.
CheckCRLSignature checks that the signature in crl is from c.
func (*Certificate)
¶
- func (c *) CheckSignature(algo SignatureAlgorithm, signed, signature []) error
CheckSignature verifies that signature is a valid signature over signed from c’s
public key.
func (*Certificate)
¶
- func (c *) CheckSignatureFrom(parent *Certificate)
CheckSignatureFrom verifies that the signature on c is a valid signature from
parent.
func (*Certificate) CreateCRL
- func (c *Certificate) CreateCRL(rand .Reader, priv interface{}, revokedCerts [].RevokedCertificate, now, expiry .Time) (crlBytes [], err error)
CreateCRL returns a DER encoded CRL, signed by this Certificate, that contains
the given list of revoked certificates.
func (*Certificate)
¶
- func (c *) Equal(other *Certificate)
func (*Certificate) Verify
- func (c *Certificate) Verify(opts ) (chains [][]*Certificate, err )
Verify attempts to verify c by building one or more chains from c to a
certificate in opts.Roots, using certificates in opts.Intermediates if needed.
If successful, it returns one or more chains where the first element of the
chain is c and the last element is from opts.Roots.
If opts.Roots is nil and system roots are unavailable the returned error will be
of type SystemRootsError.
Name constraints in the intermediates will be applied to all names claimed in
the chain, not just opts.DNSName. Thus it is invalid for a leaf to claim
example.com if an intermediate doesn’t permit it, even if example.com is not the
name being validated. Note that DirectoryName constraints are not supported.
Extended Key Usage values are enforced down a chain, so an intermediate or root
that enumerates EKUs prevents a leaf from asserting an EKU not in that list.
WARNING: this function doesn’t do any revocation checking.
// Verifying with a custom list of root certificates.
const rootPEM = `
-----BEGIN CERTIFICATE-----
MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
YWwgQ0EwHhcNMTMwNDA1MTUxNTU1WhcNMTUwNDA0MTUxNTU1WjBJMQswCQYDVQQG
EwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzElMCMGA1UEAxMcR29vZ2xlIEludGVy
bmV0IEF1dGhvcml0eSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AJwqBHdc2FCROgajguDYUEi8iT/xGXAaiEZ+4I/F8YnOIe5a/mENtzJEiaB0C1NP
VaTOgmKV7utZX8bhBYASxF6UP7xbSDj0U/ck5vuR6RXEz/RTDfRK/J9U3n2+oGtv
h8DQUB8oMANA2ghzUWx//zo8pzcGjr1LEQTrfSTe5vn8MXH7lNVg8y5Kr0LSy+rE
ahqyzFPdFUuLH8gZYR/Nnag+YyuENWllhMgZxUYi+FOVvuOAShDGKuy6lyARxzmZ
EASg8GF6lSWMTlJ14rbtCMoU/M4iarNOz0YDl5cDfsCx3nuvRTPPuj5xt970JSXC
DTWJnZ37DhF5iR43xa+OcmkCAwEAAaOB+zCB+DAfBgNVHSMEGDAWgBTAephojYn7
qwVkDBF9qn1luMrMTjAdBgNVHQ4EFgQUSt0GFhu89mi1dvWBtrtiGrpagS8wEgYD
VR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAQYwOgYDVR0fBDMwMTAvoC2g
K4YpaHR0cDovL2NybC5nZW90cnVzdC5jb20vY3Jscy9ndGdsb2JhbC5jcmwwPQYI
KwYBBQUHAQEEMTAvMC0GCCsGAQUFBzABhiFodHRwOi8vZ3RnbG9iYWwtb2NzcC5n
ZW90cnVzdC5jb20wFwYDVR0gBBAwDjAMBgorBgEEAdZ5AgUBMA0GCSqGSIb3DQEB
BQUAA4IBAQA21waAESetKhSbOHezI6B1WLuxfoNCunLaHtiONgaX4PCVOzf9G0JY
/iLIa704XtE7JW4S615ndkZAkNoUyHgN7ZVm2o6Gb4ChulYylYbc3GrKBIxbf/a/
zG+FA1jDaFETzf3I93k9mTXwVqO94FntT0QJo544evZG0R0SnU++0ED8Vf4GXjza
HFa9llF7b1cq26KqltyMdMKVvvBulRP/F/A8rLIQjcxz++iPAsbw+zOzlTvjwsto
WHPbqCRiOwY1nQ2pM714A5AuTHhdUDqB1O6gyHA43LL5Z/qHQF1hwFGPa4NrzQU6
yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx
-----END CERTIFICATE-----`
const certPEM = `
-----BEGIN CERTIFICATE-----
MIIDujCCAqKgAwIBAgIIE31FZVaPXTUwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
cm5ldCBBdXRob3JpdHkgRzIwHhcNMTQwMTI5MTMyNzQzWhcNMTQwNTI5MDAwMDAw
WjBpMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEYMBYGA1UEAwwPbWFp
bC5nb29nbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEfRrObuSW5T7q
5CnSEqefEmtH4CCv6+5EckuriNr1CjfVvqzwfAhopXkLrq45EQm8vkmf7W96XJhC
7ZM0dYi1/qOCAU8wggFLMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAa
BgNVHREEEzARgg9tYWlsLmdvb2dsZS5jb20wCwYDVR0PBAQDAgeAMGgGCCsGAQUF
LmNydDArBggrBgEFBQcwAYYfaHR0cDovL2NsaWVudHMxLmdvb2dsZS5jb20vb2Nz
cDAdBgNVHQ4EFgQUiJxtimAuTfwb+aUtBn5UYKreKvMwDAYDVR0TAQH/BAIwADAf
BgNVHSMEGDAWgBRK3QYWG7z2aLV29YG2u2IaulqBLzAXBgNVHSAEEDAOMAwGCisG
AQQB1nkCBQEwMAYDVR0fBCkwJzAloCOgIYYfaHR0cDovL3BraS5nb29nbGUuY29t
L0dJQUcyLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAH6RYHxHdcGpMpFE3oxDoFnP+
gtuBCHan2yE2GRbJ2Cw8Lw0MmuKqHlf9RSeYfd3BXeKkj1qO6TVKwCh+0HdZk283
TZZyzmEOyclm3UGFYe82P/iDFt+CeQ3NpmBg+GoaVCuWAARJN/KfglbLyyYygcQq
0SgeDh8dRKUiaW3HQSoYvTvdTuqzwK4CXsr3b5/dAOY8uMuG/IAR3FgwTbZ1dtoW
RvOTa8hYiU6A475WuZKyEHcwnGYe57u2I2KbMgcKjPniocj4QzgYsVAVKW3IwaOh
yE+vPxsiUkvQHdO2fojCkY8jg70jxM+gu59tPDNbw3Uh/2Ij310FgTHsnGQMyA==
-----END CERTIFICATE-----`
// First, create the set of root certificates. For this example we only
// have one. It's also possible to omit this in order to use the
// default root set of the current operating system.
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM([]byte(rootPEM))
if !ok {
panic("failed to parse root certificate")
}
block, _ := pem.Decode([]byte(certPEM))
if block == nil {
panic("failed to parse certificate PEM")
}
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
panic("failed to parse certificate: " + err.Error())
}
opts := x509.VerifyOptions{
DNSName: "mail.google.com",
Roots: roots,
}
if _, err := cert.Verify(opts); err != nil {
panic("failed to verify certificate: " + err.Error())
func (*Certificate)
¶
- func (c *) VerifyHostname(h string)
VerifyHostname returns nil if c is a valid certificate for the named host.
Otherwise it returns an error describing the mismatch.
type CertificateInvalidError
- type CertificateInvalidError struct {
- Cert *Certificate
- Reason
- Detail string
- }
func (CertificateInvalidError)
¶
- func (e ) Error() string
type
¶
- type CertificateRequest struct {
- Raw [] // Complete ASN.1 DER content (CSR, signature algorithm and signature).
- RawTBSCertificateRequest []byte // Certificate request info part of raw ASN.1 DER content.
- RawSubjectPublicKeyInfo [] // DER encoded SubjectPublicKeyInfo.
- RawSubject []byte // DER encoded Subject.
- Version
- Signature []byte
- SignatureAlgorithm
- PublicKeyAlgorithm PublicKeyAlgorithm
- PublicKey interface{}
- Subject .Name
- // Attributes is the dried husk of a bug and shouldn't be used.
- Attributes [].AttributeTypeAndValueSET
- // Extensions contains raw X.509 extensions. When parsing CSRs, this
- // can be used to extract extensions that are not parsed by this
- // package.
- Extensions [].Extension
- // ExtraExtensions contains extensions to be copied, raw, into any
- // marshaled CSR. Values override any extensions that would otherwise
- // be produced based on the other fields but are overridden by any
- // extensions specified in Attributes.
- //
- // The ExtraExtensions field is not populated when parsing CSRs, see
- // Extensions.
- ExtraExtensions [].Extension
- // Subject Alternate Name values.
- DNSNames []
- EmailAddresses []string
- IPAddresses [].IP
- URIs []*.URL
- }
CertificateRequest represents a PKCS #10, certificate signature request.
- func ParseCertificateRequest(asn1Data []) (*CertificateRequest, )
ParseCertificateRequest parses a single certificate request from the given ASN.1
DER data.
func (*CertificateRequest) CheckSignature
- func (c *CertificateRequest) CheckSignature()
CheckSignature reports whether the signature on c is valid.
- type ConstraintViolationError struct{}
ConstraintViolationError results when a requested usage is not permitted by a
certificate. For example: checking a signature when the public key isn’t a
certificate signing key.
func (ConstraintViolationError) Error
- func (ConstraintViolationError) Error()
type ExtKeyUsage
- type ExtKeyUsage int
ExtKeyUsage represents an extended set of actions that are valid for a given
key. Each of the ExtKeyUsage* constants define a unique action.
- const (
- ExtKeyUsageAny = iota
- ExtKeyUsageServerAuth
- ExtKeyUsageClientAuth
- ExtKeyUsageCodeSigning
- ExtKeyUsageEmailProtection
- ExtKeyUsageIPSECEndSystem
- ExtKeyUsageIPSECTunnel
- ExtKeyUsageIPSECUser
- ExtKeyUsageTimeStamping
- ExtKeyUsageOCSPSigning
- ExtKeyUsageMicrosoftServerGatedCrypto
- ExtKeyUsageNetscapeServerGatedCrypto
- ExtKeyUsageMicrosoftCommercialCodeSigning
- ExtKeyUsageMicrosoftKernelCodeSigning
- )
type
¶
HostnameError results when the set of authorized names doesn’t match the
requested name.
func (HostnameError)
¶
- func (h ) Error() string
type
¶
- type InsecureAlgorithmError
An InsecureAlgorithmError
func (InsecureAlgorithmError) Error
- func (e InsecureAlgorithmError) Error()
type InvalidReason
- type InvalidReason int
- const (
- // NotAuthorizedToSign results when a certificate is signed by another
- // which isn't marked as a CA certificate.
- NotAuthorizedToSign = iota
- // Expired results when a certificate has expired, based on the time
- // given in the VerifyOptions.
- Expired
- // CANotAuthorizedForThisName results when an intermediate or root
- // certificate has a name constraint which doesn't permit a DNS or
- // other name (including IP address) in the leaf certificate.
- CANotAuthorizedForThisName
- // TooManyIntermediates results when a path length constraint is
- // violated.
- TooManyIntermediates
- // IncompatibleUsage results when the certificate's key usage indicates
- // that it may only be used for a different purpose.
- IncompatibleUsage
- // NameMismatch results when the subject name of a parent certificate
- // does not match the issuer name in the child.
- NameMismatch
- // NameConstraintsWithoutSANs results when a leaf certificate doesn't
- // contain a Subject Alternative Name extension, but a CA certificate
- // contains name constraints.
- NameConstraintsWithoutSANs
- // UnconstrainedName results when a CA certificate contains permitted
- // name constraints, but leaf certificate contains a name of an
- // unsupported or unconstrained type.
- UnconstrainedName
- // TooManyConstraints results when the number of comparision operations
- // needed to check a certificate exceeds the limit set by
- // VerifyOptions.MaxConstraintComparisions. This limit exists to
- // prevent pathological certificates can consuming excessive amounts of
- // CPU time to verify.
- TooManyConstraints
- // CANotAuthorizedForExtKeyUsage results when an intermediate or root
- // certificate does not permit an extended key usage that is claimed by
- // the leaf certificate.
- CANotAuthorizedForExtKeyUsage
- )
type
¶
- type KeyUsage
KeyUsage represents the set of actions that are valid for a given key. It’s a
bitmap of the KeyUsage* constants.
- const (
- KeyUsageDigitalSignature KeyUsage = 1 <<
- KeyUsageContentCommitment
- KeyUsageKeyEncipherment
- KeyUsageDataEncipherment
- KeyUsageKeyAgreement
- KeyUsageCertSign
- KeyUsageCRLSign
- KeyUsageEncipherOnly
- KeyUsageDecipherOnly
- )
type PEMCipher
- type PEMCipher int
- const (
- PEMCipherDES
- PEMCipher3DES
- PEMCipherAES128
- PEMCipherAES192
- PEMCipherAES256
- )
Possible values for the EncryptPEMBlock encryption algorithm.
type PublicKeyAlgorithm
- type PublicKeyAlgorithm int
- const (
- UnknownPublicKeyAlgorithm = iota
- RSA
- DSA
- ECDSA
- )
func (PublicKeyAlgorithm)
¶
- func (algo ) String() string
type
¶
- type SignatureAlgorithm
- const (
- UnknownSignatureAlgorithm SignatureAlgorithm =
- MD2WithRSA
- MD5WithRSA
- SHA1WithRSA
- SHA256WithRSA
- SHA384WithRSA
- SHA512WithRSA
- DSAWithSHA1
- DSAWithSHA256
- ECDSAWithSHA1
- ECDSAWithSHA256
- ECDSAWithSHA384
- ECDSAWithSHA512
- SHA256WithRSAPSS
- SHA384WithRSAPSS
- SHA512WithRSAPSS
- )
func (SignatureAlgorithm) String
- func (algo SignatureAlgorithm) String()
type SystemRootsError
- type SystemRootsError struct {
- Err error
- }
SystemRootsError results when we fail to load the system root certificates.
func (SystemRootsError)
¶
- func (se ) Error() string
type
¶
- type UnhandledCriticalExtension struct{}
- func (h ) Error() string
type
¶
- type UnknownAuthorityError struct {
- Cert *
- // contains filtered or unexported fields
- }
UnknownAuthorityError results when the certificate issuer is unknown
func (UnknownAuthorityError) Error
- func (e UnknownAuthorityError) Error()
type VerifyOptions
- type VerifyOptions struct {
- DNSName string
- Intermediates *
- Roots *CertPool // if nil, the system roots are used
- CurrentTime .Time // if zero, the current time is used
- // KeyUsage specifies which Extended Key Usage values are acceptable.
- // An empty list means ExtKeyUsageServerAuth. Key usage is considered a
- // constraint down the chain which mirrors Windows CryptoAPI behavior,
- // but not the spec. To accept any key usage, include ExtKeyUsageAny.
- KeyUsages []
- // MaxConstraintComparisions is the maximum number of comparisons to
- // perform when checking a given certificate's name constraints. If
- // zero, a sensible default is used. This limit prevents pathalogical
- // certificates from consuming excessive amounts of CPU time when
- // validating.
- MaxConstraintComparisions int
- }