Documentation
¶
Index ¶
- Constants
- func NewCertificateRequest(cfg Options, key crypto.Signer) (*x509.CertificateRequest, error)
- func NewCertificateRequestBytes(cfg Options, key crypto.Signer) ([]byte, error)
- func NewECDSAPrivateKey(curve string) (*ecdsa.PrivateKey, error)
- func NewRSAPrivateKey() (*rsa.PrivateKey, error)
- func NewSelfSignedCACert(cfg Options, key crypto.Signer) (*x509.Certificate, error)
- func NewSelfSignedCACertBytes(cfg Options, key crypto.Signer) ([]byte, error)
- func NewSelfSignedCertificate(cfg Options, key crypto.Signer) (*x509.Certificate, error)
- func NewSelfSignedCertificateBytes(cfg Options, key crypto.Signer) ([]byte, error)
- func NewSignedCert(cfg Options, key crypto.Signer, caKey crypto.Signer, caCert *x509.Certificate) (*x509.Certificate, error)
- func ParseCertPEM(pemBytes []byte) (*x509.Certificate, error)
- func ParseCertsPEM(pemBytes []byte) ([]*x509.Certificate, error)
- func ParsePrivateKey(der []byte) (crypto.Signer, error)
- func ParsePrivateKeyPEM(pemBytes []byte) (crypto.Signer, error)
- type Options
- type PEMBlock
- func DecryptPrivateKeyBytes(keyPEMBlock []byte, passwd string) (*PEMBlock, error)
- func DecryptPrivateKeyFile(keyFile, passwd string) (*PEMBlock, error)
- func NewPEM(b *pem.Block) *PEMBlock
- func NewPEMForCSR(csr *x509.CertificateRequest) *PEMBlock
- func NewPEMForCSRDER(derBytes []byte) *PEMBlock
- func NewPEMForCert(crt *x509.Certificate) *PEMBlock
- func NewPEMForCertDER(derBytes []byte) *PEMBlock
- func NewPEMForECDSAKey(key *ecdsa.PrivateKey) *PEMBlock
- func NewPEMForPrivateKey(key crypto.Signer) (*PEMBlock, error)
- func NewPEMForRSAKey(key *rsa.PrivateKey) *PEMBlock
- func ParseFirstPEMBlock(pemBytes []byte) *PEMBlock
- func ParsePEM(pemBytes []byte) []*PEMBlock
- type PkixName
- type TLSCertificate
- func LoadX509KeyPair(certFile, keyFile string) (*TLSCertificate, error)
- func LoadX509KeyPairWithPassword(certFile, keyFile, passwd string) (*TLSCertificate, error)
- func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (*TLSCertificate, error)
- func X509KeyPairWithPassword(certPEMBlock, keyPEMBlock []byte, passwd string) (*TLSCertificate, error)
Constants ¶
const ( // CertificatePEMBlockType is a possible value for pem.Block.Type. CertificatePEMBlockType = "CERTIFICATE" // CertificateRequestPEMBlockType is a possible value for pem.Block.Type. CertificateRequestPEMBlockType = "CERTIFICATE REQUEST" // RASPrivateKeyPEMBlockType is a possible value for pem.Block.Type. RASPrivateKeyPEMBlockType = "RSA PRIVATE KEY" // ECDSAPrivateKeyPEMBlockType is a possible value for pem.Block.Type. ECDSAPrivateKeyPEMBlockType = "EC PRIVATE KEY" )
Variables ¶
This section is empty.
Functions ¶
func NewCertificateRequest ¶
NewCertificateRequest returns a new x509 certificate request
func NewCertificateRequestBytes ¶
NewCertificateRequestBytes returns a new certificate bytes in DER encoding
func NewECDSAPrivateKey ¶
func NewECDSAPrivateKey(curve string) (*ecdsa.PrivateKey, error)
NewECDSAPrivateKey create a new ECDSA provate key by curve
func NewRSAPrivateKey ¶
func NewRSAPrivateKey() (*rsa.PrivateKey, error)
NewRSAPrivateKey creates a new RSA private key
func NewSelfSignedCACert ¶
NewSelfSignedCACert returns a new self-signed CA x509 certificate
All keys types that are implemented via crypto.Signer are supported (This includes *rsa.PrivateKey and *ecdsa.PrivateKey.)
func NewSelfSignedCACertBytes ¶
NewSelfSignedCACertBytes returns a new self-signed CA certificate in DER encoding
All keys types that are implemented via crypto.Signer are supported (This includes *rsa.PrivateKey and *ecdsa.PrivateKey.)
func NewSelfSignedCertificate ¶
NewSelfSignedCertificate returns a new self-signed x509 certificate
All keys types that are implemented via crypto.Signer are supported (This includes *rsa.PrivateKey and *ecdsa.PrivateKey.)
func NewSelfSignedCertificateBytes ¶
NewSelfSignedCertificateBytes returns a new self-signed certificate in DER encoding
All keys types that are implemented via crypto.Signer are supported (This includes *rsa.PrivateKey and *ecdsa.PrivateKey.)
func NewSignedCert ¶
func NewSignedCert(cfg Options, key crypto.Signer, caKey crypto.Signer, caCert *x509.Certificate) (*x509.Certificate, error)
NewSignedCert returns a new certificate signed by given ca key and certificate
All keys types that are implemented via crypto.Signer are supported (This includes *rsa.PrivateKey and *ecdsa.PrivateKey.)
func ParseCertPEM ¶
func ParseCertPEM(pemBytes []byte) (*x509.Certificate, error)
ParseCertPEM decode first valid certificate pem blocks to x509 certificate
func ParseCertsPEM ¶
func ParseCertsPEM(pemBytes []byte) ([]*x509.Certificate, error)
ParseCertsPEM decode all valid certificate pem blocks to x509 certificates
func ParsePrivateKey ¶
ParsePrivateKey attempts to parse the given private key DER block. OpenSSL 0.9.8 generates PKCS#1 private keys by default, while OpenSSL 1.0.0 generates PKCS#8 keys. OpenSSL ecparam generates SEC1 EC private keys for ECDSA. We try all three.
Types ¶
type Options ¶
type Options struct {
CommonName string
Organization []string
DNSNames []string
IPs []net.IP
Usages []x509.ExtKeyUsage
}
Options contains various common Options for creating a certificate
type PEMBlock ¶
PEMBlock contains the raw bytes and a block of pem
func DecryptPrivateKeyBytes ¶
DecryptPrivateKeyBytes 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 DecryptPrivateKeyFile ¶
DecryptPrivateKeyFile takes a password encrypted key file and the password
used to encrypt it and returns a slice of decrypted DER encoded bytes.
func NewPEMForCSR ¶
func NewPEMForCSR(csr *x509.CertificateRequest) *PEMBlock
NewPEMForCSR returns a pemBlock for certificate request
func NewPEMForCSRDER ¶
NewPEMForCSRDER returns a pemBlock for certificate request
func NewPEMForCert ¶
func NewPEMForCert(crt *x509.Certificate) *PEMBlock
NewPEMForCert returns a pemBlock for x509 certificate
func NewPEMForCertDER ¶
NewPEMForCertificate returns a pemBlock for x509 certificate
func NewPEMForECDSAKey ¶
func NewPEMForECDSAKey(key *ecdsa.PrivateKey) *PEMBlock
NewPEMForECDSAKey returns a pemBlock for ecdsa private key
func NewPEMForPrivateKey ¶
NewPEMForPrivateKey returns a pemBlock for crypto private key It returns an error if the key is not *rsa.PrivateKey or *ecdsa.PrivateKey
func NewPEMForRSAKey ¶
func NewPEMForRSAKey(key *rsa.PrivateKey) *PEMBlock
NewPEMForRSAKey returns a pemBlock for ras private key
func ParseFirstPEMBlock ¶
ParsePEM find valid pem block in bytes and decode the first block.
func (*PEMBlock) EncodeToMemory ¶
EncodeToMemory returns the PEM encoding bytes of p.
type PkixName ¶
type PkixName struct {
Organization []string `json:"organization,omitempty"`
// CommonName
CommonName string `json:"commonName,omitempty"`
}
PkixName represents an X.509 distinguished name. This only includes the common elements of a DN. When parsing, all elements are stored in Names and non-standard elements can be extracted from there. When marshaling, elements in ExtraNames are appended and override other values with the same OID.
type TLSCertificate ¶
type TLSCertificate struct {
// certificate is not valid before this time
NotBefore time.Time `json:"notBefore,omitempty"`
// certificate is not valid after this time
NotAfter time.Time `json:"notAfter,omitempty"`
// Issuer information extracted from X.509 cert
Issuer PkixName `json:"issuer,omitempty"`
// Subject information extracted from X.509 cert
Subject PkixName `json:"subject,omitempty"`
// Subject Alternate Name values
DNSNames []string `json:"dnsNames,omitempty"`
IPAddresses []net.IP `json:"ipAddresses,omitempty"`
Cert tls.Certificate `json:"-"`
X509Cert *x509.Certificate `json:"-"`
}
TLSCertificate represents the external cert api secret for https
func LoadX509KeyPair ¶
func LoadX509KeyPair(certFile, keyFile string) (*TLSCertificate, error)
LoadX509KeyPair reads and parses a public/private key pair from a pair of files. The files must contain PEM encoded data.
func LoadX509KeyPairWithPassword ¶
func LoadX509KeyPairWithPassword(certFile, keyFile, passwd string) (*TLSCertificate, error)
LoadX509KeyPairWithPassword parses a encryption public/private key pair from a pair of PEM encoded data.
func X509KeyPair ¶
func X509KeyPair(certPEMBlock, keyPEMBlock []byte) (*TLSCertificate, error)
X509KeyPair parses a public/private key pair from a pair of PEM encoded data.
func X509KeyPairWithPassword ¶
func X509KeyPairWithPassword(certPEMBlock, keyPEMBlock []byte, passwd string) (*TLSCertificate, error)
X509KeyPairWithPassword parses a public/private key pair from a pair of PEM encoded data.