Skip to content

Commit 2c2e661

Browse files
authored
Merge pull request #287 from glasser/glasser/challenge-error
acmeapi: Expose more fields on Challenge
2 parents 56c12bd + a5401df commit 2c2e661

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

acmeapi/types.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package acmeapi
33
import (
44
"encoding/json"
55
"fmt"
6-
denet "github.com/hlandau/goutils/net"
7-
"gopkg.in/square/go-jose.v1"
6+
"net"
87
"time"
8+
9+
denet "github.com/hlandau/goutils/net"
10+
jose "gopkg.in/square/go-jose.v1"
911
)
1012

1113
// Represents an account registration.
@@ -28,6 +30,25 @@ type Registration struct {
2830
LatestAgreementURI string `json:"-"`
2931
}
3032

33+
// Represents an error that may have happened.
34+
// https://tools.ietf.org/html/draft-ietf-appsawg-http-problem-00
35+
type ProblemDetails struct {
36+
Type string `json:"type,omitempty"`
37+
Detail string `json:"detail,omitempty"`
38+
HTTPStatus int `json:"status,omitempty"`
39+
}
40+
41+
// Represents a single validation attempt.
42+
type ValidationRecord struct {
43+
Authorities []string `json:",omitempty"`
44+
URL string `json:"url,omitempty"`
45+
Hostname string `json:"hostname"`
46+
Port string `json:"port"`
47+
AddressesResolved []net.IP `json:"addressesResolved"`
48+
AddressUsed net.IP `json:"addressUsed"`
49+
AddressesTried []net.IP `json:"addressesTried"`
50+
}
51+
3152
// Represents a Challenge which is part of an Authorization.
3253
type Challenge struct {
3354
URI string `json:"uri"` // The URI of the challenge.
@@ -41,6 +62,10 @@ type Challenge struct {
4162
// proofOfPossession
4263
Certs []denet.Base64up `json:"certs,omitempty"`
4364

65+
Error *ProblemDetails `json:"error,omitempty"`
66+
ProvidedKeyAuthorization string `json:"keyAuthorization,omitempty"`
67+
ValidationRecord []ValidationRecord `json:"validationRecord,omitempty"`
68+
4469
retryAt time.Time
4570
}
4671

acmeapi/types_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package acmeapi
22

33
import (
4+
"bytes"
45
"encoding/json"
6+
"net"
57
"testing"
68
)
79

@@ -19,3 +21,43 @@ func TestStatus(t *testing.T) {
1921
t.Fatal()
2022
}
2123
}
24+
25+
func TestChallenge(t *testing.T) {
26+
const cJSON = `{
27+
"type": "http-01",
28+
"status": "invalid",
29+
"error": {
30+
"type": "urn:acme:error:caa",
31+
"detail": "CAA record for mymonash2021.conference.monash.edu prevents issuance",
32+
"status": 403
33+
},
34+
"uri": "https://acme-v01.api.letsencrypt.org/acme/challenge/wL4hNlUUJtGoMp6QeavoaAZjbqmBgJk2FMpOSC1aoIU/2676511905",
35+
"token": "GMgoj5xYX7qSIfN9GdmyqhdAHYrCco_Md9kKrT8v0jE",
36+
"keyAuthorization": "GMgoj5xYX7qSIfN9GdmyqhdAHYrCco_Md9kKrT8v0jE.QRRvz3cNxWGJObT4gl6G9ZNx-4cXE2eK81kX5lpYzmo",
37+
"validationRecord": [
38+
{
39+
"url": "http://mysite.foo.com/.well-known/acme-challenge/GMgoj5xYX7qSIfN9GdmyqHdAHYrCco_Md9kKrT8v0jE",
40+
"hostname": "mysite.foo.com",
41+
"port": "80",
42+
"addressesResolved": [
43+
"54.85.70.226",
44+
"52.21.26.68",
45+
"54.210.179.160",
46+
"52.1.9.49"
47+
],
48+
"addressUsed": "54.85.70.226",
49+
"addressesTried": []
50+
}
51+
]
52+
}`
53+
var c Challenge
54+
if err := json.Unmarshal([]byte(cJSON), &c); err != nil {
55+
t.Fatalf("%v", err)
56+
}
57+
if g, e := c.Error.Type, "urn:acme:error:caa"; g != e {
58+
t.Fatalf("%v != %v", g, e)
59+
}
60+
if g, e := c.ValidationRecord[0].AddressesResolved[1], net.IPv4(52, 21, 26, 68); !bytes.Equal(g, e) {
61+
t.Fatalf("%v != %v", g, e)
62+
}
63+
}

0 commit comments

Comments
 (0)