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

import (
	"encoding/json"
	"errors"
	"io"
)

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

var (
	ErrBadCSR         = errors.New("CSR is unacceptable")
	ErrBadNonce       = errors.New("Client sent an unacceptable anti-replay nonce")
	ErrConnection     = errors.New("Server could not connect to the client for DV")
	ErrDNSSEC         = errors.New("Server could not validate a DNSSEC signed domain")
	ErrMalformed      = errors.New("Request message was malformed")
	ErrServerInternal = errors.New("Server experienced an internal error")
	ErrTLS            = errors.New("Server experienced a TLS error during DV")
	ErrUnauthorized   = errors.New("Client lacks sufficient authorization")
	ErrUnknownHost    = errors.New("Server could not resolve a domain name")
	ErrRateLimited    = errors.New("Request exceeds a rate limit")
	ErrInvalidContact = errors.New("Provided contact URI for a registration was invalid")
	ErrInvalidEmail   = errors.New("Provided Email for a registration was invalid")
)

// Errors
var urnErrors = map[string]error{
	"urn:acme:error:connection":                 ErrConnection,     // boulder
	"urn:acme:error:malformed":                  ErrMalformed,      // boulder
	"urn:acme:error:serverInternal":             ErrServerInternal, // boulder
	"urn:acme:error:tls":                        ErrTLS,            // boulder
	"urn:acme:error:unauthorized":               ErrUnauthorized,   // boulder
	"urn:acme:error:unknownHost":                ErrUnknownHost,    // boulder
	"urn:acme:error:rateLimited":                ErrRateLimited,    // boulder
	"urn:acme:error:badNonce":                   ErrBadNonce,       // boulder
	"urn:acme:error:invalidEmail":               ErrInvalidEmail,   // boulder
	"urn:ietf:params:acme:error:badCSR":         ErrBadCSR,         // rfc
	"urn:ietf:params:acme:error:badNonce":       ErrBadNonce,       // rfc
	"urn:ietf:params:acme:error:connection":     ErrConnection,     // rfc
	"urn:ietf:params:acme:error:dnssec":         ErrDNSSEC,         // rfc
	"urn:ietf:params:acme:error:malformed":      ErrMalformed,      // rfc
	"urn:ietf:params:acme:error:serverInternal": ErrServerInternal, // rfc
	"urn:ietf:params:acme:error:tls":            ErrTLS,            // rfc
	"urn:ietf:params:acme:error:unauthorized":   ErrUnauthorized,   // rfc
	"urn:ietf:params:acme:error:unknownHost":    ErrUnknownHost,    // rfc
	"urn:ietf:params:acme:error:rateLimited":    ErrRateLimited,    // rfc
	"urn:ietf:params:acme:error:invalidContact": ErrInvalidContact, // rfc
}

func problem(r io.Reader) error {
	var p Problem
	if err := json.NewDecoder(r).Decode(&p); err != nil {
		return err
	}
	p.Err = urnErrors[p.Type]
	return p
}