Skip to content

Commit c6a4c4e

Browse files
committed
Change ACME EAB endpoint
1 parent c6bfc6e commit c6a4c4e

File tree

4 files changed

+65
-62
lines changed

4 files changed

+65
-62
lines changed

Diff for: authority/admin/api/eak.go

-45
This file was deleted.

Diff for: authority/admin/api/handler.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (h *Handler) Route(r api.Router) {
4343
r.MethodFunc("PATCH", "/admins/{id}", authnz(h.UpdateAdmin))
4444
r.MethodFunc("DELETE", "/admins/{id}", authnz(h.DeleteAdmin))
4545

46-
// External Account Binding Keys
47-
r.MethodFunc("POST", "/eak", authnz(h.CreateExternalAccountKey))
46+
// ACME External Account Binding Keys
47+
r.MethodFunc("GET", "/acme/eab", authnz(h.GetExternalAccountKeys))
48+
r.MethodFunc("POST", "/acme/eab", authnz(h.CreateExternalAccountKey))
4849
}

Diff for: authority/admin/eak/eak.go

-12
This file was deleted.

Diff for: ca/adminClient.go

+62-3
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,54 @@ retry:
559559
return nil
560560
}
561561

562-
// CreateExternalAccountKey performs the POST /admin/eak request to the CA.
562+
// GetExternalAccountKeysPaginate returns a page from the the GET /admin/acme/eab request to the CA.
563+
func (c *AdminClient) GetExternalAccountKeysPaginate(opts ...AdminOption) (*adminAPI.GetExternalAccountKeysResponse, error) {
564+
var retried bool
565+
o := new(adminOptions)
566+
if err := o.apply(opts); err != nil {
567+
return nil, err
568+
}
569+
u := c.endpoint.ResolveReference(&url.URL{
570+
Path: "/admin/acme/eab",
571+
RawQuery: o.rawQuery(),
572+
})
573+
tok, err := c.generateAdminToken(u.Path)
574+
if err != nil {
575+
return nil, errors.Wrapf(err, "error generating admin token")
576+
}
577+
req, err := http.NewRequest("GET", u.String(), nil)
578+
if err != nil {
579+
return nil, errors.Wrapf(err, "create GET %s request failed", u)
580+
}
581+
req.Header.Add("Authorization", tok)
582+
retry:
583+
resp, err := c.client.Do(req)
584+
if err != nil {
585+
return nil, errors.Wrapf(err, "client GET %s failed", u)
586+
}
587+
if resp.StatusCode >= 400 {
588+
if !retried && c.retryOnError(resp) {
589+
retried = true
590+
goto retry
591+
}
592+
return nil, readAdminError(resp.Body)
593+
}
594+
// var body = new(GetExternalAccountKeysResponse)
595+
// if err := readJSON(resp.Body, body); err != nil {
596+
// return nil, errors.Wrapf(err, "error reading %s", u)
597+
// }
598+
// return body, nil
599+
return nil, nil // TODO: fix correctly
600+
}
601+
602+
// CreateExternalAccountKey performs the POST /admin/acme/eab request to the CA.
563603
func (c *AdminClient) CreateExternalAccountKey(eakRequest *adminAPI.CreateExternalAccountKeyRequest) (*adminAPI.CreateExternalAccountKeyResponse, error) {
564604
var retried bool
565-
//body, err := protojson.Marshal(req)
566605
body, err := json.Marshal(eakRequest)
567606
if err != nil {
568607
return nil, errs.Wrap(http.StatusInternalServerError, err, "error marshaling request")
569608
}
570-
u := c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "eak")})
609+
u := c.endpoint.ResolveReference(&url.URL{Path: path.Join(adminURLPrefix, "acme/eab")})
571610
tok, err := c.generateAdminToken(u.Path)
572611
if err != nil {
573612
return nil, errors.Wrapf(err, "error generating admin token")
@@ -596,7 +635,27 @@ retry:
596635
return eakResp, nil
597636
}
598637

638+
// GetExternalAccountKeys returns all ACME EAB Keys from the GET /admin/acme/eab request to the CA.
639+
func (c *AdminClient) GetExternalAccountKeys(opts ...AdminOption) ([]*adminAPI.CreateExternalAccountKeyResponse, error) {
640+
var (
641+
cursor = ""
642+
eaks = []*adminAPI.CreateExternalAccountKeyResponse{}
643+
)
644+
for {
645+
resp, err := c.GetExternalAccountKeysPaginate(WithAdminCursor(cursor), WithAdminLimit(100))
646+
if err != nil {
647+
return nil, err
648+
}
649+
eaks = append(eaks, resp.EAKs...)
650+
if resp.NextCursor == "" {
651+
return eaks, nil
652+
}
653+
cursor = resp.NextCursor
654+
}
655+
}
656+
599657
func readAdminError(r io.ReadCloser) error {
658+
// TODO: not all errors can be read (i.e. 404); seems to be a bigger issue
600659
defer r.Close()
601660
adminErr := new(admin.Error)
602661
if err := json.NewDecoder(r).Decode(adminErr); err != nil {

0 commit comments

Comments
 (0)