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
84
85
86
87
88
89
90
|
package acme
import (
"sync"
"time"
)
// Authorization request
type Authorization struct {
Resource Resource `json:"resource"` // new-authz
Identifier Identifier `json:"identifier"`
Status Status `json:"status,omitempty"` // e.g. valid
Expires *time.Time `json:"expires,omitempty"`
Challenges []Challenge `json:"challenges,omitempty"`
Combinations [][]int `json:"combinations,omitempty"`
}
// Identifier ...
type Identifier struct {
Type IdentType `json:"type"` // dns
Value string `json:"value"` // example.com
}
type IdentType string
const IdentDNS IdentType = "dns"
func (a Authorization) Supported(sol map[ChalType]Solver) []Challenge {
supported := func(com []int) bool {
for _, n := range com {
if _, ok := sol[a.Challenges[n].Type]; !ok {
return false
}
}
return true
}
for _, com := range a.Combinations {
if supported(com) {
c := make([]Challenge, len(com))
for i, n := range com {
c[i] = a.Challenges[n]
}
return c
}
}
return nil
}
func (p *Provider) authz(s Signer, domain string, sol map[ChalType]Solver) error {
// first step: pocke
req := &Authorization{
Resource: ResNewAuthz,
Identifier: Identifier{
Type: IdentDNS,
Value: domain,
},
}
resp, err := p.post(p.NewAuthz, s, req)
if err != nil {
return err
}
err = parseJson(resp, req)
if err != nil {
return err
}
// second step: choose and start solver
wg := sync.WaitGroup{}
for _, ch := range req.Supported(sol) {
wg.Add(1)
go func(ch Challenge) {
p.solve(s, ch, sol[ch.Type])
wg.Done()
}(ch)
}
wg.Wait()
return nil
}
func (p *Provider) Authorize(s Signer, d *Desire) error {
wg := sync.WaitGroup{}
for _, domain := range d.altnames {
wg.Add(1)
go func(domain string) {
p.authz(s, domain, d.solver)
wg.Done()
}(domain)
}
wg.Wait()
return nil
}
|