@@ -49,6 +49,7 @@ type CAServer struct {
49
49
challengeTypes []string
50
50
url string
51
51
roots * x509.CertPool
52
+ eabRequired bool
52
53
53
54
mu sync.Mutex
54
55
certCount int // number of issued certs
@@ -152,6 +153,15 @@ func (ca *CAServer) Roots() *x509.CertPool {
152
153
return ca .roots
153
154
}
154
155
156
+ // ExternalAccountRequired makes an EAB JWS required for account registration.
157
+ func (ca * CAServer ) ExternalAccountRequired () * CAServer {
158
+ if ca .url != "" {
159
+ panic ("ExternalAccountRequired must be called before Start" )
160
+ }
161
+ ca .eabRequired = true
162
+ return ca
163
+ }
164
+
155
165
// Start starts serving requests. The server address becomes available in the
156
166
// URL field.
157
167
func (ca * CAServer ) Start () * CAServer {
@@ -224,6 +234,12 @@ type discovery struct {
224
234
NewAccount string `json:"newAccount"`
225
235
NewOrder string `json:"newOrder"`
226
236
NewAuthz string `json:"newAuthz"`
237
+
238
+ Meta discoveryMeta `json:"meta,omitempty"`
239
+ }
240
+
241
+ type discoveryMeta struct {
242
+ ExternalAccountRequired bool `json:"externalAccountRequired,omitempty"`
227
243
}
228
244
229
245
type challenge struct {
@@ -264,6 +280,9 @@ func (ca *CAServer) handle(w http.ResponseWriter, r *http.Request) {
264
280
NewNonce : ca .serverURL ("/new-nonce" ),
265
281
NewAccount : ca .serverURL ("/new-account" ),
266
282
NewOrder : ca .serverURL ("/new-order" ),
283
+ Meta : discoveryMeta {
284
+ ExternalAccountRequired : ca .eabRequired ,
285
+ },
267
286
}
268
287
if err := json .NewEncoder (w ).Encode (resp ); err != nil {
269
288
panic (fmt .Sprintf ("discovery response: %v" , err ))
@@ -283,6 +302,21 @@ func (ca *CAServer) handle(w http.ResponseWriter, r *http.Request) {
283
302
return
284
303
}
285
304
ca .acctRegistered = true
305
+
306
+ var req struct {
307
+ ExternalAccountBinding json.RawMessage
308
+ }
309
+
310
+ if err := decodePayload (& req , r .Body ); err != nil {
311
+ ca .httpErrorf (w , http .StatusBadRequest , err .Error ())
312
+ return
313
+ }
314
+
315
+ if ca .eabRequired && len (req .ExternalAccountBinding ) == 0 {
316
+ ca .httpErrorf (w , http .StatusBadRequest , "registration failed: no JWS for EAB" )
317
+ return
318
+ }
319
+
286
320
// TODO: Check the user account key against a ca.accountKeys?
287
321
w .Header ().Set ("Location" , ca .serverURL ("/accounts/1" ))
288
322
w .WriteHeader (http .StatusCreated )
0 commit comments