mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Connect with CookieAuthentication
This commit is contained in:
parent
139ec518fc
commit
64c6e3d783
6 changed files with 37 additions and 4 deletions
|
@ -193,9 +193,11 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
protected final String btcNodes, seedNodes, ignoreDevMsg, useDevPrivilegeKeys, useDevMode, useTorForBtc, rpcUser, rpcPassword,
|
||||
rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode,
|
||||
myAddress, banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress,
|
||||
torRcFile, torRcOptions, externalTorControlPort, externalTorPassword,
|
||||
torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile,
|
||||
socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, referralId, daoActivated;
|
||||
|
||||
protected final boolean externalTorUseSafeCookieAuthentication;
|
||||
|
||||
public BisqEnvironment(OptionSet options) {
|
||||
this(new JOptCommandLinePropertySource(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME, checkNotNull(
|
||||
options)));
|
||||
|
@ -279,6 +281,12 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
externalTorPassword = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD) ?
|
||||
(String) commandLineProperties.getProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD) :
|
||||
"";
|
||||
externalTorCookieFile = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) ?
|
||||
(String) commandLineProperties.getProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) :
|
||||
"";
|
||||
externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) ?
|
||||
true :
|
||||
false;
|
||||
|
||||
//RpcOptionKeys
|
||||
rpcUser = commandLineProperties.containsProperty(DaoOptionKeys.RPC_USER) ?
|
||||
|
@ -451,6 +459,9 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
setProperty(NetworkOptionKeys.TORRC_OPTIONS, torRcOptions);
|
||||
setProperty(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT, externalTorControlPort);
|
||||
setProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD, externalTorPassword);
|
||||
setProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE, externalTorCookieFile);
|
||||
if (externalTorUseSafeCookieAuthentication)
|
||||
setProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, "true");
|
||||
|
||||
setProperty(AppOptionKeys.APP_DATA_DIR_KEY, appDataDir);
|
||||
setProperty(AppOptionKeys.DESKTOP_WITH_HTTP_API, desktopWithHttpApi);
|
||||
|
|
|
@ -372,6 +372,15 @@ public abstract class BisqExecutable implements GracefulShutDownHandler {
|
|||
description("The password for controlling the already running Tor service.", ""))
|
||||
.availableIf(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT)
|
||||
.withRequiredArg();
|
||||
parser.accepts(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE,
|
||||
description("The cookie file for authenticating against the already running Tor service. Use in conjunction with --" + NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, ""))
|
||||
.availableIf(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT)
|
||||
.availableUnless(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD)
|
||||
.withRequiredArg()
|
||||
.withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.READABLE));
|
||||
parser.accepts(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE,
|
||||
description("Use the SafeCookie method when authenticating to the already running Tor service.", ""))
|
||||
.availableIf(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE);
|
||||
|
||||
//AppOptionKeys
|
||||
parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY,
|
||||
|
|
|
@ -33,4 +33,6 @@ public class NetworkOptionKeys {
|
|||
public static final String TORRC_FILE = "torrcFile";
|
||||
public static final String EXTERNAL_TOR_CONTROL_PORT = "torControlPort";
|
||||
public static final String EXTERNAL_TOR_PASSWORD = "torControlPassword";
|
||||
public static final String EXTERNAL_TOR_COOKIE_FILE = "torControlCookieFile";
|
||||
public static final String EXTERNAL_TOR_USE_SAFECOOKIE = "torControlUseSafeCookieAuth";
|
||||
}
|
||||
|
|
|
@ -48,12 +48,14 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
|||
@Named(NetworkOptionKeys.TORRC_FILE) String torrcFile,
|
||||
@Named(NetworkOptionKeys.TORRC_OPTIONS) String torrcOptions,
|
||||
@Named(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT) String controlPort,
|
||||
@Named(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD) String password) {
|
||||
@Named(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD) String password,
|
||||
@Named(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) String cookieFile,
|
||||
@Named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) boolean useSafeCookieAuthentication ) {
|
||||
networkNode = useLocalhostForP2P ?
|
||||
new LocalhostNetworkNode(address, port, networkProtoResolver) :
|
||||
new TorNetworkNode(port, torDir, networkProtoResolver, bridgeAddressProvider,
|
||||
!controlPort.isEmpty() ?
|
||||
new RunningTor(torDir, Integer.parseInt(controlPort), password) :
|
||||
new RunningTor(torDir, Integer.parseInt(controlPort), password, cookieFile, useSafeCookieAuthentication) :
|
||||
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider.getBridgeAddresses()));
|
||||
}
|
||||
|
||||
|
|
|
@ -92,5 +92,7 @@ public class P2PModule extends AppModule {
|
|||
bindConstant().annotatedWith(named(NetworkOptionKeys.TORRC_OPTIONS)).to(environment.getRequiredProperty(NetworkOptionKeys.TORRC_OPTIONS));
|
||||
bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT));
|
||||
bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD));
|
||||
bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE));
|
||||
bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)).to(environment.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) ? true : false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,12 +43,17 @@ public class RunningTor extends TorMode {
|
|||
private final int controlPort;
|
||||
private final String password;
|
||||
private final String torDir;
|
||||
private final File cookieFile;
|
||||
private final boolean useSafeCookieAuthentication;
|
||||
|
||||
|
||||
public RunningTor(final File torDir, final int controlPort, final String password) {
|
||||
public RunningTor(final File torDir, final int controlPort, final String password, final String cookieFile,
|
||||
final boolean useSafeCookieAuthentication) {
|
||||
this.torDir = torDir.getAbsolutePath();
|
||||
this.controlPort = controlPort;
|
||||
this.password = password;
|
||||
this.cookieFile = new File(cookieFile);
|
||||
this.useSafeCookieAuthentication = useSafeCookieAuthentication;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +65,8 @@ public class RunningTor extends TorMode {
|
|||
Tor result;
|
||||
if (!password.isEmpty())
|
||||
result = new ExternalTor(controlPort, password);
|
||||
else if (cookieFile.exists())
|
||||
result = new ExternalTor(controlPort, cookieFile, useSafeCookieAuthentication);
|
||||
else
|
||||
result = new ExternalTor(controlPort);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue