Documentation
¶
Index ¶
- Variables
- func ExportCSR(file string, csr *x509.CertificateRequest) error
- func ExportCert(file string, cert *x509.Certificate) error
- func ExportKeyAndCSR(keyFile, csrFile string, csr *KeyAndCSR) error
- func ExportKeyAndCert(keyFile, certFile string, cert *KeyAndCert) error
- func ExportPrivateKey(file string, priv crypto.PrivateKey) error
- func ExportPublicKey(file string, pub crypto.PublicKey) error
- func GenerateKey(keyType string) (crypto.PrivateKey, error)
- func LoadCSR(file string) (*x509.CertificateRequest, error)
- func LoadCert(file string) (*x509.Certificate, error)
- func LoadKey(file string) (crypto.PrivateKey, error)
- type KeyAndCSR
- type KeyAndCert
- type Request
Constants ¶
This section is empty.
Variables ¶
var ( DefaultKeyType = "rsa-2048" DefaultDuration = 365 * 24 * time.Hour )
Functions ¶
func ExportCSR ¶ added in v0.2.0
func ExportCSR(file string, csr *x509.CertificateRequest) error
ExportCSR saves a certificate request in PEM format from a *x509.CertificateRequest to file.
func ExportCert ¶
func ExportCert(file string, cert *x509.Certificate) error
ExportCert saves a certificate in PEM format from a *x509.Certificate to file.
func ExportKeyAndCSR ¶ added in v0.2.0
ExportKeyAndCSR saves a private key and certficate request from a KeyAndCSR to keyFile and csrFile.
func ExportKeyAndCert ¶ added in v0.2.0
func ExportKeyAndCert(keyFile, certFile string, cert *KeyAndCert) error
ExportKeyAndCert saves a private key and certficate from a KeyAndCert to keyFile and certFile.
func ExportPrivateKey ¶
func ExportPrivateKey(file string, priv crypto.PrivateKey) error
ExportPrivateKey saves a private key in PEM format from a crypto.PrivateKey to file.
func ExportPublicKey ¶
ExportPublicKey saves a public key in PEM format from a crypto.PublicKey to file.
func GenerateKey ¶
func GenerateKey(keyType string) (crypto.PrivateKey, error)
GenerateKey generates a private/public key pair. Valid keytypes are:
rsa-2048, rsa-3072, rsa-4096 ecdsa-224, ecdsa-256, ecdsa-384, ecdsa-521 ed25519
func LoadCSR ¶ added in v0.2.0
func LoadCSR(file string) (*x509.CertificateRequest, error)
LoadCSR loads and parses a certificate request from a PEM-formatted file and returns a *x509.Certificate.
Types ¶
type KeyAndCSR ¶ added in v0.2.0
type KeyAndCSR struct { CertificateRequest *x509.CertificateRequest PrivateKey crypto.PrivateKey PublicKey crypto.PublicKey }
KeyAndCSR represents a bundle of private, public keys and an associated Certificate Request
func LoadKeyAndCSR ¶ added in v0.2.0
LoadKeyAndCSR loads and parses a private key and certificate request from keyFile and csrFile and returns a KeyAndCSR.
type KeyAndCert ¶
type KeyAndCert struct { Certificate *x509.Certificate PrivateKey crypto.PrivateKey PublicKey crypto.PublicKey }
KeyAndCert represents a bundle of private, public keys and an associated Certificate
func LoadKeyAndCert ¶
func LoadKeyAndCert(keyFile string, certFile string) (*KeyAndCert, error)
LoadKeyAndCert loads and parses a private key and certificate from keyFile and certFile and returns a KeyAndCert.
func NewCert ¶
func NewCert(parent *KeyAndCert, req Request) (*KeyAndCert, error)
NewCert creates a new keypair and certificate from a Request object. If parent is nil it will be a self-signed certificate, otherwise it will be signed by the private key and certificate in the parent object.
func NewCertFromX509Template ¶
func NewCertFromX509Template(parent *KeyAndCert, keyType string, templ *x509.Certificate) (*KeyAndCert, error)
NewCertFromX509Template creates a new keypair and certificate from an X509.Certificate template. If parent is nil, it will be self-signed, otherwise it will be signed by the private key and cert from the parent.
func (*KeyAndCert) CertPool ¶ added in v0.3.0
func (k *KeyAndCert) CertPool() *x509.CertPool
CertPool returns a *x509.CertPool suitable containing the certificate. Use this with CA certs to generate a CertPool for use with: tls.Config{RootCAs: k.CertPool()}.
func (*KeyAndCert) TLSCertificate ¶ added in v0.3.0
func (k *KeyAndCert) TLSCertificate() tls.Certificate
TLSCertificate returns a tls.Certificate suitable for use with: tls.Config{Certificates: k.TLSCertificate()}.
type Request ¶
type Request struct { // CommonName to use in the certificate Subject CN string // Organization(s) to include in the Subject O []string // Organizationl Units(s) to include in the Subject OU []string // SANs is a list of SubjectAltNames to include in the certificate. DNS, IP, Email, and URIs are // supported. SANs []string // Certiicate duration. Default is 1 year if not specified Duration time.Duration // IsCA will create a CA certificate that can be used to sign other certificates. IsCA bool // KeyType is the type of private/public key pair to create. Supported keytypes // are: // rsa-2048, rsa-3072, rsa-4096 // ecdsa-224, ecdsa-256, ecdsa-384, ecdsa-521 // ed25519 KeyType string }
Request is a simplified configuration for generating a keypair and certificate with the NewCert() func. The most common attributes for a keypair and cert are available but if you need more control over the certificate contents you should create a x509.Certificate template and use the NewCertFromX509Template() func instead.