Documentation
¶
Index ¶
- func InstallCA(certFile string) error
- func NewCertificate(options *CertificateOptions) (Certificate, PrivateKey, error)
- func NewCertificateAndPrivateKeyPEM(options *CertificateOptions) (Certificate, PrivateKey, error)
- func NewKey() (*ecdsa.PrivateKey, error)
- func NewMatchingKey(inputKey crypto.PrivateKey) (crypto.PrivateKey, error)
- func NewSelfSignedCertificatePair(name string, org string) ([]byte, []byte, error)
- func NewSelfSignedCertificatePairWithOptions(cn, org string, sans, ipsans []string, notAfter time.Time) ([]byte, []byte, error)
- func NewTLSCertificate(options *CertificateOptions) (tls.Certificate, error)
- func NewX509Certificate(options *CertificateOptions) (*x509.Certificate, crypto.PrivateKey, error)
- func PairFromFile(certFile, keyFile string) (*x509.Certificate, crypto.PrivateKey, error)
- func ParseCertificatePEM(pemBytes []byte) (*x509.Certificate, error)
- func ParsePrivateKeyFromDER(derBytes PrivateKey) (crypto.PrivateKey, error)
- func ParsePrivateKeyFromPEM(pemBytes []byte) (crypto.PrivateKey, error)
- func PrivateKeyFromFile(keyFile string) (crypto.PrivateKey, error)
- func PublicKeyFromPrivateKey(privateKey crypto.PrivateKey) crypto.PublicKey
- func TLSCertFromFile(certFile, keyFile string) (tls.Certificate, error)
- func UninstallCA(certFile string) error
- func WriteCertAndKeyToFiles(certDER, keyDER []byte, certFile, keyFile string) error
- func WriteCertificateAndPrivateKeyToDisk(certificateBytes, keyBytes []byte, name, directory string) error
- func WritePEMToFile(derBytes []byte, blockType, filePath string, mode os.FileMode) error
- func X509CertificateFromFile(certFile string) (*x509.Certificate, error)
- type CA
- func (ca *CA) NewCertificate(cn string, sans, ipsans []string) (Certificate, PrivateKey, error)
- func (ca *CA) NewIntermediateX509Certificate(cn string, sans, ipsans []string) (*x509.Certificate, crypto.PrivateKey, error)
- func (ca *CA) NewTLSCertificate(cn string, sans, ipsans []string) (tls.Certificate, error)
- func (ca *CA) NewX509Certificate(cn string, sans, ipsans []string) (*x509.Certificate, crypto.PrivateKey, error)
- type CertInfo
- type Certificate
- type CertificateOptions
- type Intermediate
- func (intermediate *Intermediate) Chain() (Certificate, error)
- func (intermediate *Intermediate) NewCertificate(cn string, sans, ipsans []string) (Certificate, PrivateKey, error)
- func (intermediate *Intermediate) NewTLSCertificate(cn string, sans, ipsans []string) (tls.Certificate, error)
- func (intermediate *Intermediate) NewX509Certificate(cn string, sans, ipsans []string) (*x509.Certificate, crypto.PrivateKey, error)
- type OSCertStore
- type PrivateKey
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InstallCA ¶
InstallCA installs the CA certificate at the given path into the OS trust store. This requires elevated privileges on most platforms.
func NewCertificate ¶
func NewCertificate(options *CertificateOptions) (Certificate, PrivateKey, error)
This is a PEM enclosed
func NewCertificateAndPrivateKeyPEM ¶
func NewCertificateAndPrivateKeyPEM(options *CertificateOptions) (Certificate, PrivateKey, error)
func NewKey ¶
func NewKey() (*ecdsa.PrivateKey, error)
func NewMatchingKey ¶
func NewMatchingKey(inputKey crypto.PrivateKey) (crypto.PrivateKey, error)
func NewSelfSignedCertificatePairWithOptions ¶
func NewSelfSignedCertificatePairWithOptions(cn, org string, sans, ipsans []string, notAfter time.Time) ([]byte, []byte, error)
NewSelfSignedCertificatePairWithOptions creates a self-signed certificate pair with explicit SANs, IP SANs, and optional expiry. If notAfter is zero, defaults to 1 year.
func NewTLSCertificate ¶
func NewTLSCertificate(options *CertificateOptions) (tls.Certificate, error)
func NewX509Certificate ¶
func NewX509Certificate(options *CertificateOptions) (*x509.Certificate, crypto.PrivateKey, error)
func PairFromFile ¶
func PairFromFile(certFile, keyFile string) (*x509.Certificate, crypto.PrivateKey, error)
func ParseCertificatePEM ¶
func ParseCertificatePEM(pemBytes []byte) (*x509.Certificate, error)
func ParsePrivateKeyFromDER ¶
func ParsePrivateKeyFromDER(derBytes PrivateKey) (crypto.PrivateKey, error)
ParsePrivateKeyFromDER is derived from the Go standard library (crypto/tls).
Copyright 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
func ParsePrivateKeyFromPEM ¶
func ParsePrivateKeyFromPEM(pemBytes []byte) (crypto.PrivateKey, error)
func PrivateKeyFromFile ¶
func PrivateKeyFromFile(keyFile string) (crypto.PrivateKey, error)
func PublicKeyFromPrivateKey ¶
func PublicKeyFromPrivateKey(privateKey crypto.PrivateKey) crypto.PublicKey
func TLSCertFromFile ¶
func TLSCertFromFile(certFile, keyFile string) (tls.Certificate, error)
func UninstallCA ¶
UninstallCA removes a previously installed CA certificate from the OS trust store. This requires elevated privileges on most platforms.
func WriteCertAndKeyToFiles ¶
WriteCertAndKeyToFiles writes a DER certificate and key to the specified file paths as PEM.
func WritePEMToFile ¶
WritePEMToFile writes PEM-encoded DER bytes to a specific file path.
func X509CertificateFromFile ¶
func X509CertificateFromFile(certFile string) (*x509.Certificate, error)
Types ¶
type CA ¶
type CA struct {
Certificate *x509.Certificate
PrivateKey crypto.PrivateKey
Org string
}
The CA should be offline unless generating certificates for intermediate certificate authorities.
func (*CA) NewCertificate ¶
func (ca *CA) NewCertificate(cn string, sans, ipsans []string) (Certificate, PrivateKey, error)
func (*CA) NewIntermediateX509Certificate ¶
func (ca *CA) NewIntermediateX509Certificate(cn string, sans, ipsans []string) (*x509.Certificate, crypto.PrivateKey, error)
func (*CA) NewTLSCertificate ¶
func (*CA) NewX509Certificate ¶
func (ca *CA) NewX509Certificate(cn string, sans, ipsans []string) (*x509.Certificate, crypto.PrivateKey, error)
type CertInfo ¶
type CertInfo struct {
Subject string
Issuer string
SerialNumber *big.Int
NotBefore time.Time
NotAfter time.Time
DNSNames []string
IPAddresses []net.IP
IsCA bool
FilePath string
}
CertInfo holds parsed certificate details for display purposes.
func CertInfoFromFile ¶
CertInfoFromFile reads a PEM certificate file and returns its info.
func CertInfoFromX509 ¶
func CertInfoFromX509(cert *x509.Certificate, filePath string) *CertInfo
CertInfoFromX509 extracts display info from a parsed x509 certificate.
func (*CertInfo) DaysRemaining ¶
DaysRemaining returns the number of days until the certificate expires.
type Certificate ¶
type Certificate []byte
this is an x509 certificate in der format(without pem headers).
func ParseCertificatePEMToDER ¶
func ParseCertificatePEMToDER(pemBytes []byte) (Certificate, error)
func ParseCertificateX509ToPEM ¶
func ParseCertificateX509ToPEM(certificate *x509.Certificate) (Certificate, error)
func (*Certificate) Append ¶
func (certificate *Certificate) Append(certs ...Certificate)
type CertificateOptions ¶
type CertificateOptions struct {
SigningKey crypto.PrivateKey
SigningCert *x509.Certificate
Org string
CommonName string
SANS []string
IPSANS []string
IsCA bool
IsSelfSigned bool
NotAfter time.Time
}
func (*CertificateOptions) ParseIPSANS ¶
func (options *CertificateOptions) ParseIPSANS() []net.IP
type Intermediate ¶
type Intermediate struct {
CA *x509.Certificate
Certificate *x509.Certificate
PrivateKey crypto.PrivateKey
Org string
}
func NewIntermediate ¶
func NewIntermediate(caFile, certFile, keyFile string, org string) (*Intermediate, error)
func (*Intermediate) Chain ¶
func (intermediate *Intermediate) Chain() (Certificate, error)
func (*Intermediate) NewCertificate ¶
func (intermediate *Intermediate) NewCertificate(cn string, sans, ipsans []string) (Certificate, PrivateKey, error)
func (*Intermediate) NewTLSCertificate ¶
func (intermediate *Intermediate) NewTLSCertificate(cn string, sans, ipsans []string) (tls.Certificate, error)
func (*Intermediate) NewX509Certificate ¶
func (intermediate *Intermediate) NewX509Certificate(cn string, sans, ipsans []string) (*x509.Certificate, crypto.PrivateKey, error)
type OSCertStore ¶
OSCertStore is retained for backward compatibility. Trust store operations are now handled by InstallCA/UninstallCA in truststore.go with platform-specific implementations.
type PrivateKey ¶
type PrivateKey []byte