Skip to content

Commit 8986763

Browse files
authored
Merge pull request #614 from gcaracuel/tlsvalidity_flag
Allow loopd autogenerated TLS cert validity override with a new flag
2 parents a5f4f86 + 7b31f1f commit 8986763

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

loopd/config.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ var (
9999
)
100100

101101
// DefaultAutogenValidity is the default validity of a self-signed
102-
// certificate. The value corresponds to 14 months
103-
// (14 months * 30 days * 24 hours).
104-
DefaultAutogenValidity = 14 * 30 * 24 * time.Hour
102+
// certificate in number of days.
103+
DefaultAutogenValidity = 365 * 24 * time.Hour
105104
)
106105

107106
type lndConfig struct {
@@ -146,12 +145,13 @@ type Config struct {
146145
Sqlite *loopdb.SqliteConfig `group:"sqlite" namespace:"sqlite"`
147146
Postgres *loopdb.PostgresConfig `group:"postgres" namespace:"postgres"`
148147

149-
TLSCertPath string `long:"tlscertpath" description:"Path to write the TLS certificate for loop's RPC and REST services."`
150-
TLSKeyPath string `long:"tlskeypath" description:"Path to write the TLS private key for loop's RPC and REST services."`
151-
TLSExtraIPs []string `long:"tlsextraip" description:"Adds an extra IP to the generated certificate."`
152-
TLSExtraDomains []string `long:"tlsextradomain" description:"Adds an extra domain to the generated certificate."`
153-
TLSAutoRefresh bool `long:"tlsautorefresh" description:"Re-generate TLS certificate and key if the IPs or domains are changed."`
154-
TLSDisableAutofill bool `long:"tlsdisableautofill" description:"Do not include the interface IPs or the system hostname in TLS certificate, use first --tlsextradomain as Common Name instead, if set."`
148+
TLSCertPath string `long:"tlscertpath" description:"Path to write the TLS certificate for loop's RPC and REST services."`
149+
TLSKeyPath string `long:"tlskeypath" description:"Path to write the TLS private key for loop's RPC and REST services."`
150+
TLSExtraIPs []string `long:"tlsextraip" description:"Adds an extra IP to the generated certificate."`
151+
TLSExtraDomains []string `long:"tlsextradomain" description:"Adds an extra domain to the generated certificate."`
152+
TLSAutoRefresh bool `long:"tlsautorefresh" description:"Re-generate TLS certificate and key if the IPs or domains are changed."`
153+
TLSDisableAutofill bool `long:"tlsdisableautofill" description:"Do not include the interface IPs or the system hostname in TLS certificate, use first --tlsextradomain as Common Name instead, if set."`
154+
TLSValidity time.Duration `long:"tlsvalidity" description:"Loop's TLS certificate validity period in days. Defaults to 8760h (1 year)"`
155155

156156
MacaroonPath string `long:"macaroonpath" description:"Path to write the macaroon for loop's RPC and REST services if it doesn't exist."`
157157

@@ -204,6 +204,7 @@ func DefaultConfig() Config {
204204
DebugLevel: defaultLogLevel,
205205
TLSCertPath: DefaultTLSCertPath,
206206
TLSKeyPath: DefaultTLSKeyPath,
207+
TLSValidity: DefaultAutogenValidity,
207208
MacaroonPath: DefaultMacaroonPath,
208209
MaxLSATCost: lsat.DefaultMaxCostSats,
209210
MaxLSATFee: lsat.DefaultMaxRoutingFeeSats,
@@ -348,7 +349,12 @@ func Validate(cfg *Config) error {
348349

349350
// At least one retry.
350351
if cfg.MaxPaymentRetries < 1 {
351-
return fmt.Errorf("max payment retries must be positive")
352+
return fmt.Errorf("max payment retries must be at least 1")
353+
}
354+
355+
// TLS Validity period to be at least 24 hours
356+
if cfg.TLSValidity < time.Hour*24 {
357+
return fmt.Errorf("TLS certificate minimum validity period is 24h")
352358
}
353359

354360
return nil
@@ -415,7 +421,7 @@ func loadCertWithCreate(cfg *Config) (tls.Certificate, *x509.Certificate,
415421
certBytes, keyBytes, err := cert.GenCertPair(
416422
defaultSelfSignedOrganization, cfg.TLSExtraIPs,
417423
cfg.TLSExtraDomains, cfg.TLSDisableAutofill,
418-
DefaultAutogenValidity,
424+
cfg.TLSValidity,
419425
)
420426
if err != nil {
421427
return tls.Certificate{}, nil, err

0 commit comments

Comments
 (0)