func NewCAServer(challengeTypes []string, domainsWhitelist []string) *CAServer {
	var whitelist []string
	for _, name := range domainsWhitelist {
		whitelist = append(whitelist, name)
	}
	sort.Strings(whitelist)
	ca := &CAServer{
		challengeTypes:   challengeTypes,
		domainsWhitelist: whitelist,
		domainAddr:       make(map[string]string),
		authorizations:   make(map[string]*authorization),
	}

	key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
	if err != nil {
		panic(fmt.Sprintf("ecdsa.GenerateKey: %v", err))
	}
	tmpl := &x509.Certificate{
		SerialNumber: big.NewInt(1),
		Subject: pkix.Name{
			Organization: []string{"Test Acme Co"},
			CommonName:   "Root CA",
		},
		NotBefore:             time.Now(),
		NotAfter:              time.Now().Add(365 * 24 * time.Hour),
		KeyUsage:              x509.KeyUsageCertSign,
		BasicConstraintsValid: true,
		IsCA:                  true,
	}
	der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
	if err != nil {
		panic(fmt.Sprintf("x509.CreateCertificate: %v", err))
	}
	cert, err := x509.ParseCertificate(der)
	if err != nil {
		panic(fmt.Sprintf("x509.ParseCertificate: %v", err))
	}
	ca.Roots = x509.NewCertPool()
	ca.Roots.AddCert(cert)
	ca.rootKey = key
	ca.rootCert = der
	ca.rootTemplate = tmpl

	ca.server = httptest.NewServer(http.HandlerFunc(ca.handle))
	ca.URL = ca.server.URL
	return ca
}
// NewCAServer creates a new ACME test server and starts serving requests.
// The returned CAServer issues certs signed with the CA roots
// available in the Roots field.
//
// The challengeTypes argument defines the supported ACME challenge types
// sent to a client in a response for a domain authorization.
// If domainsWhitelist is non-empty, the certs will be issued only for the specified
// list of domains. Otherwise, any domain name is allowed.
NewCAServer creates a new ACME test server and starts serving requests.
The returned CAServer issues certs signed with the CA roots
available in the Roots field.

The challengeTypes argument defines the supported ACME challenge types
sent to a client in a response for a domain authorization.
If domainsWhitelist is non-empty, the certs will be issued only for the specified
list of domains. Otherwise, any domain name is allowed.
// NewCAServer creates a new ACME test server and starts serving requests . // The returned CAServer issues certs signed with the CA roots // available in the Roots field . // // The challengeTypes argument defines the supported ACME challenge types // sent to a client in a response for a domain authorization . // If domainsWhitelist is non - empty the certs will be issued only for the specified // list of domains . Otherwise any domain name is allowed .
func NewCAServer(challengeTypes []string, domainsWhitelist []string) *CAServer {
	var whitelist []string
	for _, name := range domainsWhitelist {
		whitelist = append(whitelist, name)
	}
	sort.Strings(whitelist)
	ca := &CAServer{
		challengeTypes:   challengeTypes,
		domainsWhitelist: whitelist,
		domainAddr:       make(map[string]string),
		authorizations:   make(map[string]*authorization),
	}
	key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
	if err != nil {
		panic(fmt.Sprintf("ecdsa.GenerateKey: %v", err))
	}
	tmpl := &x509.Certificate{
		SerialNumber: big.NewInt(1),
		Subject: pkix.Name{
			Organization: []string{"Test Acme Co"},
			CommonName:   "Root CA",
		},
		NotBefore:             time.Now(),
		NotAfter:              time.Now().Add(365 * 24 * time.Hour),
		KeyUsage:              x509.KeyUsageCertSign,
		BasicConstraintsValid: true,
		IsCA:                  true,
	}
	der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
	if err != nil {
		panic(fmt.Sprintf("x509.CreateCertificate: %v", err))
	}
	cert, err := x509.ParseCertificate(der)
	if err != nil {
		panic(fmt.Sprintf("x509.ParseCertificate: %v", err))
	}
	ca.Roots = x509.NewCertPool()
	ca.Roots.AddCert(cert)
	ca.rootKey = key
	ca.rootCert = der
	ca.rootTemplate = tmpl
	ca.server = httptest.NewServer(http.HandlerFunc(ca.handle))
	ca.URL = ca.server.URL
	return ca
}
func NewCAServer ( challengeTypes [ ] string , domainsWhitelist [ ] string ) * CAServer { var whitelist [ ] string for _ , name := range domainsWhitelist { whitelist = append ( whitelist , name ) } sort . Strings ( whitelist ) ca := & CAServer { challengeTypes : challengeTypes , domainsWhitelist : whitelist , domainAddr : make ( map [ string ] string ) , authorizations : make ( map [ string ] * authorization ) , } key , err := ecdsa . GenerateKey ( elliptic . P256 ( ) , rand . Reader ) if err != nil { panic ( fmt . Sprintf ( " " , err ) ) } tmpl := & x509 . Certificate { SerialNumber : big . NewInt ( 1 ) , Subject : pkix . Name { Organization : [ ] string { " " } , CommonName : " " , } , NotBefore : time . Now ( ) , NotAfter : time . Now ( ) . Add ( 365 * 24 * time . Hour ) , KeyUsage : x509 . KeyUsageCertSign , BasicConstraintsValid : true , IsCA : true , } der , err := x509 . CreateCertificate ( rand . Reader , tmpl , tmpl , & key . PublicKey , key ) if err != nil { panic ( fmt . Sprintf ( " " , err ) ) } cert , err := x509 . ParseCertificate ( der ) if err != nil { panic ( fmt . Sprintf ( " " , err ) ) } ca . Roots = x509 . NewCertPool ( ) ca . Roots . AddCert ( cert ) ca . rootKey = key ca . rootCert = der ca . rootTemplate = tmpl ca . server = httptest . NewServer ( http . HandlerFunc ( ca . handle ) ) ca . URL = ca . server . URL return ca }
NewCAServer creates a new ACME test server and starts serving requests.
NewCAServer creates a new ACME test server and starts serving requests .