certutil

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 22 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.

Documentation

Index

Constants

View Source
const (
	Bits2048 = 2048
)

Variables

View Source
var (
	DefaultCommonName = "default"
)
View Source
var OIDStringToNameMap = map[string]string{
	"2.5.29.14":         "Subject Key Identifier",
	"2.5.29.15":         "Key Usage",
	"2.5.29.37":         "Extended Key Usage",
	"2.5.29.35":         "Authority Key Identifier",
	"2.5.29.19":         "Basic Constraints",
	"2.5.29.17":         "Subject Alt Name",
	"2.5.29.32":         "Certificate Policies",
	"2.5.29.30":         "Name Constraints",
	"2.5.29.31":         "CRL Distribution Points",
	"1.3.6.1.5.5.7.1.1": "Authority Info Access",
	"2.5.29.20":         "CRL Number",
}

Functions

func Encode

func Encode(b CertBundle) ([]byte, error)

func EncodePKCS12 added in v0.9.0

func EncodePKCS12(b CertBundle, password string) ([]byte, error)

EncodePKCS12 is b's certificate, key and chain as a PKCS#12 file encrypted with password - by modern algorithms, AES-256 and PBKDF2-SHA256, which OpenSSL 3 reads without -legacy.

func GetExtensionValue

func GetExtensionValue(cert *x509.Certificate, oid string) (string, error)

func LoadCert

func LoadCert(CaPath, CertPath, KeyPath string) (*tls.Config, error)

func NewCSR added in v0.9.0

func NewCSR(key crypto.Signer, cn string, dnsNames []string, ips []net.IP) ([]byte, error)

NewCSR is a PEM certificate request for key's public key - what a requester sends to have it signed while keeping key to itself.

func NewCertPool

func NewCertPool(certs ...*x509.Certificate) *x509.CertPool

func ParseCSR added in v0.9.0

func ParseCSR(b []byte) (*x509.CertificateRequest, error)

ParseCSR reads a PEM or DER certificate request and checks its signature, which proves the requester holds the private key of the public key it sends.

func ParseDERCert

func ParseDERCert(b []byte) (*x509.Certificate, error)

func ParseDERKey

func ParseDERKey(der []byte, password string) (crypto.PrivateKey, error)

func ParsePEM

func ParsePEM(certBytes, caBytes, keyBytes []byte, password string) (*x509.Certificate, []*x509.Certificate, crypto.PrivateKey, error)

func ParsePEMCert

func ParsePEMCert(b []byte) (*x509.Certificate, []*x509.Certificate, error)

func ParsePEMKey

func ParsePEMKey(b []byte, password string) (crypto.PrivateKey, error)

func ParsePKCS12

func ParsePKCS12(pfxBytes []byte, password string) (*x509.Certificate, []*x509.Certificate, crypto.PrivateKey, error)

Types

type CABundle

type CABundle interface {
	CertBundle
	SignClient(req *ClientRequest) (CertBundle, error)
	SignServer(req *ServerRequest) (CertBundle, error)
	// SignCSR returns the certificate without a key: the key stays with the requester.
	SignCSR(csr *x509.CertificateRequest, req *CSRRequest) (CertBundle, error)
	SignCA(req *CARequest) (CABundle, error)
}

func MustCAFromFile

func MustCAFromFile(certFile, caFile, keyFile string) CABundle

func NewCA

func NewCA(cert *x509.Certificate, pool []*x509.Certificate, key crypto.PrivateKey) (CABundle, error)

func NewCABundle

func NewCABundle(certBytes []byte, keyPEM []byte) (CABundle, error)

type CARequest

type CARequest struct {
	CommonName string
	DNSNames   []string
	IPs        []net.IP
	KeepChain  bool
}

type CSRRequest added in v0.9.0

type CSRRequest struct {
	ExtKeyUsage []x509.ExtKeyUsage // at least one
	CommonName  string
	DNSNames    []string
	IPs         []net.IP
	ValidPeriod time.Duration // 0: until the CA expires
	KeepChain   bool
}

CSRRequest is what a CSR is signed into. The CA decides the identity: the CSR contributes its public key, and any name it asks for must be one of these.

type CertBundle

type CertBundle interface {
	CAs() []*x509.Certificate
	IsCA() bool
	Cert() *x509.Certificate
	CertDER() []byte
	CertPEM() []byte
	CertTLS() tls.Certificate
	Key() crypto.PrivateKey
	KeyDER() []byte
	KeyPEM() []byte
	Dump(certFile, keyFile string) error
	common.Debuggable
}

func Decode

func Decode(bundleData []byte) (CertBundle, error)

func MustCertFromFile

func MustCertFromFile(certFile, caFile, keyFile string) CertBundle

func NewCABundleWithoutKey

func NewCABundleWithoutKey(caBytes []byte) (CertBundle, error)

func NewCert

func NewCert(cert *x509.Certificate, pool []*x509.Certificate, key crypto.PrivateKey) (CertBundle, error)

func NewCertBundle

func NewCertBundle(certBytes, keyBytes []byte) (CertBundle, error)

func NewCertBundleWithoutKey

func NewCertBundleWithoutKey(certBytes []byte) (CertBundle, error)

type ClientRequest

type ClientRequest struct {
	CommonName  string
	ValidPeriod time.Duration
	KeepChain   bool
}

type Manager

type Manager interface {
	CABundle
	ClientFiles(req *ClientRequest, certFile, keyFile string) error
	ServerFiles(req *ServerRequest, certFile, keyFile string) error
}

func New

func New(opts ...Option) (Manager, error)

type Option

type Option func(m *manager)

func WithCertBytes

func WithCertBytes(certBytes, caBytes, keyBytes []byte) Option

func WithCertFile

func WithCertFile(certFile, caFile, keyFile string) Option

func WithCommonName

func WithCommonName(cn string) Option

func WithPassword

func WithPassword(password string) Option

type ServerRequest

type ServerRequest struct {
	CommonName  string
	DNSNames    []string
	IPs         []net.IP
	ValidPeriod time.Duration
	KeepChain   bool
}

Jump to

Keyboard shortcuts

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