aboutsummaryrefslogtreecommitdiff
path: root/messages.go
blob: cb2adf75e5a06b995b142eb39f0032b44c6e70a6 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package acme

import (
	"net"
	"time"

	"github.com/square/go-jose"
)

const (
	// LEV1 Let's Encrytpt V1
	LEV1 = `https://acme-v01.api.letsencrypt.org/directory`
	// LES Let's Encrypt Staging
	LES = `https://acme-staging.api.letsencrypt.org/directory`
)

// Directory ...
type Directory struct {
	NewReg     string `json:"new-reg"`
	RecoverReg string `json:"recover-reg"`
	NewAuthz   string `json:"new-authz"`
	NewCert    string `json:"new-cert"`
	RevokeCert string `json:"revoke-cert"`
}

// Registration Objects
type Registration struct {
	Resource       Resource         `json:"resource"` // new-reg
	Contact        Contacts         `json:"contact,omitempty"`
	Agreement      string           `json:"agreement,omitempty"`
	Authorizations string           `json:"authorizations,omitempty"`
	Certificates   string           `json:"certificates,omitempty"`
	ID             int              `json:"id,omitempty"`
	Key            *jose.JsonWebKey `json:"key,omitempty"`
	InitialIP      *net.IP          `json:"initialIp,omitempty"` // not in draft
	CreatedAt      *time.Time       `json:"createdAt,omitempty"`
}

// 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"`
}

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
}

// Identifier ...
type Identifier struct {
	Type  IdentType `json:"type"`  // dns
	Value string    `json:"value"` // example.com
}

// Challege ...
type Challenge struct {
	Resource         Resource   `json:"resource"` // challenge
	Type             ChalType   `json:"type"`
	Token            string     `json:"token,omitempty"`
	Status           Status     `json:"status,omitempty"` // e.g. valid
	URI              string     `json:"uri,omitempty"`
	Validated        *time.Time `json:"validated,omitempty"`
	KeyAuthorization string     `json:"keyAuthorization,omitempty"`
	Err              *Problem   `json:"error,omitempty"`
}

// Problem description
type Problem struct {
	Type     string `json:"type"`
	Detail   string `json:"detail"`
	Instance string `json:"instance"`
	Err      error  `json:"-"`
}

func (p Problem) Error() string {
	return p.Detail
}

// Status of request
type Status string

// Statuses
const (
	StatusUnknown    Status = "unknown"
	StatusPending    Status = "pending"
	StatusProcessing Status = "processing"
	StatusValid      Status = "valid"
	StatusInvalid    Status = "invalid"
	StatusRevoked    Status = "revoked"
)

type Resource string

const (
	ResNewReg     Resource = "new-reg"
	ResRecoverReg Resource = "recover-reg"
	ResNewAuthz   Resource = "new-authz"
	ResNewCert    Resource = "new-cert"
	ResRevokeCert Resource = "revoke-cert"
	ResReg        Resource = "reg"
	ResAuthz      Resource = "authz"
	ResChallenge  Resource = "challenge"
	ResCert       Resource = "cert"
)

type IdentType string

const IdentDNS IdentType = "dns"

type ChalType string

const (
	ChallengeHTTP ChalType = "http-01"
	ChallengeTLS  ChalType = "tls-sni-01"
	ChallengePOP  ChalType = "proofOfPossession-01"
	ChallengeDNS  ChalType = "dns-01"
)

type CSR struct {
	Resource Resource `json:"resource"` // new-cert
	CSR      string   `json:"csr"`
}