// CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format.
// The exp argument indicates the desired certificate validity duration. CA may issue a certificate
// with a different duration.
// If the bundle argument is true, the returned value will also contain the CA (issuer) certificate chain.
//
// In the case where CA server does not provide the issued certificate in the response,
// CreateCert will poll certURL using c.FetchCert, which will result in additional round-trips.
// In such scenario the caller can cancel the polling with ctx.
//
// CreateCert returns an error if the CA's response or chain was unreasonably large.
// Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features.
CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format.
The exp argument indicates the desired certificate validity duration. CA may issue a certificate
with a different duration.
If the bundle argument is true, the returned value will also contain the CA (issuer) certificate chain.

In the case where CA server does not provide the issued certificate in the response,
CreateCert will poll certURL using c.FetchCert, which will result in additional round-trips.
In such scenario the caller can cancel the polling with ctx.

CreateCert returns an error if the CA's response or chain was unreasonably large.
Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features.
// CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format . // The exp argument indicates the desired certificate validity duration . CA may issue a certificate // with a different duration . // If the bundle argument is true the returned value will also contain the CA ( issuer ) certificate chain . // // In the case where CA server does not provide the issued certificate in the response // CreateCert will poll certURL using c . FetchCert which will result in additional round - trips . // In such scenario the caller can cancel the polling with ctx . // // CreateCert returns an error if the CA ' s response or chain was unreasonably large . // Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features .
func (c *Client) CreateCert(ctx context.Context, csr []byte, exp time.Duration, bundle bool) (der [][]byte, certURL string, err error) {
	if _, err := c.Discover(ctx); err != nil {
		return nil, "", err
	}
	req := struct {
		Resource  string `json:"resource"`
		CSR       string `json:"csr"`
		NotBefore string `json:"notBefore,omitempty"`
		NotAfter  string `json:"notAfter,omitempty"`
	}{
		Resource: "new-cert",
		CSR:      base64.RawURLEncoding.EncodeToString(csr),
	}
	now := timeNow()
	req.NotBefore = now.Format(time.RFC3339)
	if exp > 0 {
		req.NotAfter = now.Add(exp).Format(time.RFC3339)
	}
	res, err := c.postJWS(ctx, c.Key, c.dir.CertURL, req)
	if err != nil {
		return nil, "", err
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusCreated {
		return nil, "", responseError(res)
	}
	curl := res.Header.Get("location") 
	if res.ContentLength == 0 {
		cert, err := c.FetchCert(ctx, curl, bundle)
		return cert, curl, err
	}
	cert, err := c.responseCert(ctx, res, bundle)
	return cert, curl, err
}
func ( c * Client ) CreateCert ( ctx context . Context , csr [ ] byte , exp time . Duration , bundle bool ) ( der [ ] [ ] byte , certURL string , err error ) { if _ , err := c . Discover ( ctx ) ; err != nil { return nil , " " , err } req := struct { Resource string `json:"resource"` CSR string `json:"csr"` NotBefore string `json:"notBefore,omitempty"` NotAfter string `json:"notAfter,omitempty"` } { Resource : " " , CSR : base64 . RawURLEncoding . EncodeToString ( csr ) , } now := timeNow ( ) req . NotBefore = now . Format ( time . RFC3339 ) if exp > 0 { req . NotAfter = now . Add ( exp ) . Format ( time . RFC3339 ) } res , err := c . postJWS ( ctx , c . Key , c . dir . CertURL , req ) if err != nil { return nil , " " , err } defer res . Body . Close ( ) if res . StatusCode != http . StatusCreated { return nil , " " , responseError ( res ) } curl := res . Header . Get ( " " ) if res . ContentLength == 0 { cert , err := c . FetchCert ( ctx , curl , bundle ) return cert , curl , err } cert , err := c . responseCert ( ctx , res , bundle ) return cert , curl , err }
CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format.
CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format .
// cert permanent URL // no cert in the body; poll until we get it // slurp issued cert and CA chain, if requested