smimesign/fakeca
Lucas Garron 1a37be2f81
Update some `README` paths.
2021-10-04 12:35:54 -07:00
..
LICENSE.md Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
README.md Update some `README` paths. 2021-10-04 12:35:54 -07:00
configuration.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
fakeca_test.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
identity.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00

README.md

fakeca PkgGoDev

This is a package for creating fake certificate authorities for test fixtures.

Example

package main

import (
	"crypto/x509/pkix"

	"github.com/github/smimesign/fakeca"
)

func main() {
	// Change defaults for cert subjects.
	fakeca.DefaultProvince = []string{"CO"}
	fakeca.DefaultLocality = []string{"Denver"}

	// Create a root CA.
	root := fakeca.New(fakeca.IsCA, fakeca.Subject(pkix.Name{
		CommonName: "root.myorg.com",
	}))

	// Create an intermediate CA under the root.
	intermediate := root.Issue(fakeca.IsCA, fakeca.Subject(pkix.Name{
		CommonName: "intermediate.myorg.com",
	}))

	// Create a leaf certificate under the intermediate.
	leaf := intermediate.Issue(fakeca.Subject(pkix.Name{
		CommonName: "leaf.myorg.com",
	}))

	// Get PFX (PKCS12) blob containing certificate and encrypted private key.
	leafPFX := leaf.PFX("pa55w0rd")

	// Get an *x509.CertPool containing certificate chain from CA to leaf for use
	// with Go's TLS libraries.
	leafPool := leaf.ChainPool()
}