-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
104 lines (84 loc) · 2.13 KB
/
types.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package acme
import (
"crypto/ecdsa"
"fmt"
"net/http"
"time"
"github.com/tommie/acme-go/protocol"
)
type Authorization struct {
protocol.Authorization
Status protocol.Status
Identifier Identifier
URI string
RetryAfter time.Duration
}
func newAuthorization(authz *protocol.Authorization, resp *http.Response) (*Authorization, error) {
st := authz.Status
if st == "" {
// Missing status value means "pending". ACME spec Sec. 5.3.
st = protocol.StatusPending
}
id, err := newIdentifier(authz.Identifier)
if err != nil {
return nil, err
}
uri, err := resp.Location()
if err == http.ErrNoLocation {
// Fall back to request URI.
// TODO: Check that the request wasn't for a new authorization.
uri = resp.Request.URL
} else if err != nil {
return nil, err
}
ra, _ := retryAfter(resp.Header, 0)
return &Authorization{
Authorization: *authz,
Status: st,
Identifier: id,
URI: uri.String(),
RetryAfter: ra,
}, nil
}
type Certificate struct {
Bytes []byte
URI string
IssuerURIs []string
RetryAfter time.Duration
}
type Identifier interface {
Protocol() *protocol.Identifier
String() string
}
type DNSIdentifier string
func (u DNSIdentifier) Protocol() *protocol.Identifier {
return &protocol.Identifier{Type: protocol.DNS, Value: string(u)}
}
func (i DNSIdentifier) String() string {
return "dns:" + string(i)
}
func newIdentifier(id protocol.Identifier) (Identifier, error) {
switch id.Type {
case protocol.DNS:
return DNSIdentifier(id.Value), nil
default:
return nil, fmt.Errorf("unknown identifier type %q in %v", id.Type, id)
}
}
type Registration struct {
protocol.Registration
URI string
RecoveryKey []byte
TermsOfServiceURI string
}
// newRegistration constructs a Registration from a registration
// request and response.
func newRegistration(reg *protocol.Registration, req *protocol.Registration, recPriv *ecdsa.PrivateKey) (*Registration, error) {
ret := &Registration{Registration: *reg}
if recPriv != nil {
if reg.RecoveryKey != nil {
return nil, fmt.Errorf("recovery keys are not implemented")
}
}
return ret, nil
}