pki

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Getting Started Tasks: [x] Generate private key. [x] Generate self-signed certificate for bootstrap. [ ] Generate root certificate. [ ] Generate intermediate certificate. [ ] Storage mechanism based on interface{}. Pluggable set of storage backends. [ ] Take the root ca offline and securely store keys.

Differentiators:

  • Modern REST API.
  • Opinionated defaults and minimal number of knobs.
  • Reporting - know the state of current PKI deployment.
  • Automated issuing, distribution, and renewal of certificates without relying on third parties. This requires and agent.
  • Make it simple for configuration managmenet tools to take on this capability (but no depend on them).
  • Report on certificate usage, pulling from OS-native logging where feasible.
  • Integration with OS-native certificate storage mechanisms.

Research:

  • Key escrow capabilities.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallCA

func InstallCA(certFile string) error

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 NewSelfSignedCertificatePair

func NewSelfSignedCertificatePair(name string, org string) ([]byte, []byte, 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

func UninstallCA(certFile string) error

UninstallCA removes a previously installed CA certificate from the OS trust store. This requires elevated privileges on most platforms.

func WriteCertAndKeyToFiles

func WriteCertAndKeyToFiles(certDER, keyDER []byte, certFile, keyFile string) error

WriteCertAndKeyToFiles writes a DER certificate and key to the specified file paths as PEM.

func WriteCertificateAndPrivateKeyToDisk

func WriteCertificateAndPrivateKeyToDisk(certificateBytes, keyBytes []byte, name, directory string) error

func WritePEMToFile

func WritePEMToFile(derBytes []byte, blockType, filePath string, mode os.FileMode) error

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 NewCA

func NewCA(name, org string) (*CA, error)

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 *CA) NewTLSCertificate(cn string, sans, ipsans []string) (tls.Certificate, error)

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

func CertInfoFromFile(certFile string) (*CertInfo, error)

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

func (ci *CertInfo) DaysRemaining() int

DaysRemaining returns the number of days until the certificate expires.

func (*CertInfo) Status

func (ci *CertInfo) Status() string

Status returns the certificate's validity status.

func (*CertInfo) String

func (ci *CertInfo) String() string

String returns a formatted multi-line summary of the certificate.

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

type OSCertStore struct {
	CAROOT             string
	IgnoreCheckFailure bool
}

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

type PublicKey

type PublicKey []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL