func TestReGenerate(t *testing.T) { var req = &CertificateRequest{ Names: []Name{ { C: "US", ST: "California", L: "San Francisco", O: "CloudFlare", OU: "Systems Engineering", }, }, CN: "cloudflare.com", Hosts: []string{"cloudflare.com", "www.cloudflare.com", "192.168.0.1"}, KeyRequest: &BasicKeyRequest{"ecdsa", 256}, } csr, key, err := ParseRequest(req) if err != nil { t.Fatalf("%v", err) } priv, err := helpers.ParsePrivateKeyPEM(key) if err != nil { t.Fatalf("%v", err) } csr, err = Generate(priv, req) if err != nil { t.Fatalf("%v", err) } if _, _, err = helpers.ParseCSR(csr); err != nil { t.Fatalf("%v", err) } }
// Regenerate uses the provided CSR as a template for signing a new // CSR using priv. func Regenerate(priv crypto.Signer, csr []byte) ([]byte, error) { req, extra, err := helpers.ParseCSR(csr) if err != nil { return nil, err } else if len(extra) > 0 { return nil, errors.New("csr: trailing data in certificate request") } return x509.CreateCertificateRequest(rand.Reader, req, priv) }
func TestGenerate(t *testing.T) { var req = &CertificateRequest{ Names: []Name{ { C: "US", ST: "California", L: "San Francisco", O: "CloudFlare", OU: "Systems Engineering", }, }, CN: "cloudflare.com", Hosts: []string{"cloudflare.com", "www.cloudflare.com", "192.168.0.1", "*****@*****.**"}, KeyRequest: &BasicKeyRequest{"ecdsa", 256}, } key, err := req.KeyRequest.Generate() if err != nil { t.Fatalf("%v", err) } priv, ok := key.(crypto.Signer) if !ok { t.Fatal("Private key is not a signer.") } csrPEM, err := Generate(priv, req) if err != nil { t.Fatalf("%v", err) } csr, _, err := helpers.ParseCSR(csrPEM) if err != nil { t.Fatalf("%v", err) } if len(csr.DNSNames) != 2 { t.Fatal("SAN parsing error") } if len(csr.IPAddresses) != 1 { t.Fatal("SAN parsing error") } if len(csr.EmailAddresses) != 1 { t.Fatal("SAN parsing error") } }