certlib

package
v0.0.0-...-2a7ebff Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultKeySize = 2048
View Source
const MinKeySize = 2048

Variables

This section is empty.

Functions

func CreateCertPool

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

CreateCertPool creates a new certificate pool from the given certificates

func CreateClientTLSCredentials

func CreateClientTLSCredentials(args ClientTLSConfigArgs[[]byte]) (cred credentials.TransportCredentials, err error)

func CreateServerTLSConfig

func CreateServerTLSConfig(args ServerTLSConfigArgs[[]byte]) (cred credentials.TransportCredentials, err error)

func CreateTLSConfig

func CreateTLSConfig(cert CertKey, roots *x509.CertPool) *tls.Config

CreateTLSConfig creates a basic TLS config for server or client

func EncodeCertificateToPEM

func EncodeCertificateToPEM(cert *x509.Certificate) (certPEMBytes []byte, err error)

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(key *rsa.PrivateKey) (keyPEMBytes []byte, err error)

func EncodePublicKeyToPEM

func EncodePublicKeyToPEM(key *rsa.PublicKey) (keyPEMBytes []byte, err error)

func EncodeRSAPrivateKeyToPEM

func EncodeRSAPrivateKeyToPEM(key *rsa.PrivateKey) (keyPEMBytes []byte, err error)

func EncodeRSAPublicKeyToPEM

func EncodeRSAPublicKeyToPEM(key *rsa.PublicKey) (keyPEMBytes []byte, err error)

func LoadClientTLSCredentials

func LoadClientTLSCredentials(args ClientTLSConfigArgs[string]) (cred credentials.TransportCredentials, err error)

func LoadServerTLSCredentials

func LoadServerTLSCredentials(args ServerTLSConfigArgs[string]) (cred credentials.TransportCredentials, err error)

func ParseCertificateFromFile

func ParseCertificateFromFile(path string) (cert *x509.Certificate, err error)

func ParseCertificateFromPEM

func ParseCertificateFromPEM(certPEMBytes []byte) (cert *x509.Certificate, err error)

func ParsePrivateKeyFromFile

func ParsePrivateKeyFromFile(path string) (key *rsa.PrivateKey, err error)

func ParsePrivateKeyFromPEM

func ParsePrivateKeyFromPEM(keyPEMBytes []byte) (key *rsa.PrivateKey, err error)

func VerifyCertificate

func VerifyCertificate(args VerifyCertificateArgs) (err error)

Types

type CertKey

type CertKey struct {
	Cert *x509.Certificate
	Key  *rsa.PrivateKey
}

func GenerateBasicCA

func GenerateBasicCA(commonName string, organization string, country string, duration time.Duration) (CertKey, error)

GenerateBasicCA creates a root CA with basic settings

func GenerateBasicClientCert

func GenerateBasicClientCert(commonName string, issuer CertKey, duration time.Duration) (CertKey, error)

GenerateBasicClientCert creates a client certificate with basic settings

func GenerateBasicIntermediateCA

func GenerateBasicIntermediateCA(commonName string, organization string, country string, issuer CertKey, duration time.Duration) (CertKey, error)

GenerateBasicIntermediateCA creates an intermediate CA with basic settings

func GenerateBasicServerCert

func GenerateBasicServerCert(commonName string, dnsNames []string, issuer CertKey, duration time.Duration) (CertKey, error)

GenerateBasicServerCert creates a server certificate with basic settings

func GenerateCertificate

func GenerateCertificate(certType CertificateType, args CertificateArgs) (res CertKey, err error)

func (*CertKey) PublicKey

func (c *CertKey) PublicKey() *rsa.PublicKey

func (*CertKey) TLSCertificate

func (c *CertKey) TLSCertificate() *tls.Certificate

type CertificateArgs

type CertificateArgs struct {
	Serial         *big.Int
	Subject        pkix.Name
	Extensions     []pkix.Extension
	Issuer         CertKey
	NotBefore      time.Time
	Duration       time.Duration
	EmailAddresses []string
	DNSNames       []string
	IPAddresses    []net.IP
	KeySize        int
}

type CertificateType

type CertificateType int
const (
	CertificateTypeRootCA CertificateType = iota
	CertificateTypeIntermediateCA
	CertificateTypeServer
	CertificateTypeClient
)

type ClientTLSConfigArgs

type ClientTLSConfigArgs[T any] struct {
	Cert       T
	Key        T
	CA         T
	ServerName string
}

type ServerTLSConfigArgs

type ServerTLSConfigArgs[T any] struct {
	Cert T
	Key  T
	CA   T
}

type VerifyCertificateArgs

type VerifyCertificateArgs struct {
	Type          CertificateType
	Cert          *x509.Certificate
	DNSName       string
	Intermediates []*x509.Certificate
	Roots         []*x509.Certificate
}

Jump to

Keyboard shortcuts

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