-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathdns.go
83 lines (68 loc) · 1.64 KB
/
dns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package responder
import (
"crypto"
"encoding/json"
"fmt"
"gopkg.in/hlandau/acmeapi.v2/acmeutils"
)
type DNSChallengeInfo struct {
Hostname string
Body string
}
type dnsResponder struct {
rcfg Config
validation []byte
dnsString string
}
func newDNSResponder(rcfg Config) (Responder, error) {
s := &dnsResponder{
rcfg: rcfg,
validation: []byte("{}"),
}
if rcfg.Hostname == "" {
return nil, fmt.Errorf("must provide a hostname")
}
var err error
s.dnsString, err = acmeutils.DNSKeyAuthorization(rcfg.AccountKey, rcfg.Token)
if err != nil {
return nil, err
}
return s, nil
}
// Start is a no-op for the DNS method.
func (s *dnsResponder) Start() error {
// Try hooks.
if startFunc := s.rcfg.ChallengeConfig.StartHookFunc; startFunc != nil {
err := startFunc(&DNSChallengeInfo{
Hostname: s.rcfg.Hostname,
Body: s.dnsString,
})
return err
}
return fmt.Errorf("DNS challenge not supported")
}
// Stop is a no-op for the DNS method.
func (s *dnsResponder) Stop() error {
// Try hooks.
if stopFunc := s.rcfg.ChallengeConfig.StopHookFunc; stopFunc != nil {
err := stopFunc(&DNSChallengeInfo{
Hostname: s.rcfg.Hostname,
Body: s.dnsString,
})
log.Warne(err, "failed to uninstall DNS challenge via hook (ignoring)")
return nil
}
return fmt.Errorf("DNS challenge not supported")
}
func (s *dnsResponder) RequestDetectedChan() <-chan struct{} {
return nil
}
func (s *dnsResponder) Validation() json.RawMessage {
return json.RawMessage(s.validation)
}
func (s *dnsResponder) ValidationSigningKey() crypto.PrivateKey {
return nil
}
func init() {
RegisterResponder("dns-01", newDNSResponder)
}