aboutsummaryrefslogtreecommitdiff
path: root/messages.go
blob: c270f320af6b9e06c2ad22e7024d5a736a436bb8 (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
package acme

import (
	"fmt"
	"net"
	"time"
)

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        []Contact `json:"contact,omitempty"`
	Agreement      string    `json:"agreement,omitempty"`
	Authorizations string    `json:"authorizations,omitempty"`
	Certificates   string    `json:"certificates,omitempty"`
}

// RegistrationResp ...
type RegistrationResp struct {
	ID        int       `json:"id"`
	Key       Key       `json:"key"`
	Contact   []string  `json:"contact"`
	InitialIP net.IP    `json:"initialIp"` // not in draft
	CreatedAt time.Time `json:"createdAt"` // 2006-01-02T15:04:05.999999999Z
}

// Key contains public part of jose.JsonWebKey
type Key struct {
	Kty string `json:"kty"` // RSA, EC
	E   string `json:"e"`
	N   string `json:"n"`
}

// Authorization request
type Authorization struct {
	Resource   Resource   `json:"resource"` // new-authz
	Identifier Identifier `json:"identifier"`
}

// AuthorizationResp Objects
type AuthorizationResp struct {
	Identifier   Identifier  `json:"identifier"`
	Status       Status      `json:"status,omitemtpy"`  // e.g. valid
	Expires      string      `json:"expires,omitempty"` // 2006-01-02
	Challenges   []Challenge `json:"challenges"`
	Combinations [][]int     `json:"combinations,omitemtpy"`
}

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

// Challege ...
type Challenge struct {
	Type             string `json:"type"`      // http-01
	Status           Status `json:"status"`    // e.g. valid
	Validated        string `json:"validated"` // 2006-01-02T15:04Z
	KeyAuthorization string `json:"keyAuthorization"`
}

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

// Status of request
type Status int

// Statuses
const (
	StatusUnknown Status = iota
	StatusPending
	StatusProcessing
	StatusValid
	StatusInvalid
	StatusRevoked
)

// UnmarshalText implemets json interface for status decoding
func (s *Status) UnmarshalText(b []byte) error {
	var status = map[string]Status{
		"unknown":    StatusUnknown,
		"pending":    StatusPending,
		"processing": StatusProcessing,
		"valid":      StatusValid,
		"invalid":    StatusInvalid,
		"revoked":    StatusRevoked,
	}
	if st, ok := status[string(b)]; ok {
		*s = st
		return nil
	}
	return fmt.Errorf("unknown status %v", string(b))
}