challenges.go raw
1 package challenge
2
3 import (
4 "fmt"
5
6 "github.com/go-acme/lego/v4/acme"
7 )
8
9 // Type is a string that identifies a particular challenge type and version of ACME challenge.
10 type Type string
11
12 const (
13 // HTTP01 is the "http-01" ACME challenge https://www.rfc-editor.org/rfc/rfc8555.html#section-8.3
14 // Note: ChallengePath returns the URL path to fulfill this challenge.
15 HTTP01 = Type("http-01")
16
17 // DNS01 is the "dns-01" ACME challenge https://www.rfc-editor.org/rfc/rfc8555.html#section-8.4
18 // Note: GetRecord returns a DNS record which will fulfill this challenge.
19 DNS01 = Type("dns-01")
20
21 // TLSALPN01 is the "tls-alpn-01" ACME challenge https://www.rfc-editor.org/rfc/rfc8737.html
22 TLSALPN01 = Type("tls-alpn-01")
23 )
24
25 func (t Type) String() string {
26 return string(t)
27 }
28
29 func FindChallenge(chlgType Type, authz acme.Authorization) (acme.Challenge, error) {
30 for _, chlg := range authz.Challenges {
31 if chlg.Type == string(chlgType) {
32 return chlg, nil
33 }
34 }
35
36 return acme.Challenge{}, fmt.Errorf("[%s] acme: unable to find challenge %s", GetTargetedDomain(authz), chlgType)
37 }
38
39 func GetTargetedDomain(authz acme.Authorization) string {
40 if authz.Wildcard {
41 return "*." + authz.Identifier.Value
42 }
43
44 return authz.Identifier.Value
45 }
46