Example #1
0
func (c *Certs) setupKeys() {
	for _, cert := range c.Certificates {
		rsaBitsLenght := 2048
		if cert.CertConfig.KeyLength > 0 {
			rsaBitsLenght = cert.CertConfig.KeyLength
		}
		cert.PrivateKey = key.GenerateKey(cert.CertConfig.KeyType, rsaBitsLenght)
	}
}
func createInterCA() (*x509.Certificate, interface{}) {
	interCaPriv := key.GenerateKey("RSA", 1024) // use small key for fast generation
	interCaData := Certificate{
		Id:                 "two",
		Country:            "SE",
		Organization:       "test",
		OrganizationalUnit: "WebInterCA",
		CA:                 true,
		PrivateKey:         interCaPriv,
		ValidFrom:          time.Now(),
		ValidTo:            time.Now().AddDate(1, 0, 0),
	}
	return CreateCertificateTemplate(interCaData), interCaPriv
}
func createCA() (*x509.Certificate, interface{}) {
	caPriv := key.GenerateKey("RSA", 1024)
	caData := Certificate{
		Id:                 "one",
		Country:            "SE",
		Organization:       "test",
		OrganizationalUnit: "WebCA",
		CA:                 true,
		PrivateKey:         caPriv,
		ValidFrom:          time.Now(),
		ValidTo:            time.Now().AddDate(1, 0, 0),
	}

	return CreateCertificateTemplate(caData), caPriv
}
func createClient() (*x509.Certificate, interface{}) {
	clientPriv := key.GenerateKey("RSA", 1024)
	clientData := Certificate{
		Id:                 "three",
		Country:            "SE",
		Organization:       "test",
		OrganizationalUnit: "Web",
		CA:                 false,
		CommonName:         "www.baz.se",
		AlternativeNames:   []string{"www.foo.se", "www.bar.se"},
		PrivateKey:         clientPriv,
		ValidFrom:          time.Now(),
		ValidTo:            time.Now().AddDate(1, 0, 0),
	}
	return CreateCertificateTemplate(clientData), clientPriv
}