Documentation ¶
Overview ¶
Package x509 parses X.509-encoded keys and certificates.
Index ¶
- func CreateCertificate(rand io.Reader, template, parent *Certificate, pub *rsa.PublicKey, ...) (cert []byte, err os.Error)
- func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte
- func ParseCRL(crlBytes []byte) (certList *pkix.CertificateList, err os.Error)
- func ParseDERCRL(derBytes []byte) (certList *pkix.CertificateList, err os.Error)
- func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err os.Error)
- type CertPool
- type Certificate
- func (c *Certificate) CheckCRLSignature(crl *pkix.CertificateList) (err os.Error)
- func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature []byte) (err os.Error)
- func (c *Certificate) CheckSignatureFrom(parent *Certificate) (err os.Error)
- func (c *Certificate) CreateCRL(rand io.Reader, priv *rsa.PrivateKey, revokedCerts []pkix.RevokedCertificate, ...) (crlBytes []byte, err os.Error)
- func (c *Certificate) Equal(other *Certificate) bool
- func (c *Certificate) Verify(opts VerifyOptions) (chains [][]*Certificate, err os.Error)
- func (c *Certificate) VerifyHostname(h string) os.Error
- type CertificateInvalidError
- type ConstraintViolationError
- type ExtKeyUsage
- type HostnameError
- type InvalidReason
- type KeyUsage
- type PublicKeyAlgorithm
- type SignatureAlgorithm
- type UnhandledCriticalExtension
- type UnknownAuthorityError
- type UnsupportedAlgorithmError
- type VerifyOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateCertificate ¶
func CreateCertificate(rand io.Reader, template, parent *Certificate, pub *rsa.PublicKey, priv *rsa.PrivateKey) (cert []byte, err os.Error)
CreateSelfSignedCertificate creates a new certificate based on a template. The following members of template are used: SerialNumber, Subject, NotBefore, NotAfter, KeyUsage, BasicConstraintsValid, IsCA, MaxPathLen, SubjectKeyId, DNSNames, PermittedDNSDomainsCritical, PermittedDNSDomains.
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.
func MarshalPKCS1PrivateKey ¶
func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte
MarshalPKCS1PrivateKey converts a private key to ASN.1 DER encoded form.
func ParseCRL ¶
func ParseCRL(crlBytes []byte) (certList *pkix.CertificateList, err os.Error)
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 ParseDERCRL ¶
func ParseDERCRL(derBytes []byte) (certList *pkix.CertificateList, err os.Error)
ParseDERCRL parses a DER encoded CRL from the given bytes.
func ParsePKCS1PrivateKey ¶
func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err os.Error)
ParsePKCS1PrivateKey returns an RSA private key from its ASN.1 PKCS#1 DER encoded form.
Types ¶
type CertPool ¶
type CertPool struct {
// contains filtered or unexported fields
}
Roots is a set of certificates.
func (*CertPool) AddCert ¶
func (s *CertPool) AddCert(cert *Certificate)
AddCert adds a certificate to a pool.
func (*CertPool) AppendCertsFromPEM ¶
AppendCertsFromPEM attempts to parse a series of PEM encoded root certificates. It appends any certificates found to s and returns true if any certificates were successfully parsed.
On many Linux systems, /etc/ssl/cert.pem will contains the system wide set of root CAs in a format suitable for this function.
type Certificate ¶
type Certificate struct { Raw []byte // Complete ASN.1 DER content (certificate, signature algorithm and signature). RawTBSCertificate []byte // Certificate part of raw ASN.1 DER content. RawSubjectPublicKeyInfo []byte // DER encoded SubjectPublicKeyInfo. Signature []byte SignatureAlgorithm SignatureAlgorithm PublicKeyAlgorithm PublicKeyAlgorithm PublicKey interface{} Version int SerialNumber *big.Int Issuer pkix.Name Subject pkix.Name NotBefore, NotAfter *time.Time // Validity bounds. KeyUsage KeyUsage ExtKeyUsage []ExtKeyUsage // Sequence of extended key usages. UnknownExtKeyUsage []asn1.ObjectIdentifier // Encountered extended key usages unknown to this package. BasicConstraintsValid bool // if true then the next two fields are valid. IsCA bool MaxPathLen int SubjectKeyId []byte AuthorityKeyId []byte // Subject Alternate Name values DNSNames []string EmailAddresses []string // Name constraints PermittedDNSDomainsCritical bool // if true then the name constraints are marked critical. PermittedDNSDomains []string PolicyIdentifiers []asn1.ObjectIdentifier }
A Certificate represents an X.509 certificate.
func ParseCertificate ¶
func ParseCertificate(asn1Data []byte) (*Certificate, os.Error)
ParseCertificate parses a single certificate from the given ASN.1 DER data.
func ParseCertificates ¶
func ParseCertificates(asn1Data []byte) ([]*Certificate, os.Error)
ParseCertificates parses one or more certificates from the given ASN.1 DER data. The certificates must be concatenated with no intermediate padding.
func (*Certificate) CheckCRLSignature ¶
func (c *Certificate) CheckCRLSignature(crl *pkix.CertificateList) (err os.Error)
CheckCRLSignature checks that the signature in crl is from c.
func (*Certificate) CheckSignature ¶
func (c *Certificate) CheckSignature(algo SignatureAlgorithm, signed, signature []byte) (err os.Error)
CheckSignature verifies that signature is a valid signature over signed from c's public key.
func (*Certificate) CheckSignatureFrom ¶
func (c *Certificate) CheckSignatureFrom(parent *Certificate) (err os.Error)
CheckSignatureFrom verifies that the signature on c is a valid signature from parent.
func (*Certificate) CreateCRL ¶
func (c *Certificate) CreateCRL(rand io.Reader, priv *rsa.PrivateKey, revokedCerts []pkix.RevokedCertificate, now, expiry *time.Time) (crlBytes []byte, err os.Error)
CreateCRL returns a DER encoded CRL, signed by this Certificate, that contains the given list of revoked certificates.
func (*Certificate) Equal ¶
func (c *Certificate) Equal(other *Certificate) bool
func (*Certificate) Verify ¶
func (c *Certificate) Verify(opts VerifyOptions) (chains [][]*Certificate, err os.Error)
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 chains where the first element of the chain is c and the last element is from opts.Roots.
WARNING: this doesn't do any revocation checking.
func (*Certificate) VerifyHostname ¶
func (c *Certificate) VerifyHostname(h string) os.Error
VerifyHostname returns nil if c is a valid certificate for the named host. Otherwise it returns an os.Error describing the mismatch.
type CertificateInvalidError ¶
type CertificateInvalidError struct { Cert *Certificate Reason InvalidReason }
CertificateInvalidError results when an odd error occurs. Users of this library probably want to handle all these errors uniformly.
func (CertificateInvalidError) String ¶
func (e CertificateInvalidError) String() string
type ConstraintViolationError ¶
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) String ¶
func (ConstraintViolationError) String() string
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 ExtKeyUsage = iota ExtKeyUsageServerAuth ExtKeyUsageClientAuth ExtKeyUsageCodeSigning ExtKeyUsageEmailProtection ExtKeyUsageTimeStamping ExtKeyUsageOCSPSigning )
type HostnameError ¶
type HostnameError struct { Certificate *Certificate Host string }
HostnameError results when the set of authorized names doesn't match the requested name.
func (HostnameError) String ¶
func (h HostnameError) String() string
type InvalidReason ¶
type InvalidReason int
const ( // NotAuthorizedToSign results when a certificate is signed by another // which isn't marked as a CA certificate. NotAuthorizedToSign InvalidReason = 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 include the name // being checked. CANotAuthorizedForThisName )
type KeyUsage ¶
type KeyUsage int
KeyUsage represents the set of actions that are valid for a given key. It's a bitmap of the KeyUsage* constants.
type PublicKeyAlgorithm ¶
type PublicKeyAlgorithm int
const ( UnknownPublicKeyAlgorithm PublicKeyAlgorithm = iota RSA DSA )
type SignatureAlgorithm ¶
type SignatureAlgorithm int
const ( UnknownSignatureAlgorithm SignatureAlgorithm = iota MD2WithRSA MD5WithRSA SHA1WithRSA SHA256WithRSA SHA384WithRSA SHA512WithRSA DSAWithSHA1 DSAWithSHA256 )
type UnhandledCriticalExtension ¶
type UnhandledCriticalExtension struct{}
func (UnhandledCriticalExtension) String ¶
func (h UnhandledCriticalExtension) String() string
type UnknownAuthorityError ¶
type UnknownAuthorityError struct {
// contains filtered or unexported fields
}
UnknownAuthorityError results when the certificate issuer is unknown
func (UnknownAuthorityError) String ¶
func (e UnknownAuthorityError) String() string
type UnsupportedAlgorithmError ¶
type UnsupportedAlgorithmError struct{}
UnsupportedAlgorithmError results from attempting to perform an operation that involves algorithms that are not currently implemented.
func (UnsupportedAlgorithmError) String ¶
func (UnsupportedAlgorithmError) String() string
type VerifyOptions ¶
type VerifyOptions struct { DNSName string Intermediates *CertPool Roots *CertPool CurrentTime int64 // if 0, the current system time is used. }
VerifyOptions contains parameters for Certificate.Verify. It's a structure because other PKIX verification APIs have ended up needing many options.