forked from TrueCloudLab/lego
60ae6e6dc9
As per announcement [1, 2], tools.ietf.org is going to shut down in the near future. This updates the links to the referenced RFCs to their new location, as per [3]. [1]: https://mailarchive.ietf.org/arch/msg/ietf/0n-6EXEmkTp3Uv_vj-5Vnm3o0bo/ [2]: https://mailarchive.ietf.org/arch/msg/ietf-announce/xKzJZIyanPCclTd7DU9PxBAbwhA/ [3]: https://github.com/ietf-tools/tools-transition-plan#new-service-locations
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package challenge
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/go-acme/lego/v4/acme"
|
|
)
|
|
|
|
// Type is a string that identifies a particular challenge type and version of ACME challenge.
|
|
type Type string
|
|
|
|
const (
|
|
// HTTP01 is the "http-01" ACME challenge https://www.rfc-editor.org/rfc/rfc8555.html#section-8.3
|
|
// Note: ChallengePath returns the URL path to fulfill this challenge.
|
|
HTTP01 = Type("http-01")
|
|
|
|
// DNS01 is the "dns-01" ACME challenge https://www.rfc-editor.org/rfc/rfc8555.html#section-8.4
|
|
// Note: GetRecord returns a DNS record which will fulfill this challenge.
|
|
DNS01 = Type("dns-01")
|
|
|
|
// TLSALPN01 is the "tls-alpn-01" ACME challenge https://www.rfc-editor.org/rfc/rfc8737.html
|
|
TLSALPN01 = Type("tls-alpn-01")
|
|
)
|
|
|
|
func (t Type) String() string {
|
|
return string(t)
|
|
}
|
|
|
|
func FindChallenge(chlgType Type, authz acme.Authorization) (acme.Challenge, error) {
|
|
for _, chlg := range authz.Challenges {
|
|
if chlg.Type == string(chlgType) {
|
|
return chlg, nil
|
|
}
|
|
}
|
|
|
|
return acme.Challenge{}, fmt.Errorf("[%s] acme: unable to find challenge %s", GetTargetedDomain(authz), chlgType)
|
|
}
|
|
|
|
func GetTargetedDomain(authz acme.Authorization) string {
|
|
if authz.Wildcard {
|
|
return "*." + authz.Identifier.Value
|
|
}
|
|
return authz.Identifier.Value
|
|
}
|