cert

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorInvalidCommonName is given if an empty or invalid common name is given
	ErrorInvalidCommonName = errors.New("invalid common name")
	// ErrorInvalidSubjectAltName is given if an empty or invalid subject alt  name is given
	ErrorInvalidSubjectAltName = errors.New("invalid subject alt name")
	// ErrorInvalidBitSize is given if an invalid bitsize is given
	ErrorInvalidBitSize = errors.New("invalid bit size")
)

Functions

func GenerateCA

func GenerateCA(req *Request) ([]byte, []byte, error)

GenerateCA will generate a CA certificate pair and will return certificate, key and a possible error The Generated key will be in RSA format and has a bit size of 4096 and output of the Certificate and Key will be returned in PEM format as bytes.

func GenerateCertificate

func GenerateCertificate(req *Request, caCrt []byte, caKey []byte) ([]byte, []byte, error)

GenerateCertificate will generate a signed certificate pair and will return certificate, key and a possible error The Generated key will be in RSA format and has a bit size of 4096 and output of the Certificate and Key will be returned in PEM format as bytes.

The certificate will be signed by the given CA Certificate pair (caCrt and caKey). Validity of the CA Certificate pair is checked.

func GenerateRandomBigInt

func GenerateRandomBigInt() (*big.Int, error)

GenerateRandomBigInt generates a random big.int (decimal) needed for certificate serial numbers.

Types

type Request

type Request struct {
	Organization  string
	Country       string
	Province      string
	Locality      string
	StreetAddress string
	PostalCode    string
	CommonName    string

	SerialNumber     *big.Int
	NameSerialNumber string

	SubjectAltNames []string

	NotBefore time.Time
	NotAfter  time.Time

	BitSize int
}

Request is the struct needed to generate a CA or Certificate pair

func NewRequest

func NewRequest() *Request

NewRequest will create a new Request struct and set the NotBefore to now and the NotAfter to one day from now

func ReadCSR added in v0.6.0

func ReadCSR(csrFile []byte) (*Request, error)

ReadCSR reads csr into a x509.CertificateRequest and converts it into a Request

func (*Request) GetPKIXName

func (req *Request) GetPKIXName() pkix.Name

GetPKIXName extracts the Request object into a PKIX Name format for usage in constructing the certificate The NameSerialNumber is used as pkix.Name.SerialNumber here (if given).

func (*Request) Validate

func (req *Request) Validate() error

Validate will check the validity of the Request object

The checks are: - A Common Name is mandatory - If a list of SubjectAltNames is given, none of them can be empty

Jump to

Keyboard shortcuts

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