Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 00:45 UTC
caddytls: Allow missing ECH meta file
Matthew Holt committed
Apr 18, 2025 at 12:20 UTC
fb22a26b1a08a2fa3b2526d1852467904ee140f6
1 file changed
+21
-15
modules/caddytls/ech.go
+21
-15
@@ -278,7 +278,7 @@ func (t *TLS) publishECHConfigs() error {
278
// if all the (inner) domains have had this ECH config list published
279
// by this publisher, then try the next publication config
280
if len(serverNamesSet) == 0 {
281
- logger.Debug("ECH config list already published by publisher for associated domains",
281
+ logger.Debug("ECH config list already published by publisher for associated domains (or no domains to publish for)",
282
zap.Uint8s("config_ids", configIDs),
283
zap.String("publisher", publisherKey))
284
continue
@@ -299,7 +299,7 @@ func (t *TLS) publishECHConfigs() error {
299
err := publisher.PublishECHConfigList(t.ctx, dnsNamesToPublish, echCfgListBin)
300
if err == nil {
301
t.logger.Info("published ECH configuration list",
302
- zap.Strings("domains", publication.Domains),
302
+ zap.Strings("domains", dnsNamesToPublish),
303
zap.Uint8s("config_ids", configIDs),
304
zap.Error(err))
305
// update publication history, so that we don't unnecessarily republish every time
@@ -389,27 +389,33 @@ func loadECHConfig(ctx caddy.Context, configID string) (echConfig, error) {
389
return echConfig{}, nil
390
}
391
metaBytes, err := storage.Load(ctx, metaKey)
392
- if err != nil {
392
+ if errors.Is(err, fs.ErrNotExist) {
393
+ logger.Warn("ECH config metadata file missing; will recreate at next publication",
394
+ zap.String("config_id", configID),
395
+ zap.Error(err))
396
+ } else if err != nil {
397
delErr := storage.Delete(ctx, cfgIDKey)
398
if delErr != nil {
395
- return echConfig{}, fmt.Errorf("error loading ECH metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
399
+ return echConfig{}, fmt.Errorf("error loading ECH config metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
400
}
397
- logger.Warn("could not load ECH metadata; deleted its config folder",
401
+ logger.Warn("could not load ECH config metadata; deleted its folder",
402
zap.String("config_id", configID),
403
zap.Error(err))
404
return echConfig{}, nil
405
}
406
var meta echConfigMeta
403
- if err := json.Unmarshal(metaBytes, &meta); err != nil {
404
- // even though it's just metadata, reset the whole config since we can't reliably maintain it
405
- delErr := storage.Delete(ctx, cfgIDKey)
406
- if delErr != nil {
407
- return echConfig{}, fmt.Errorf("error decoding ECH metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
407
+ if len(metaBytes) > 0 {
408
+ if err := json.Unmarshal(metaBytes, &meta); err != nil {
409
+ // even though it's just metadata, reset the whole config since we can't reliably maintain it
410
+ delErr := storage.Delete(ctx, cfgIDKey)
411
+ if delErr != nil {
412
+ return echConfig{}, fmt.Errorf("error decoding ECH metadata (%v) and cleaning up parent storage key %s: %v", err, cfgIDKey, delErr)
413
+ }
414
+ logger.Warn("could not JSON-decode ECH metadata; deleted its config folder",
415
+ zap.String("config_id", configID),
416
+ zap.Error(err))
417
+ return echConfig{}, nil
418
}
409
- logger.Warn("could not JSON-decode ECH metadata; deleted its config folder",
410
- zap.String("config_id", configID),
411
- zap.Error(err))
412
- return echConfig{}, nil
419
}
420
421
cfg.privKeyBin = privKeyBytes
@@ -700,7 +706,7 @@ nextName:
706
// HTTPS and SVCB RRs: RFC 9460 (https://www.rfc-editor.org/rfc/rfc9460)
707
Scheme: "https",
708
Name: relName,
703
- TTL: 1 * time.Minute, // TODO: for testing only
709
+ TTL: 5 * time.Minute, // TODO: low hard-coded value only temporary; change to a higher value once more field-tested and key rotation is implemented
710
Priority: 2, // allows a manual override with priority 1
711
Target: ".",
712
Params: params,