@@ -238,13 +238,6 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
238
238
return nil , errors .Wrap (err , "error creating SCEP authority" )
239
239
}
240
240
241
- // According to the RFC (https://tools.ietf.org/html/rfc8894#section-7.10),
242
- // SCEP operations are performed using HTTP, so that's why the API is mounted
243
- // to the insecure mux.
244
- insecureMux .Route ("/" + scepPrefix , func (r chi.Router ) {
245
- scepAPI .Route (r )
246
- })
247
-
248
241
// The RFC also mentions usage of HTTPS, but seems to advise
249
242
// against it, because of potential interoperability issues.
250
243
// Currently I think it's not bad to use HTTPS also, so that's
@@ -266,7 +259,6 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
266
259
return nil , err
267
260
}
268
261
handler = m .Middleware (handler )
269
- insecureHandler = m .Middleware (insecureHandler )
270
262
}
271
263
272
264
// Add logger if configured
@@ -276,25 +268,24 @@ func (ca *CA) Init(cfg *config.Config) (*CA, error) {
276
268
return nil , err
277
269
}
278
270
handler = logger .Middleware (handler )
279
- insecureHandler = logger .Middleware (insecureHandler )
280
271
}
281
272
282
273
// Create context with all the necessary values.
283
274
baseContext := buildContext (auth , scepAuthority , acmeDB , acmeLinker )
284
275
285
- ca .srv = server .New (cfg .Address , handler , tlsConfig )
286
- ca .srv .BaseContext = func (net.Listener ) context.Context {
287
- return baseContext
276
+ if cfg .Address != "" {
277
+ ca .srv = server .New (cfg .Address , handler , tlsConfig )
278
+ ca .srv .BaseContext = func (net.Listener ) context.Context {
279
+ return baseContext
280
+ }
288
281
}
289
282
290
- // only start the insecure server if the insecure address is configured
291
- // and, currently, also only when it should serve SCEP endpoints.
292
- if ca .shouldServeSCEPEndpoints () && cfg .InsecureAddress != "" {
283
+ if cfg .InsecureAddress != "" {
293
284
// TODO: instead opt for having a single server.Server but two
294
285
// http.Servers handling the HTTP and HTTPS handler? The latter
295
286
// will probably introduce more complexity in terms of graceful
296
287
// reload.
297
- ca .insecureSrv = server .New (cfg .InsecureAddress , insecureHandler , nil )
288
+ ca .insecureSrv = server .New (cfg .InsecureAddress , handler , nil )
298
289
ca .insecureSrv .BaseContext = func (net.Listener ) context.Context {
299
290
return baseContext
300
291
}
@@ -335,11 +326,13 @@ func (ca *CA) Run() error {
335
326
log .Printf ("Current context: %s" , step .Contexts ().GetCurrent ().Name )
336
327
}
337
328
log .Printf ("Config file: %s" , ca .opts .configFile )
338
- baseURL := fmt .Sprintf ("https://%s%s" ,
339
- authorityInfo .DNSNames [0 ],
340
- ca .config .Address [strings .LastIndex (ca .config .Address , ":" ):])
341
- log .Printf ("The primary server URL is %s" , baseURL )
342
- log .Printf ("Root certificates are available at %s/roots.pem" , baseURL )
329
+ if ca .config .Address != "" {
330
+ baseURL := fmt .Sprintf ("https://%s%s" ,
331
+ authorityInfo .DNSNames [0 ],
332
+ ca .config .Address [strings .LastIndex (ca .config .Address , ":" ):])
333
+ log .Printf ("The primary server URL is %s" , baseURL )
334
+ log .Printf ("Root certificates are available at %s/roots.pem" , baseURL )
335
+ }
343
336
if len (authorityInfo .DNSNames ) > 1 {
344
337
log .Printf ("Additional configured hostnames: %s" ,
345
338
strings .Join (authorityInfo .DNSNames [1 :], ", " ))
@@ -363,11 +356,13 @@ func (ca *CA) Run() error {
363
356
}()
364
357
}
365
358
366
- wg .Add (1 )
367
- go func () {
368
- defer wg .Done ()
369
- errs <- ca .srv .ListenAndServe ()
370
- }()
359
+ if ca .srv != nil {
360
+ wg .Add (1 )
361
+ go func () {
362
+ defer wg .Done ()
363
+ errs <- ca .srv .ListenAndServe ()
364
+ }()
365
+ }
371
366
372
367
// wait till error occurs; ensures the servers keep listening
373
368
err := <- errs
0 commit comments