Skip to content

Commit 3c9c67e

Browse files
authored
caddytls: ECH key rotation (#7356)
* caddytls: ECH key rotation * Stop rotation goroutine on config unload * Publish ECH keys after rotating
1 parent 598b08f commit 3c9c67e

File tree

3 files changed

+233
-72
lines changed

3 files changed

+233
-72
lines changed

modules/caddytls/connpolicy.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,11 @@ func (cp ConnectionPolicies) TLSConfig(ctx caddy.Context) *tls.Config {
168168
tlsApp.RegisterServerNames(echNames)
169169
}
170170

171-
// TODO: Ideally, ECH keys should be rotated. However, as of Go 1.24, the std lib implementation
172-
// does not support safely modifying the tls.Config's EncryptedClientHelloKeys field.
173-
// So, we implement static ECH keys temporarily. See https://github.com/golang/go/issues/71920.
174-
// Revisit this after Go 1.25 is released and implement key rotation.
175-
var stdECHKeys []tls.EncryptedClientHelloKey
176-
for _, echConfigs := range tlsApp.EncryptedClientHello.configs {
177-
for _, c := range echConfigs {
178-
stdECHKeys = append(stdECHKeys, tls.EncryptedClientHelloKey{
179-
Config: c.configBin,
180-
PrivateKey: c.privKeyBin,
181-
SendAsRetry: c.sendAsRetry,
182-
})
183-
}
171+
tlsCfg.GetEncryptedClientHelloKeys = func(chi *tls.ClientHelloInfo) ([]tls.EncryptedClientHelloKey, error) {
172+
tlsApp.EncryptedClientHello.configsMu.RLock()
173+
defer tlsApp.EncryptedClientHello.configsMu.RUnlock()
174+
return tlsApp.EncryptedClientHello.stdlibReady, nil
184175
}
185-
tlsCfg.EncryptedClientHelloKeys = stdECHKeys
186176
}
187177
}
188178

0 commit comments

Comments
 (0)