Blame vendor/golang.org/x/crypto/acme/types.go

Packit Service 509fd4
// Copyright 2016 The Go Authors. All rights reserved.
Packit Service 509fd4
// Use of this source code is governed by a BSD-style
Packit Service 509fd4
// license that can be found in the LICENSE file.
Packit Service 509fd4
Packit Service 509fd4
package acme
Packit Service 509fd4
Packit Service 509fd4
import (
Packit Service 509fd4
	"crypto"
Packit Service 509fd4
	"crypto/x509"
Packit Service 509fd4
	"errors"
Packit Service 509fd4
	"fmt"
Packit Service 509fd4
	"net/http"
Packit Service 509fd4
	"strings"
Packit Service 509fd4
	"time"
Packit Service 509fd4
)
Packit Service 509fd4
Packit Service 509fd4
// ACME status values of Account, Order, Authorization and Challenge objects.
Packit Service 509fd4
// See https://tools.ietf.org/html/rfc8555#section-7.1.6 for details.
Packit Service 509fd4
const (
Packit Service 509fd4
	StatusDeactivated = "deactivated"
Packit Service 509fd4
	StatusExpired     = "expired"
Packit Service 509fd4
	StatusInvalid     = "invalid"
Packit Service 509fd4
	StatusPending     = "pending"
Packit Service 509fd4
	StatusProcessing  = "processing"
Packit Service 509fd4
	StatusReady       = "ready"
Packit Service 509fd4
	StatusRevoked     = "revoked"
Packit Service 509fd4
	StatusUnknown     = "unknown"
Packit Service 509fd4
	StatusValid       = "valid"
Packit Service 509fd4
)
Packit Service 509fd4
Packit Service 509fd4
// CRLReasonCode identifies the reason for a certificate revocation.
Packit Service 509fd4
type CRLReasonCode int
Packit Service 509fd4
Packit Service 509fd4
// CRL reason codes as defined in RFC 5280.
Packit Service 509fd4
const (
Packit Service 509fd4
	CRLReasonUnspecified          CRLReasonCode = 0
Packit Service 509fd4
	CRLReasonKeyCompromise        CRLReasonCode = 1
Packit Service 509fd4
	CRLReasonCACompromise         CRLReasonCode = 2
Packit Service 509fd4
	CRLReasonAffiliationChanged   CRLReasonCode = 3
Packit Service 509fd4
	CRLReasonSuperseded           CRLReasonCode = 4
Packit Service 509fd4
	CRLReasonCessationOfOperation CRLReasonCode = 5
Packit Service 509fd4
	CRLReasonCertificateHold      CRLReasonCode = 6
Packit Service 509fd4
	CRLReasonRemoveFromCRL        CRLReasonCode = 8
Packit Service 509fd4
	CRLReasonPrivilegeWithdrawn   CRLReasonCode = 9
Packit Service 509fd4
	CRLReasonAACompromise         CRLReasonCode = 10
Packit Service 509fd4
)
Packit Service 509fd4
Packit Service 509fd4
var (
Packit Service 509fd4
	// ErrUnsupportedKey is returned when an unsupported key type is encountered.
Packit Service 509fd4
	ErrUnsupportedKey = errors.New("acme: unknown key type; only RSA and ECDSA are supported")
Packit Service 509fd4
Packit Service 509fd4
	// ErrAccountAlreadyExists indicates that the Client's key has already been registered
Packit Service 509fd4
	// with the CA. It is returned by Register method.
Packit Service 509fd4
	ErrAccountAlreadyExists = errors.New("acme: account already exists")
Packit Service 509fd4
Packit Service 509fd4
	// ErrNoAccount indicates that the Client's key has not been registered with the CA.
Packit Service 509fd4
	ErrNoAccount = errors.New("acme: account does not exist")
Packit Service 509fd4
)
Packit Service 509fd4
Packit Service 509fd4
// Error is an ACME error, defined in Problem Details for HTTP APIs doc
Packit Service 509fd4
// http://tools.ietf.org/html/draft-ietf-appsawg-http-problem.
Packit Service 509fd4
type Error struct {
Packit Service 509fd4
	// StatusCode is The HTTP status code generated by the origin server.
Packit Service 509fd4
	StatusCode int
Packit Service 509fd4
	// ProblemType is a URI reference that identifies the problem type,
Packit Service 509fd4
	// typically in a "urn:acme:error:xxx" form.
Packit Service 509fd4
	ProblemType string
Packit Service 509fd4
	// Detail is a human-readable explanation specific to this occurrence of the problem.
Packit Service 509fd4
	Detail string
Packit Service 509fd4
	// Instance indicates a URL that the client should direct a human user to visit
Packit Service 509fd4
	// in order for instructions on how to agree to the updated Terms of Service.
Packit Service 509fd4
	// In such an event CA sets StatusCode to 403, ProblemType to
Packit Service 509fd4
	// "urn:ietf:params:acme:error:userActionRequired" and a Link header with relation
Packit Service 509fd4
	// "terms-of-service" containing the latest TOS URL.
Packit Service 509fd4
	Instance string
Packit Service 509fd4
	// Header is the original server error response headers.
Packit Service 509fd4
	// It may be nil.
Packit Service 509fd4
	Header http.Header
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (e *Error) Error() string {
Packit Service 509fd4
	return fmt.Sprintf("%d %s: %s", e.StatusCode, e.ProblemType, e.Detail)
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// AuthorizationError indicates that an authorization for an identifier
Packit Service 509fd4
// did not succeed.
Packit Service 509fd4
// It contains all errors from Challenge items of the failed Authorization.
Packit Service 509fd4
type AuthorizationError struct {
Packit Service 509fd4
	// URI uniquely identifies the failed Authorization.
Packit Service 509fd4
	URI string
Packit Service 509fd4
Packit Service 509fd4
	// Identifier is an AuthzID.Value of the failed Authorization.
Packit Service 509fd4
	Identifier string
Packit Service 509fd4
Packit Service 509fd4
	// Errors is a collection of non-nil error values of Challenge items
Packit Service 509fd4
	// of the failed Authorization.
Packit Service 509fd4
	Errors []error
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (a *AuthorizationError) Error() string {
Packit Service 509fd4
	e := make([]string, len(a.Errors))
Packit Service 509fd4
	for i, err := range a.Errors {
Packit Service 509fd4
		e[i] = err.Error()
Packit Service 509fd4
	}
Packit Service 509fd4
	return fmt.Sprintf("acme: authorization error for %s: %s", a.Identifier, strings.Join(e, "; "))
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// OrderError is returned from Client's order related methods.
Packit Service 509fd4
// It indicates the order is unusable and the clients should start over with
Packit Service 509fd4
// AuthorizeOrder.
Packit Service 509fd4
//
Packit Service 509fd4
// The clients can still fetch the order object from CA using GetOrder
Packit Service 509fd4
// to inspect its state.
Packit Service 509fd4
type OrderError struct {
Packit Service 509fd4
	OrderURL string
Packit Service 509fd4
	Status   string
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (oe *OrderError) Error() string {
Packit Service 509fd4
	return fmt.Sprintf("acme: order %s status: %s", oe.OrderURL, oe.Status)
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// RateLimit reports whether err represents a rate limit error and
Packit Service 509fd4
// any Retry-After duration returned by the server.
Packit Service 509fd4
//
Packit Service 509fd4
// See the following for more details on rate limiting:
Packit Service 509fd4
// https://tools.ietf.org/html/draft-ietf-acme-acme-05#section-5.6
Packit Service 509fd4
func RateLimit(err error) (time.Duration, bool) {
Packit Service 509fd4
	e, ok := err.(*Error)
Packit Service 509fd4
	if !ok {
Packit Service 509fd4
		return 0, false
Packit Service 509fd4
	}
Packit Service 509fd4
	// Some CA implementations may return incorrect values.
Packit Service 509fd4
	// Use case-insensitive comparison.
Packit Service 509fd4
	if !strings.HasSuffix(strings.ToLower(e.ProblemType), ":ratelimited") {
Packit Service 509fd4
		return 0, false
Packit Service 509fd4
	}
Packit Service 509fd4
	if e.Header == nil {
Packit Service 509fd4
		return 0, true
Packit Service 509fd4
	}
Packit Service 509fd4
	return retryAfter(e.Header.Get("Retry-After")), true
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// Account is a user account. It is associated with a private key.
Packit Service 509fd4
// Non-RFC 8555 fields are empty when interfacing with a compliant CA.
Packit Service 509fd4
type Account struct {
Packit Service 509fd4
	// URI is the account unique ID, which is also a URL used to retrieve
Packit Service 509fd4
	// account data from the CA.
Packit Service 509fd4
	// When interfacing with RFC 8555-compliant CAs, URI is the "kid" field
Packit Service 509fd4
	// value in JWS signed requests.
Packit Service 509fd4
	URI string
Packit Service 509fd4
Packit Service 509fd4
	// Contact is a slice of contact info used during registration.
Packit Service 509fd4
	// See https://tools.ietf.org/html/rfc8555#section-7.3 for supported
Packit Service 509fd4
	// formats.
Packit Service 509fd4
	Contact []string
Packit Service 509fd4
Packit Service 509fd4
	// Status indicates current account status as returned by the CA.
Packit Service 509fd4
	// Possible values are StatusValid, StatusDeactivated, and StatusRevoked.
Packit Service 509fd4
	Status string
Packit Service 509fd4
Packit Service 509fd4
	// OrdersURL is a URL from which a list of orders submitted by this account
Packit Service 509fd4
	// can be fetched.
Packit Service 509fd4
	OrdersURL string
Packit Service 509fd4
Packit Service 509fd4
	// The terms user has agreed to.
Packit Service 509fd4
	// A value not matching CurrentTerms indicates that the user hasn't agreed
Packit Service 509fd4
	// to the actual Terms of Service of the CA.
Packit Service 509fd4
	//
Packit Service 509fd4
	// It is non-RFC 8555 compliant. Package users can store the ToS they agree to
Packit Service 509fd4
	// during Client's Register call in the prompt callback function.
Packit Service 509fd4
	AgreedTerms string
Packit Service 509fd4
Packit Service 509fd4
	// Actual terms of a CA.
Packit Service 509fd4
	//
Packit Service 509fd4
	// It is non-RFC 8555 compliant. Use Directory's Terms field.
Packit Service 509fd4
	// When a CA updates their terms and requires an account agreement,
Packit Service 509fd4
	// a URL at which instructions to do so is available in Error's Instance field.
Packit Service 509fd4
	CurrentTerms string
Packit Service 509fd4
Packit Service 509fd4
	// Authz is the authorization URL used to initiate a new authz flow.
Packit Service 509fd4
	//
Packit Service 509fd4
	// It is non-RFC 8555 compliant. Use Directory's AuthzURL or OrderURL.
Packit Service 509fd4
	Authz string
Packit Service 509fd4
Packit Service 509fd4
	// Authorizations is a URI from which a list of authorizations
Packit Service 509fd4
	// granted to this account can be fetched via a GET request.
Packit Service 509fd4
	//
Packit Service 509fd4
	// It is non-RFC 8555 compliant and is obsoleted by OrdersURL.
Packit Service 509fd4
	Authorizations string
Packit Service 509fd4
Packit Service 509fd4
	// Certificates is a URI from which a list of certificates
Packit Service 509fd4
	// issued for this account can be fetched via a GET request.
Packit Service 509fd4
	//
Packit Service 509fd4
	// It is non-RFC 8555 compliant and is obsoleted by OrdersURL.
Packit Service 509fd4
	Certificates string
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// Directory is ACME server discovery data.
Packit Service 509fd4
// See https://tools.ietf.org/html/rfc8555#section-7.1.1 for more details.
Packit Service 509fd4
type Directory struct {
Packit Service 509fd4
	// NonceURL indicates an endpoint where to fetch fresh nonce values from.
Packit Service 509fd4
	NonceURL string
Packit Service 509fd4
Packit Service 509fd4
	// RegURL is an account endpoint URL, allowing for creating new accounts.
Packit Service 509fd4
	// Pre-RFC 8555 CAs also allow modifying existing accounts at this URL.
Packit Service 509fd4
	RegURL string
Packit Service 509fd4
Packit Service 509fd4
	// OrderURL is used to initiate the certificate issuance flow
Packit Service 509fd4
	// as described in RFC 8555.
Packit Service 509fd4
	OrderURL string
Packit Service 509fd4
Packit Service 509fd4
	// AuthzURL is used to initiate identifier pre-authorization flow.
Packit Service 509fd4
	// Empty string indicates the flow is unsupported by the CA.
Packit Service 509fd4
	AuthzURL string
Packit Service 509fd4
Packit Service 509fd4
	// CertURL is a new certificate issuance endpoint URL.
Packit Service 509fd4
	// It is non-RFC 8555 compliant and is obsoleted by OrderURL.
Packit Service 509fd4
	CertURL string
Packit Service 509fd4
Packit Service 509fd4
	// RevokeURL is used to initiate a certificate revocation flow.
Packit Service 509fd4
	RevokeURL string
Packit Service 509fd4
Packit Service 509fd4
	// KeyChangeURL allows to perform account key rollover flow.
Packit Service 509fd4
	KeyChangeURL string
Packit Service 509fd4
Packit Service 509fd4
	// Term is a URI identifying the current terms of service.
Packit Service 509fd4
	Terms string
Packit Service 509fd4
Packit Service 509fd4
	// Website is an HTTP or HTTPS URL locating a website
Packit Service 509fd4
	// providing more information about the ACME server.
Packit Service 509fd4
	Website string
Packit Service 509fd4
Packit Service 509fd4
	// CAA consists of lowercase hostname elements, which the ACME server
Packit Service 509fd4
	// recognises as referring to itself for the purposes of CAA record validation
Packit Service 509fd4
	// as defined in RFC6844.
Packit Service 509fd4
	CAA []string
Packit Service 509fd4
Packit Service 509fd4
	// ExternalAccountRequired indicates that the CA requires for all account-related
Packit Service 509fd4
	// requests to include external account binding information.
Packit Service 509fd4
	ExternalAccountRequired bool
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// rfcCompliant reports whether the ACME server implements RFC 8555.
Packit Service 509fd4
// Note that some servers may have incomplete RFC implementation
Packit Service 509fd4
// even if the returned value is true.
Packit Service 509fd4
// If rfcCompliant reports false, the server most likely implements draft-02.
Packit Service 509fd4
func (d *Directory) rfcCompliant() bool {
Packit Service 509fd4
	return d.OrderURL != ""
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// Order represents a client's request for a certificate.
Packit Service 509fd4
// It tracks the request flow progress through to issuance.
Packit Service 509fd4
type Order struct {
Packit Service 509fd4
	// URI uniquely identifies an order.
Packit Service 509fd4
	URI string
Packit Service 509fd4
Packit Service 509fd4
	// Status represents the current status of the order.
Packit Service 509fd4
	// It indicates which action the client should take.
Packit Service 509fd4
	//
Packit Service 509fd4
	// Possible values are StatusPending, StatusReady, StatusProcessing, StatusValid and StatusInvalid.
Packit Service 509fd4
	// Pending means the CA does not believe that the client has fulfilled the requirements.
Packit Service 509fd4
	// Ready indicates that the client has fulfilled all the requirements and can submit a CSR
Packit Service 509fd4
	// to obtain a certificate. This is done with Client's CreateOrderCert.
Packit Service 509fd4
	// Processing means the certificate is being issued.
Packit Service 509fd4
	// Valid indicates the CA has issued the certificate. It can be downloaded
Packit Service 509fd4
	// from the Order's CertURL. This is done with Client's FetchCert.
Packit Service 509fd4
	// Invalid means the certificate will not be issued. Users should consider this order
Packit Service 509fd4
	// abandoned.
Packit Service 509fd4
	Status string
Packit Service 509fd4
Packit Service 509fd4
	// Expires is the timestamp after which CA considers this order invalid.
Packit Service 509fd4
	Expires time.Time
Packit Service 509fd4
Packit Service 509fd4
	// Identifiers contains all identifier objects which the order pertains to.
Packit Service 509fd4
	Identifiers []AuthzID
Packit Service 509fd4
Packit Service 509fd4
	// NotBefore is the requested value of the notBefore field in the certificate.
Packit Service 509fd4
	NotBefore time.Time
Packit Service 509fd4
Packit Service 509fd4
	// NotAfter is the requested value of the notAfter field in the certificate.
Packit Service 509fd4
	NotAfter time.Time
Packit Service 509fd4
Packit Service 509fd4
	// AuthzURLs represents authorizations to complete before a certificate
Packit Service 509fd4
	// for identifiers specified in the order can be issued.
Packit Service 509fd4
	// It also contains unexpired authorizations that the client has completed
Packit Service 509fd4
	// in the past.
Packit Service 509fd4
	//
Packit Service 509fd4
	// Authorization objects can be fetched using Client's GetAuthorization method.
Packit Service 509fd4
	//
Packit Service 509fd4
	// The required authorizations are dictated by CA policies.
Packit Service 509fd4
	// There may not be a 1:1 relationship between the identifiers and required authorizations.
Packit Service 509fd4
	// Required authorizations can be identified by their StatusPending status.
Packit Service 509fd4
	//
Packit Service 509fd4
	// For orders in the StatusValid or StatusInvalid state these are the authorizations
Packit Service 509fd4
	// which were completed.
Packit Service 509fd4
	AuthzURLs []string
Packit Service 509fd4
Packit Service 509fd4
	// FinalizeURL is the endpoint at which a CSR is submitted to obtain a certificate
Packit Service 509fd4
	// once all the authorizations are satisfied.
Packit Service 509fd4
	FinalizeURL string
Packit Service 509fd4
Packit Service 509fd4
	// CertURL points to the certificate that has been issued in response to this order.
Packit Service 509fd4
	CertURL string
Packit Service 509fd4
Packit Service 509fd4
	// The error that occurred while processing the order as received from a CA, if any.
Packit Service 509fd4
	Error *Error
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// OrderOption allows customizing Client.AuthorizeOrder call.
Packit Service 509fd4
type OrderOption interface {
Packit Service 509fd4
	privateOrderOpt()
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// WithOrderNotBefore sets order's NotBefore field.
Packit Service 509fd4
func WithOrderNotBefore(t time.Time) OrderOption {
Packit Service 509fd4
	return orderNotBeforeOpt(t)
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// WithOrderNotAfter sets order's NotAfter field.
Packit Service 509fd4
func WithOrderNotAfter(t time.Time) OrderOption {
Packit Service 509fd4
	return orderNotAfterOpt(t)
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
type orderNotBeforeOpt time.Time
Packit Service 509fd4
Packit Service 509fd4
func (orderNotBeforeOpt) privateOrderOpt() {}
Packit Service 509fd4
Packit Service 509fd4
type orderNotAfterOpt time.Time
Packit Service 509fd4
Packit Service 509fd4
func (orderNotAfterOpt) privateOrderOpt() {}
Packit Service 509fd4
Packit Service 509fd4
// Authorization encodes an authorization response.
Packit Service 509fd4
type Authorization struct {
Packit Service 509fd4
	// URI uniquely identifies a authorization.
Packit Service 509fd4
	URI string
Packit Service 509fd4
Packit Service 509fd4
	// Status is the current status of an authorization.
Packit Service 509fd4
	// Possible values are StatusPending, StatusValid, StatusInvalid, StatusDeactivated,
Packit Service 509fd4
	// StatusExpired and StatusRevoked.
Packit Service 509fd4
	Status string
Packit Service 509fd4
Packit Service 509fd4
	// Identifier is what the account is authorized to represent.
Packit Service 509fd4
	Identifier AuthzID
Packit Service 509fd4
Packit Service 509fd4
	// The timestamp after which the CA considers the authorization invalid.
Packit Service 509fd4
	Expires time.Time
Packit Service 509fd4
Packit Service 509fd4
	// Wildcard is true for authorizations of a wildcard domain name.
Packit Service 509fd4
	Wildcard bool
Packit Service 509fd4
Packit Service 509fd4
	// Challenges that the client needs to fulfill in order to prove possession
Packit Service 509fd4
	// of the identifier (for pending authorizations).
Packit Service 509fd4
	// For valid authorizations, the challenge that was validated.
Packit Service 509fd4
	// For invalid authorizations, the challenge that was attempted and failed.
Packit Service 509fd4
	//
Packit Service 509fd4
	// RFC 8555 compatible CAs require users to fuflfill only one of the challenges.
Packit Service 509fd4
	Challenges []*Challenge
Packit Service 509fd4
Packit Service 509fd4
	// A collection of sets of challenges, each of which would be sufficient
Packit Service 509fd4
	// to prove possession of the identifier.
Packit Service 509fd4
	// Clients must complete a set of challenges that covers at least one set.
Packit Service 509fd4
	// Challenges are identified by their indices in the challenges array.
Packit Service 509fd4
	// If this field is empty, the client needs to complete all challenges.
Packit Service 509fd4
	//
Packit Service 509fd4
	// This field is unused in RFC 8555.
Packit Service 509fd4
	Combinations [][]int
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// AuthzID is an identifier that an account is authorized to represent.
Packit Service 509fd4
type AuthzID struct {
Packit Service 509fd4
	Type  string // The type of identifier, "dns" or "ip".
Packit Service 509fd4
	Value string // The identifier itself, e.g. "example.org".
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// DomainIDs creates a slice of AuthzID with "dns" identifier type.
Packit Service 509fd4
func DomainIDs(names ...string) []AuthzID {
Packit Service 509fd4
	a := make([]AuthzID, len(names))
Packit Service 509fd4
	for i, v := range names {
Packit Service 509fd4
		a[i] = AuthzID{Type: "dns", Value: v}
Packit Service 509fd4
	}
Packit Service 509fd4
	return a
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// IPIDs creates a slice of AuthzID with "ip" identifier type.
Packit Service 509fd4
// Each element of addr is textual form of an address as defined
Packit Service 509fd4
// in RFC1123 Section 2.1 for IPv4 and in RFC5952 Section 4 for IPv6.
Packit Service 509fd4
func IPIDs(addr ...string) []AuthzID {
Packit Service 509fd4
	a := make([]AuthzID, len(addr))
Packit Service 509fd4
	for i, v := range addr {
Packit Service 509fd4
		a[i] = AuthzID{Type: "ip", Value: v}
Packit Service 509fd4
	}
Packit Service 509fd4
	return a
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// wireAuthzID is ACME JSON representation of authorization identifier objects.
Packit Service 509fd4
type wireAuthzID struct {
Packit Service 509fd4
	Type  string `json:"type"`
Packit Service 509fd4
	Value string `json:"value"`
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// wireAuthz is ACME JSON representation of Authorization objects.
Packit Service 509fd4
type wireAuthz struct {
Packit Service 509fd4
	Identifier   wireAuthzID
Packit Service 509fd4
	Status       string
Packit Service 509fd4
	Expires      time.Time
Packit Service 509fd4
	Wildcard     bool
Packit Service 509fd4
	Challenges   []wireChallenge
Packit Service 509fd4
	Combinations [][]int
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (z *wireAuthz) authorization(uri string) *Authorization {
Packit Service 509fd4
	a := &Authorization{
Packit Service 509fd4
		URI:          uri,
Packit Service 509fd4
		Status:       z.Status,
Packit Service 509fd4
		Identifier:   AuthzID{Type: z.Identifier.Type, Value: z.Identifier.Value},
Packit Service 509fd4
		Expires:      z.Expires,
Packit Service 509fd4
		Wildcard:     z.Wildcard,
Packit Service 509fd4
		Challenges:   make([]*Challenge, len(z.Challenges)),
Packit Service 509fd4
		Combinations: z.Combinations, // shallow copy
Packit Service 509fd4
	}
Packit Service 509fd4
	for i, v := range z.Challenges {
Packit Service 509fd4
		a.Challenges[i] = v.challenge()
Packit Service 509fd4
	}
Packit Service 509fd4
	return a
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (z *wireAuthz) error(uri string) *AuthorizationError {
Packit Service 509fd4
	err := &AuthorizationError{
Packit Service 509fd4
		URI:        uri,
Packit Service 509fd4
		Identifier: z.Identifier.Value,
Packit Service 509fd4
	}
Packit Service 509fd4
	for _, raw := range z.Challenges {
Packit Service 509fd4
		if raw.Error != nil {
Packit Service 509fd4
			err.Errors = append(err.Errors, raw.Error.error(nil))
Packit Service 509fd4
		}
Packit Service 509fd4
	}
Packit Service 509fd4
	return err
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// Challenge encodes a returned CA challenge.
Packit Service 509fd4
// Its Error field may be non-nil if the challenge is part of an Authorization
Packit Service 509fd4
// with StatusInvalid.
Packit Service 509fd4
type Challenge struct {
Packit Service 509fd4
	// Type is the challenge type, e.g. "http-01", "tls-alpn-01", "dns-01".
Packit Service 509fd4
	Type string
Packit Service 509fd4
Packit Service 509fd4
	// URI is where a challenge response can be posted to.
Packit Service 509fd4
	URI string
Packit Service 509fd4
Packit Service 509fd4
	// Token is a random value that uniquely identifies the challenge.
Packit Service 509fd4
	Token string
Packit Service 509fd4
Packit Service 509fd4
	// Status identifies the status of this challenge.
Packit Service 509fd4
	// In RFC 8555, possible values are StatusPending, StatusProcessing, StatusValid,
Packit Service 509fd4
	// and StatusInvalid.
Packit Service 509fd4
	Status string
Packit Service 509fd4
Packit Service 509fd4
	// Validated is the time at which the CA validated this challenge.
Packit Service 509fd4
	// Always zero value in pre-RFC 8555.
Packit Service 509fd4
	Validated time.Time
Packit Service 509fd4
Packit Service 509fd4
	// Error indicates the reason for an authorization failure
Packit Service 509fd4
	// when this challenge was used.
Packit Service 509fd4
	// The type of a non-nil value is *Error.
Packit Service 509fd4
	Error error
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// wireChallenge is ACME JSON challenge representation.
Packit Service 509fd4
type wireChallenge struct {
Packit Service 509fd4
	URL       string `json:"url"` // RFC
Packit Service 509fd4
	URI       string `json:"uri"` // pre-RFC
Packit Service 509fd4
	Type      string
Packit Service 509fd4
	Token     string
Packit Service 509fd4
	Status    string
Packit Service 509fd4
	Validated time.Time
Packit Service 509fd4
	Error     *wireError
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (c *wireChallenge) challenge() *Challenge {
Packit Service 509fd4
	v := &Challenge{
Packit Service 509fd4
		URI:    c.URL,
Packit Service 509fd4
		Type:   c.Type,
Packit Service 509fd4
		Token:  c.Token,
Packit Service 509fd4
		Status: c.Status,
Packit Service 509fd4
	}
Packit Service 509fd4
	if v.URI == "" {
Packit Service 509fd4
		v.URI = c.URI // c.URL was empty; use legacy
Packit Service 509fd4
	}
Packit Service 509fd4
	if v.Status == "" {
Packit Service 509fd4
		v.Status = StatusPending
Packit Service 509fd4
	}
Packit Service 509fd4
	if c.Error != nil {
Packit Service 509fd4
		v.Error = c.Error.error(nil)
Packit Service 509fd4
	}
Packit Service 509fd4
	return v
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// wireError is a subset of fields of the Problem Details object
Packit Service 509fd4
// as described in https://tools.ietf.org/html/rfc7807#section-3.1.
Packit Service 509fd4
type wireError struct {
Packit Service 509fd4
	Status   int
Packit Service 509fd4
	Type     string
Packit Service 509fd4
	Detail   string
Packit Service 509fd4
	Instance string
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (e *wireError) error(h http.Header) *Error {
Packit Service 509fd4
	return &Error{
Packit Service 509fd4
		StatusCode:  e.Status,
Packit Service 509fd4
		ProblemType: e.Type,
Packit Service 509fd4
		Detail:      e.Detail,
Packit Service 509fd4
		Instance:    e.Instance,
Packit Service 509fd4
		Header:      h,
Packit Service 509fd4
	}
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// CertOption is an optional argument type for the TLS ChallengeCert methods for
Packit Service 509fd4
// customizing a temporary certificate for TLS-based challenges.
Packit Service 509fd4
type CertOption interface {
Packit Service 509fd4
	privateCertOpt()
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
// WithKey creates an option holding a private/public key pair.
Packit Service 509fd4
// The private part signs a certificate, and the public part represents the signee.
Packit Service 509fd4
func WithKey(key crypto.Signer) CertOption {
Packit Service 509fd4
	return &certOptKey{key}
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
type certOptKey struct {
Packit Service 509fd4
	key crypto.Signer
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
func (*certOptKey) privateCertOpt() {}
Packit Service 509fd4
Packit Service 509fd4
// WithTemplate creates an option for specifying a certificate template.
Packit Service 509fd4
// See x509.CreateCertificate for template usage details.
Packit Service 509fd4
//
Packit Service 509fd4
// In TLS ChallengeCert methods, the template is also used as parent,
Packit Service 509fd4
// resulting in a self-signed certificate.
Packit Service 509fd4
// The DNSNames field of t is always overwritten for tls-sni challenge certs.
Packit Service 509fd4
func WithTemplate(t *x509.Certificate) CertOption {
Packit Service 509fd4
	return (*certOptTemplate)(t)
Packit Service 509fd4
}
Packit Service 509fd4
Packit Service 509fd4
type certOptTemplate x509.Certificate
Packit Service 509fd4
Packit Service 509fd4
func (*certOptTemplate) privateCertOpt() {}