Documentation ¶
Index ¶
- Constants
- func CheckSignature(csr *x509.CertificateRequest, algo x509.SignatureAlgorithm, ...) error
- func CheckSignatureFrom(c *x509.Certificate, parent *x509.Certificate) error
- func CreateCertificate(rand io.Reader, template, parent *x509.Certificate, pub, priv interface{}) (cert []byte, err error)
- func CreateCertificateRequest(rand io.Reader, template *x509.CertificateRequest, priv interface{}) (csr []byte, err error)
- func DefaultSigAlgo(priv crypto.Signer) x509.SignatureAlgorithm
- func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte
- func MarshalPKIXPublicKey(pub interface{}) ([]byte, error)
- func ParseCertificate(asn1Data []byte) (*x509.Certificate, error)
- func ParseCertificateRequest(asn1Data []byte) (*x509.CertificateRequest, error)
- func ParsePKCS1PrivateKey(der []byte) (*rsa.PrivateKey, error)
- func ParsePKCS8PrivateKey(der []byte) (key interface{}, err error)
- func ParsePKIXPublicKey(derBytes []byte) (pub interface{}, err error)
- func ParseSM2PrivateKey(der []byte) (*sm2.PrivateKey, error)
- func SignerAlgo(priv crypto.Signer) x509.SignatureAlgorithm
- func Verify(c *x509.Certificate, opts VerifyOptions) (chains [][]*x509.Certificate, err error)
- type CertPool
- type CertificateInvalidError
- type InvalidReason
- type UnknownAuthorityError
- type VerifyOptions
Constants ¶
const ( UnknownSignatureAlgorithm x509.SignatureAlgorithm = iota + 20 SHA256WithSM2 )
const ( UnknownPublicKeyAlgorithm x509.PublicKeyAlgorithm = iota + 5 SM2 )
Variables ¶
This section is empty.
Functions ¶
func CheckSignature ¶
func CheckSignature(csr *x509.CertificateRequest, algo x509.SignatureAlgorithm, signed, signature []byte) error
CheckSignature verifies a signature made by the key on a CSR, such as on the CSR itself.
func CheckSignatureFrom ¶
func CheckSignatureFrom(c *x509.Certificate, parent *x509.Certificate) error
CheckSignatureFrom verifies that the signature on c is a valid signature from parent.
func CreateCertificate ¶
func CreateCertificate(rand io.Reader, template, parent *x509.Certificate, pub, priv interface{}) (cert []byte, err error)
CreateCertificate creates a new certificate based on a template. The following members of template are used: SerialNumber, Subject, NotBefore, NotAfter, KeyUsage, ExtKeyUsage, UnknownExtKeyUsage, BasicConstraintsValid, IsCA, MaxPathLen, SubjectKeyId, DNSNames, PermittedDNSDomainsCritical, PermittedDNSDomains, SignatureAlgorithm.
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.)
func CreateCertificateRequest ¶
func CreateCertificateRequest(rand io.Reader, template *x509.CertificateRequest, priv interface{}) (csr []byte, err error)
CreateCertificateRequest creates a new certificate request based on a template. The following members of template are used: Subject, Attributes, SignatureAlgorithm, Extensions, DNSNames, EmailAddresses, and IPAddresses. 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 DefaultSigAlgo ¶
func DefaultSigAlgo(priv crypto.Signer) x509.SignatureAlgorithm
func MarshalPKCS1PrivateKey ¶
func MarshalPKCS1PrivateKey(key *rsa.PrivateKey) []byte
MarshalPKCS1PrivateKey converts a private key to ASN.1 DER encoded form.
func MarshalPKIXPublicKey ¶
func ParseCertificate ¶
func ParseCertificate(asn1Data []byte) (*x509.Certificate, error)
func ParseCertificateRequest ¶
func ParseCertificateRequest(asn1Data []byte) (*x509.CertificateRequest, error)
ParseCertificateRequest parses a single certificate request from the given ASN.1 DER data.
func ParsePKCS1PrivateKey ¶
func ParsePKCS1PrivateKey(der []byte) (*rsa.PrivateKey, error)
ParsePKCS1PrivateKey returns an RSA private key from its ASN.1 PKCS#1 DER encoded form.
func ParsePKCS8PrivateKey ¶
ParsePKCS8PrivateKey parses an unencrypted, PKCS#8 private key. See RFC 5208.
func ParsePKIXPublicKey ¶
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.
func ParseSM2PrivateKey ¶
func ParseSM2PrivateKey(der []byte) (*sm2.PrivateKey, error)
func SignerAlgo ¶
func SignerAlgo(priv crypto.Signer) x509.SignatureAlgorithm
SignerAlgo returns an X.509 signature algorithm from a crypto.Signer.
func Verify ¶
func Verify(c *x509.Certificate, opts VerifyOptions) (chains [][]*x509.Certificate, err 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 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.
WARNING: this doesn't do any revocation checking.
Types ¶
type CertPool ¶
type CertPool struct {
// contains filtered or unexported fields
}
CertPool is a set of certificates.
func (*CertPool) AddCert ¶
func (s *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 CertificateInvalidError ¶
type CertificateInvalidError struct { Cert *x509.Certificate Reason InvalidReason }
func (CertificateInvalidError) Error ¶
func (e CertificateInvalidError) Error() 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 // 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 )
type UnknownAuthorityError ¶
type UnknownAuthorityError struct { Cert *x509.Certificate // contains filtered or unexported fields }
func (UnknownAuthorityError) Error ¶
func (e UnknownAuthorityError) Error() string
type VerifyOptions ¶
type VerifyOptions struct { DNSName string Intermediates *CertPool Roots *CertPool // if nil, the system roots are used CurrentTime time.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 []x509.ExtKeyUsage }