certs

package
v3.0.15 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTLSCertExpiresSoon = fmt.Errorf("TLS certificate will expire soon")

ErrTLSCertExpiresSoon is returned when the TLS certificate is about to expire.

View Source
var GenerateCert = func(template *x509.Certificate) ([]byte, []byte, error) {
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return nil, nil, errors.Wrap(err, "failed to generate private key")
	}

	derBytes, err := x509.CreateCertificate(rand.Reader, template, template, &priv.PublicKey, priv)
	if err != nil {
		return nil, nil, errors.Wrap(err, "failed to create certificate")
	}

	certPEM := new(bytes.Buffer)

	if err := pem.Encode(certPEM, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
		return nil, nil, err
	}

	keyPEM := new(bytes.Buffer)

	if err := pem.Encode(keyPEM, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}); err != nil {
		return nil, nil, err
	}

	return certPEM.Bytes(), keyPEM.Bytes(), nil
}

GenerateCert generates a new TLS certificate and returns it as PEM.

Functions

func GetConfig

func GetConfig(certPEM, keyPEM []byte) (*tls.Config, error)

GetConfig tries to load TLS config or generate new one which is then returned.

func NewTLSTemplate

func NewTLSTemplate() (*x509.Certificate, error)

NewTLSTemplate creates a new TLS template certificate with a random serial number.

Types

type Installer

type Installer struct{}

func NewInstaller

func NewInstaller() *Installer

func (*Installer) InstallCert

func (installer *Installer) InstallCert(certPEM []byte) error

func (*Installer) UninstallCert

func (installer *Installer) UninstallCert(certPEM []byte) error

Jump to

Keyboard shortcuts

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