Skip to content

Commit ed41c92

Browse files
authored
tls: add reuse_private_keys (#6025)
1 parent d9ff7b1 commit ed41c92

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

caddyconfig/httpcaddyfile/builtins.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func parseBind(h Helper) ([]ConfigValue, error) {
9090
// dns_ttl <duration>
9191
// dns_challenge_override_domain <domain>
9292
// on_demand
93+
// reuse_private_keys
9394
// eab <key_id> <mac_key>
9495
// issuer <module_name> [...]
9596
// get_certificate <module_name> [...]
@@ -106,6 +107,7 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
106107
var issuers []certmagic.Issuer
107108
var certManagers []certmagic.Manager
108109
var onDemand bool
110+
var reusePrivateKeys bool
109111

110112
for h.Next() {
111113
// file certificate loader
@@ -483,6 +485,12 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
483485
}
484486
onDemand = true
485487

488+
case "reuse_private_keys":
489+
if h.NextArg() {
490+
return nil, h.ArgErr()
491+
}
492+
reusePrivateKeys = true
493+
486494
case "insecure_secrets_log":
487495
if !h.NextArg() {
488496
return nil, h.ArgErr()
@@ -589,6 +597,14 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
589597
})
590598
}
591599

600+
// reuse private keys TLS
601+
if reusePrivateKeys {
602+
configVals = append(configVals, ConfigValue{
603+
Class: "tls.reuse_private_keys",
604+
Value: true,
605+
})
606+
}
607+
592608
// custom certificate selection
593609
if len(certSelector.AnyTag) > 0 {
594610
cp.CertSelection = &certSelector

caddyconfig/httpcaddyfile/tlsapp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ func (st ServerType) buildTLSApp(
118118
ap.OnDemand = true
119119
}
120120

121+
// reuse private keys tls
122+
if _, ok := sblock.pile["tls.reuse_private_keys"]; ok {
123+
ap.ReusePrivateKeys = true
124+
}
125+
121126
if keyTypeVals, ok := sblock.pile["tls.key_type"]; ok {
122127
ap.KeyType = keyTypeVals[0].Value.(string)
123128
}
@@ -587,6 +592,7 @@ outer:
587592
aps[i].MustStaple == aps[j].MustStaple &&
588593
aps[i].KeyType == aps[j].KeyType &&
589594
aps[i].OnDemand == aps[j].OnDemand &&
595+
aps[i].ReusePrivateKeys == aps[j].ReusePrivateKeys &&
590596
aps[i].RenewalWindowRatio == aps[j].RenewalWindowRatio {
591597
if len(aps[i].SubjectsRaw) > 0 && len(aps[j].SubjectsRaw) == 0 {
592598
// later policy (at j) has no subjects ("catch-all"), so we can

modules/caddytls/automation.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ type AutomationPolicy struct {
138138
// load. This enables On-Demand TLS for this policy.
139139
OnDemand bool `json:"on_demand,omitempty"`
140140

141+
// If true, private keys already existing in storage
142+
// will be reused. Otherwise, a new key will be
143+
// created for every new certificate to mitigate
144+
// pinning and reduce the scope of key compromise.
145+
// TEMPORARY: Key pinning is against industry best practices.
146+
// This property will likely be removed in the future.
147+
// Do not rely on it forever; watch the release notes.
148+
ReusePrivateKeys bool `json:"reuse_private_keys,omitempty"`
149+
141150
// Disables OCSP stapling. Disabling OCSP stapling puts clients at
142151
// greater risk, reduces their privacy, and usually lowers client
143152
// performance. It is NOT recommended to disable this unless you
@@ -288,6 +297,7 @@ func (ap *AutomationPolicy) Provision(tlsApp *TLS) error {
288297
KeySource: keySource,
289298
OnEvent: tlsApp.onEvent,
290299
OnDemand: ond,
300+
ReusePrivateKeys: ap.ReusePrivateKeys,
291301
OCSP: certmagic.OCSPConfig{
292302
DisableStapling: ap.DisableOCSPStapling,
293303
ResponderOverrides: ap.OCSPOverrides,

0 commit comments

Comments
 (0)