Browse Source

Make `meta` object optional in ACME directory response

Harware appliances from Kemp seem to validate the contents of the
`meta` object, even if none of the properties in the `meta` object
is set. According to the RFC, the `meta` object, as well as its
properties are optional, so technically this should be fixed by
the manufacturer.

This commit is to see if we validation of the `meta` object is
skipped if it's not available in the response.
Herman Slatman 4 years ago
parent
commit
c9793561ff
2 changed files with 11 additions and 6 deletions
  1. 10 5
      acme/api/handler.go
  2. 1 1
      acme/api/handler_test.go

+ 10 - 5
acme/api/handler.go

@@ -205,7 +205,7 @@ type Directory struct {
 	NewOrder   string `json:"newOrder"`
 	RevokeCert string `json:"revokeCert"`
 	KeyChange  string `json:"keyChange"`
-	Meta       Meta   `json:"meta"`
+	Meta       *Meta  `json:"meta,omitempty"`
 }
 
 // ToLog enables response logging for the Directory type.
@@ -228,16 +228,21 @@ func GetDirectory(w http.ResponseWriter, r *http.Request) {
 	}
 
 	linker := acme.MustLinkerFromContext(ctx)
-	render.JSON(w, &Directory{
+	directory := &Directory{
 		NewNonce:   linker.GetLink(ctx, acme.NewNonceLinkType),
 		NewAccount: linker.GetLink(ctx, acme.NewAccountLinkType),
 		NewOrder:   linker.GetLink(ctx, acme.NewOrderLinkType),
 		RevokeCert: linker.GetLink(ctx, acme.RevokeCertLinkType),
 		KeyChange:  linker.GetLink(ctx, acme.KeyChangeLinkType),
-		Meta: Meta{
+	}
+	// Only add the ACME `meta` object when one (or more) of its
+	// properties is set.
+	if acmeProv.RequireEAB {
+		directory.Meta = &Meta{
 			ExternalAccountRequired: acmeProv.RequireEAB,
-		},
-	})
+		}
+	}
+	render.JSON(w, directory)
 }
 
 // NotImplemented returns a 501 and is generally a placeholder for functionality which

+ 1 - 1
acme/api/handler_test.go

@@ -129,7 +129,7 @@ func TestHandler_GetDirectory(t *testing.T) {
 				NewOrder:   fmt.Sprintf("%s/acme/%s/new-order", baseURL.String(), provName),
 				RevokeCert: fmt.Sprintf("%s/acme/%s/revoke-cert", baseURL.String(), provName),
 				KeyChange:  fmt.Sprintf("%s/acme/%s/key-change", baseURL.String(), provName),
-				Meta: Meta{
+				Meta: &Meta{
 					ExternalAccountRequired: true,
 				},
 			}