forked from TrueCloudLab/lego
Use boulder error messages.
This commit is contained in:
parent
c4add3c81e
commit
f08c15df80
4 changed files with 46 additions and 15 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -28,6 +29,27 @@ type TOSError struct {
|
||||||
RemoteError
|
RemoteError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type domainError struct {
|
||||||
|
Domain string
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
|
type challengeError struct {
|
||||||
|
RemoteError
|
||||||
|
records []validationRecord
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c challengeError) Error() string {
|
||||||
|
|
||||||
|
var errStr string
|
||||||
|
for _, validation := range c.records {
|
||||||
|
errStr = errStr + fmt.Sprintf("\tValidation for %s:%s\n\tResolved to:\n\t\t%s\n\tUsed: %s\n\n",
|
||||||
|
validation.Hostname, validation.Port, strings.Join(validation.ResolvedAddresses, "\n\t\t"), validation.UsedAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s\nError Detail:\n%s", c.RemoteError.Error(), errStr)
|
||||||
|
}
|
||||||
|
|
||||||
func handleHTTPError(resp *http.Response) error {
|
func handleHTTPError(resp *http.Response) error {
|
||||||
var errorDetail RemoteError
|
var errorDetail RemoteError
|
||||||
decoder := json.NewDecoder(resp.Body)
|
decoder := json.NewDecoder(resp.Body)
|
||||||
|
@ -46,7 +68,6 @@ func handleHTTPError(resp *http.Response) error {
|
||||||
return errorDetail
|
return errorDetail
|
||||||
}
|
}
|
||||||
|
|
||||||
type domainError struct {
|
func handleChallengeError(chlng challenge) error {
|
||||||
Domain string
|
return challengeError{chlng.Error, chlng.ValidationRecords}
|
||||||
Error error
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ Loop:
|
||||||
case "pending":
|
case "pending":
|
||||||
break
|
break
|
||||||
case "invalid":
|
case "invalid":
|
||||||
return errors.New("The server could not validate our request.")
|
return handleChallengeError(challengeResponse)
|
||||||
default:
|
default:
|
||||||
return errors.New("The server returned an unexpected state.")
|
return errors.New("The server returned an unexpected state.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,15 +72,25 @@ type identifier struct {
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type validationRecord struct {
|
||||||
|
URI string `json:"url,omitempty"`
|
||||||
|
Hostname string `json:"hostname,omitempty"`
|
||||||
|
Port string `json:"port,omitempty"`
|
||||||
|
ResolvedAddresses []string `json:"addressesResolved,omitempty"`
|
||||||
|
UsedAddress string `json:"addressUsed,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type challenge struct {
|
type challenge struct {
|
||||||
Resource string `json:"resource,omitempty"`
|
Resource string `json:"resource,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
URI string `json:"uri,omitempty"`
|
URI string `json:"uri,omitempty"`
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
KeyAuthorization string `json:"keyAuthorization,omitempty"`
|
KeyAuthorization string `json:"keyAuthorization,omitempty"`
|
||||||
TLS bool `json:"tls,omitempty"`
|
TLS bool `json:"tls,omitempty"`
|
||||||
Iterations int `json:"n,omitempty"`
|
Iterations int `json:"n,omitempty"`
|
||||||
|
Error RemoteError `json:"error,omitempty"`
|
||||||
|
ValidationRecords []validationRecord `json:"validationRecord,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type csrMessage struct {
|
type csrMessage struct {
|
||||||
|
|
|
@ -90,7 +90,7 @@ Loop:
|
||||||
case "pending":
|
case "pending":
|
||||||
break
|
break
|
||||||
case "invalid":
|
case "invalid":
|
||||||
return errors.New("The server could not validate our request.")
|
return handleChallengeError(challengeResponse)
|
||||||
default:
|
default:
|
||||||
return errors.New("The server returned an unexpected state.")
|
return errors.New("The server returned an unexpected state.")
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,8 @@ func (t *tlsSNIChallenge) startSNITLSServer(cert tls.Certificate) {
|
||||||
}
|
}
|
||||||
// Signal successfull start
|
// Signal successfull start
|
||||||
t.start <- tlsListener
|
t.start <- tlsListener
|
||||||
|
|
||||||
http.Serve(tlsListener, nil)
|
http.Serve(tlsListener, nil)
|
||||||
|
|
||||||
t.end <- nil
|
t.end <- nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue