2019-03-11 16:56:48 +00:00
|
|
|
package acme
|
2018-12-06 21:50:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2020-05-08 17:35:25 +00:00
|
|
|
// Errors types.
|
2018-12-06 21:50:17 +00:00
|
|
|
const (
|
|
|
|
errNS = "urn:ietf:params:acme:error:"
|
|
|
|
BadNonceErr = errNS + "badNonce"
|
|
|
|
)
|
|
|
|
|
2020-11-24 08:38:11 +00:00
|
|
|
// ProblemDetails the problem details object.
|
2021-10-22 19:26:08 +00:00
|
|
|
// - https://www.rfc-editor.org/rfc/rfc7807.html#section-3.1
|
|
|
|
// - https://www.rfc-editor.org/rfc/rfc8555.html#section-7.3.3
|
2018-12-06 21:50:17 +00:00
|
|
|
type ProblemDetails struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Detail string `json:"detail,omitempty"`
|
|
|
|
HTTPStatus int `json:"status,omitempty"`
|
|
|
|
Instance string `json:"instance,omitempty"`
|
|
|
|
SubProblems []SubProblem `json:"subproblems,omitempty"`
|
|
|
|
|
|
|
|
// additional values to have a better error message (Not defined by the RFC)
|
|
|
|
Method string `json:"method,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-11-24 08:38:11 +00:00
|
|
|
// SubProblem a "subproblems".
|
2021-10-22 19:26:08 +00:00
|
|
|
// - https://www.rfc-editor.org/rfc/rfc8555.html#section-6.7.1
|
2018-12-06 21:50:17 +00:00
|
|
|
type SubProblem struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Detail string `json:"detail,omitempty"`
|
|
|
|
Identifier Identifier `json:"identifier,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p ProblemDetails) Error() string {
|
|
|
|
msg := fmt.Sprintf("acme: error: %d", p.HTTPStatus)
|
2021-03-04 19:16:59 +00:00
|
|
|
if p.Method != "" || p.URL != "" {
|
2018-12-06 21:50:17 +00:00
|
|
|
msg += fmt.Sprintf(" :: %s :: %s", p.Method, p.URL)
|
|
|
|
}
|
|
|
|
msg += fmt.Sprintf(" :: %s :: %s", p.Type, p.Detail)
|
|
|
|
|
|
|
|
for _, sub := range p.SubProblems {
|
|
|
|
msg += fmt.Sprintf(", problem: %q :: %s", sub.Type, sub.Detail)
|
|
|
|
}
|
|
|
|
|
2021-03-04 19:16:59 +00:00
|
|
|
if p.Instance != "" {
|
2018-12-06 21:50:17 +00:00
|
|
|
msg += ", url: " + p.Instance
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
// NonceError represents the error which is returned
|
|
|
|
// if the nonce sent by the client was not accepted by the server.
|
|
|
|
type NonceError struct {
|
|
|
|
*ProblemDetails
|
|
|
|
}
|