config: modify private key path to be onion type agnostic

This commit is contained in:
Wilmer Paulino committed 2018-09-11 19:37:11 -07:00
1 parent 9ae0ac53a2
commit 8599b30c78
1 file changed
+29 -18
+29 -18
View File
@@ -57,6 +57,7 @@ const (
defaultTorDNSPort = 53 defaultTorDNSPort = 53
defaultTorControlPort = 9051 defaultTorControlPort = 9051
defaultTorV2PrivateKeyFilename = "v2_onion_private_key" defaultTorV2PrivateKeyFilename = "v2_onion_private_key"
defaultTorV3PrivateKeyFilename = "v3_onion_private_key"
defaultBroadcastDelta = 10 defaultBroadcastDelta = 10
@@ -86,10 +87,9 @@ var (
defaultBitcoindDir = btcutil.AppDataDir("bitcoin", false) defaultBitcoindDir = btcutil.AppDataDir("bitcoin", false)
defaultLitecoindDir = btcutil.AppDataDir("litecoin", false) defaultLitecoindDir = btcutil.AppDataDir("litecoin", false)
defaultTorSOCKS = net.JoinHostPort("localhost", strconv.Itoa(defaultTorSOCKSPort)) defaultTorSOCKS = net.JoinHostPort("localhost", strconv.Itoa(defaultTorSOCKSPort))
defaultTorDNS = net.JoinHostPort(defaultTorDNSHost, strconv.Itoa(defaultTorDNSPort)) defaultTorDNS = net.JoinHostPort(defaultTorDNSHost, strconv.Itoa(defaultTorDNSPort))
defaultTorControl = net.JoinHostPort("localhost", strconv.Itoa(defaultTorControlPort)) defaultTorControl = net.JoinHostPort("localhost", strconv.Itoa(defaultTorControlPort))
defaultTorV2PrivateKeyPath = filepath.Join(defaultLndDir, defaultTorV2PrivateKeyFilename)
) )
type chainConfig struct { type chainConfig struct {
@@ -148,14 +148,14 @@ type autoPilotConfig struct {
} }
type torConfig struct { type torConfig struct {
Active bool `long:"active" description:"Allow outbound and inbound connections to be routed through Tor"` Active bool `long:"active" description:"Allow outbound and inbound connections to be routed through Tor"`
SOCKS string `long:"socks" description:"The host:port that Tor's exposed SOCKS5 proxy is listening on"` SOCKS string `long:"socks" description:"The host:port that Tor's exposed SOCKS5 proxy is listening on"`
DNS string `long:"dns" description:"The DNS server as host:port that Tor will use for SRV queries - NOTE must have TCP resolution enabled"` DNS string `long:"dns" description:"The DNS server as host:port that Tor will use for SRV queries - NOTE must have TCP resolution enabled"`
StreamIsolation bool `long:"streamisolation" description:"Enable Tor stream isolation by randomizing user credentials for each connection."` StreamIsolation bool `long:"streamisolation" description:"Enable Tor stream isolation by randomizing user credentials for each connection."`
Control string `long:"control" description:"The host:port that Tor is listening on for Tor control connections"` Control string `long:"control" description:"The host:port that Tor is listening on for Tor control connections"`
V2 bool `long:"v2" description:"Automatically set up a v2 onion service to listen for inbound connections"` V2 bool `long:"v2" description:"Automatically set up a v2 onion service to listen for inbound connections"`
V2PrivateKeyPath string `long:"v2privatekeypath" description:"The path to the private key of the onion service being created"` V3 bool `long:"v3" description:"Automatically set up a v3 onion service to listen for inbound connections"`
V3 bool `long:"v3" description:"Use a v3 onion service to listen for inbound connections"` PrivateKeyPath string `long:"privatekeypath" description:"The path to the private key of the onion service being created"`
} }
// config defines the configuration options for lnd. // config defines the configuration options for lnd.
@@ -304,10 +304,9 @@ func loadConfig() (*config, error) {
Color: defaultColor, Color: defaultColor,
MinChanSize: int64(minChanFundingSize), MinChanSize: int64(minChanFundingSize),
Tor: &torConfig{ Tor: &torConfig{
SOCKS: defaultTorSOCKS, SOCKS: defaultTorSOCKS,
DNS: defaultTorDNS, DNS: defaultTorDNS,
Control: defaultTorControl, Control: defaultTorControl,
V2PrivateKeyPath: defaultTorV2PrivateKeyPath,
}, },
net: &tor.ClearNet{}, net: &tor.ClearNet{},
} }
@@ -363,7 +362,6 @@ func loadConfig() (*config, error) {
cfg.TLSCertPath = filepath.Join(lndDir, defaultTLSCertFilename) cfg.TLSCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
cfg.TLSKeyPath = filepath.Join(lndDir, defaultTLSKeyFilename) cfg.TLSKeyPath = filepath.Join(lndDir, defaultTLSKeyFilename)
cfg.LogDir = filepath.Join(lndDir, defaultLogDirname) cfg.LogDir = filepath.Join(lndDir, defaultLogDirname)
cfg.Tor.V2PrivateKeyPath = filepath.Join(lndDir, defaultTorV2PrivateKeyFilename)
} }
// Create the lnd directory if it doesn't already exist. // Create the lnd directory if it doesn't already exist.
@@ -399,7 +397,7 @@ func loadConfig() (*config, error) {
cfg.LtcdMode.Dir = cleanAndExpandPath(cfg.LtcdMode.Dir) cfg.LtcdMode.Dir = cleanAndExpandPath(cfg.LtcdMode.Dir)
cfg.BitcoindMode.Dir = cleanAndExpandPath(cfg.BitcoindMode.Dir) cfg.BitcoindMode.Dir = cleanAndExpandPath(cfg.BitcoindMode.Dir)
cfg.LitecoindMode.Dir = cleanAndExpandPath(cfg.LitecoindMode.Dir) cfg.LitecoindMode.Dir = cleanAndExpandPath(cfg.LitecoindMode.Dir)
cfg.Tor.V2PrivateKeyPath = cleanAndExpandPath(cfg.Tor.V2PrivateKeyPath) cfg.Tor.PrivateKeyPath = cleanAndExpandPath(cfg.Tor.PrivateKeyPath)
// Ensure that the user didn't attempt to specify negative values for // Ensure that the user didn't attempt to specify negative values for
// any of the autopilot params. // any of the autopilot params.
@@ -490,6 +488,19 @@ func loadConfig() (*config, error) {
cfg.DisableListen = true cfg.DisableListen = true
} }
if cfg.Tor.PrivateKeyPath == "" {
switch {
case cfg.Tor.V2:
cfg.Tor.PrivateKeyPath = filepath.Join(
lndDir, defaultTorV2PrivateKeyFilename,
)
case cfg.Tor.V3:
cfg.Tor.PrivateKeyPath = filepath.Join(
lndDir, defaultTorV3PrivateKeyFilename,
)
}
}
// Set up the network-related functions that will be used throughout // Set up the network-related functions that will be used throughout
// the daemon. We use the standard Go "net" package functions by // the daemon. We use the standard Go "net" package functions by
// default. If we should be proxying all traffic through Tor, then // default. If we should be proxying all traffic through Tor, then