Skip to content

Commit 5b9b25b

Browse files
committed
certcache: integrate cache encryption layer
1 parent 538cea7 commit 5b9b25b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,27 @@ type proxyArg struct {
177177
value string
178178
}
179179

180+
type hexArg struct {
181+
value []byte
182+
}
183+
184+
func (a *hexArg) String() string {
185+
return hex.EncodeToString(a.value)
186+
}
187+
188+
func (a *hexArg) Set(s string) error {
189+
b, err := hex.DecodeString(s)
190+
if err != nil {
191+
return err
192+
}
193+
a.value = b
194+
return nil
195+
}
196+
197+
func (a *hexArg) Value() []byte {
198+
return a.value
199+
}
200+
180201
type cacheKind int
181202

182203
const (
@@ -210,6 +231,7 @@ type CLIArgs struct {
210231
autocertHTTP string
211232
autocertLocalCacheTTL time.Duration
212233
autocertLocalCacheTimeout time.Duration
234+
autocertCacheEncKey hexArg
213235
passwd string
214236
passwdCost int
215237
hmacSign bool
@@ -290,6 +312,7 @@ func parse_args() CLIArgs {
290312
return nil
291313
})
292314
flag.StringVar(&args.autocertCacheRedisPrefix, "autocert-cache-redis-prefix", "", "prefix to use for keys in Redis or Redis Cluster cache")
315+
flag.Var(&args.autocertCacheEncKey, "autocert-cache-enc-key", "hex-encoded encryption key for cert cache entries")
293316
flag.StringVar(&args.autocertACME, "autocert-acme", autocert.DefaultACMEDirectory, "custom ACME endpoint")
294317
flag.StringVar(&args.autocertEmail, "autocert-email", "", "email used for ACME registration")
295318
flag.StringVar(&args.autocertHTTP, "autocert-http", "", "listen address for HTTP-01 challenges handler of ACME")
@@ -559,6 +582,13 @@ func run() int {
559582
return 3
560583
}
561584
}
585+
if len(args.autocertCacheEncKey.Value()) > 0 {
586+
certCache, err = certcache.NewEncryptedCache(args.autocertCacheEncKey.Value(), certCache)
587+
if err != nil {
588+
mainLogger.Critical("unable to construct cache encryption layer: %v", err)
589+
return 3
590+
}
591+
}
562592
if args.autocertLocalCacheTTL > 0 {
563593
lcc := certcache.NewLocalCertCache(
564594
certCache,

0 commit comments

Comments
 (0)