cert

package
v0.0.0-...-0c45706 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package cert defines helper functions to generate TLS certificates.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultRecipe defines a default recipe to create self-signed certificate.
	DefaultRecipe = Recipe{
		CA:        nil,
		Hosts:     []string{"localhost", "127.0.0.1"},
		KeySpec:   "ecdsa:p256",
		ValidFrom: time.Now(),
		ValidFor:  time.Duration(365 * 24 * time.Hour),
	}
)

Functions

func New

func New(recipe Recipe, isCA bool) (*tls.Certificate, error)

New simply wraps NewFile with parameters set not to generate any files.

func NewFile

func NewFile(recipe Recipe, isCA bool, certFile, keyFile string) (*tls.Certificate, error)

NewFile generates self-signed x509 certificate and returns it. Both :certFile and :keyFile should be filled or empty else will return error. To use as x509.Certificate, access .Leaf field of returned certificate.

Reference: https://golang.org/src/crypto/tls/generate_cert.go

Types

type Recipe

type Recipe struct {
	// CA certificate to sign with. generated certificate is self-signed if CA is nil.
	CA *tls.Certificate

	// Names and IPs of hosts to generate certificate for.
	// Returns error if empty.
	Hosts []string

	// Key algorithm and strength to use in format 'algorhtm[:strength]'.
	// Available keyspecs are: rsa:<int>, ecdsa:p224/p256/p384/p521, ed25519.
	KeySpec string

	// Validity of the certificate.
	ValidFrom time.Time
	ValidFor  time.Duration
}

Recipe specify detail of certificate generation

Jump to

Keyboard shortcuts

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