Use same private_key in NewTor and RunningTor mode

This commit is contained in:
Florian Reimair 2018-11-27 03:34:24 +01:00
parent 5a8731c8a5
commit b38f31239a
4 changed files with 14 additions and 26 deletions

View File

@ -47,7 +47,6 @@ configure(subprojects) {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://raw.githubusercontent.com/JesusMcCloud/tor-binary/8.0.3/release/' }
}
dependencies {
@ -188,10 +187,10 @@ configure(project(':common')) {
configure(project(':p2p')) {
dependencies {
compile project(':common')
compile('com.github.JesusMcCloud.netlayer:tor.native:0.6') {
compile('com.github.JesusMcCloud.netlayer:tor.native:0.6.1') {
exclude(module: 'slf4j-api')
}
compile('com.github.JesusMcCloud.netlayer:tor.external:0.6') {
compile('com.github.JesusMcCloud.netlayer:tor.external:0.6.1') {
exclude(module: 'slf4j-api')
}
compile('org.apache.httpcomponents:httpclient:4.5.3') {

View File

@ -47,21 +47,12 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class NewTor extends TorMode {
/**
* <code>Netlayer</code> stores its hidden service files in a custom
* subdirectory of <code>$torDir/hiddenservice/</code>. Note that the
* {@link HiddenServiceSocket} does add this part on its own, hence,
* {@link NewTor#getHiddenServiceDirectory()} returns only the custom
* subdirectory (which happens to be <code>""</code>)
*/
private static final String HIDDEN_SERVICE_DIRECTORY = "hiddenservice";
private final String torrcFile;
private final String torrcOptions;
private final Collection<String> bridgeEntries;
public NewTor(File torWorkingDirectory, String torrcFile, String torrcOptions, Collection<String> bridgeEntries) {
super(torWorkingDirectory, HIDDEN_SERVICE_DIRECTORY);
super(torWorkingDirectory);
this.torrcFile = torrcFile;
this.torrcOptions = torrcOptions;
this.bridgeEntries = bridgeEntries;

View File

@ -40,7 +40,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class RunningTor extends TorMode {
private static final String EXTERNAL_TOR_HIDDEN_SERVICE = "externalTorHiddenService";
private final int controlPort;
private final String password;
private final File cookieFile;
@ -49,7 +48,7 @@ public class RunningTor extends TorMode {
public RunningTor(final File torDir, final int controlPort, final String password, final String cookieFile,
final boolean useSafeCookieAuthentication) {
super(torDir, EXTERNAL_TOR_HIDDEN_SERVICE);
super(torDir);
this.controlPort = controlPort;
this.password = password;
this.cookieFile = new File(cookieFile);
@ -81,7 +80,7 @@ public class RunningTor extends TorMode {
@Override
public String getHiddenServiceDirectory() {
return new File(torDir, EXTERNAL_TOR_HIDDEN_SERVICE).getAbsolutePath();
return new File(torDir, HIDDEN_SERVICE_DIRECTORY).getAbsolutePath();
}
}

View File

@ -35,11 +35,11 @@ import bisq.common.storage.FileUtil;
public abstract class TorMode {
/**
* The directory where the <code>private_key</code> file sits in. Kept private,
* because it is only valid for the {@link TorMode#doRollingBackup()} due to the
* inner workings of the <code>Netlayer</code> dependency.
* The sub-directory where the <code>private_key</code> file sits in. Kept
* private, because it only concerns implementations of {@link TorMode}.
*/
private final File hiddenServiceDirectory;
protected static final String HIDDEN_SERVICE_DIRECTORY = "hiddenservice";
protected final File torDir;
/**
@ -51,9 +51,8 @@ public abstract class TorMode {
* necessarily equal
* {@link TorMode#getHiddenServiceDirectory()}.
*/
public TorMode(File torDir, String hiddenServiceDir) {
public TorMode(File torDir) {
this.torDir = torDir;
this.hiddenServiceDirectory = new File(torDir, hiddenServiceDir);
}
/**
@ -70,9 +69,9 @@ public abstract class TorMode {
* other stuff to the hiddenServiceDir, thus, selecting nothing (i.e.
* <code>""</code>) as a hidden service directory is fine. {@link ExternalTor},
* however, does not have a Tor installation path and thus, takes the hidden
* service path literally. Hence, we set
* <code>"torDir/externalTorHiddenService"</code> as the hidden service
* directory.
* service path literally. Hence, we set <code>"torDir/hiddenservice"</code> as
* the hidden service directory. By doing so, we use the same
* <code>private_key</code> file as in {@link NewTor} mode.
*
* @return <code>""</code> in {@link NewTor} Mode,
* <code>"torDir/externalTorHiddenService"</code> in {@link RunningTor}
@ -84,7 +83,7 @@ public abstract class TorMode {
* Do a rolling backup of the "private_key" file.
*/
protected void doRollingBackup() {
FileUtil.rollingBackup(hiddenServiceDirectory, "private_key", 20);
FileUtil.rollingBackup(new File(torDir, HIDDEN_SERVICE_DIRECTORY), "private_key", 20);
}
}