Commit 00a3931e authored by zeroleak's avatar zeroleak
Browse files

add cli.torConfig.customTorrc

parent c7f5f4e6
......@@ -62,11 +62,16 @@ cli.torConfig.executable = /path/to/bin/tor
- Use `local` to detect a local tor install.
- Use custom path to `tor` binary to use your own tor build.
Custom config can be appended to Torrc with:
```
cli.torConfig.onionServer = true
cli.torConfig.onionBackend = true
cli.torConfig.customTorrc = /path/to/torrc
```
Tor mode can be customized with:
```
cli.torConfig.onionServer = true # whirlpool server
cli.torConfig.onionBackend = true # wallet backend
```
When tor enabled, connect to whirlpool server or wallet backend through:
- `true`: Tor hidden services
- `false`: clearnet over Tor
......
......@@ -9,6 +9,8 @@ import com.samourai.whirlpool.cli.utils.CliUtils;
import com.samourai.whirlpool.client.exception.NotifiableException;
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
......@@ -239,8 +241,18 @@ public class JavaTorClient {
return torInstance;
}
private TorSettings computeTorSettings() {
TorSettings torSettings = new JavaTorSettings(cliConfig.getCliProxy());
private TorSettings computeTorSettings() throws Exception {
String customTorrc = null;
String customTorrcFilename = cliConfig.getTorConfig().getCustomTorrc();
if (!StringUtils.isEmpty(customTorrcFilename)) {
try {
customTorrc = new String(Files.readAllBytes(Paths.get(customTorrcFilename)));
} catch (Exception e) {
throw new NotifiableException(
"Cannot read cli.torConfig.customTorrc file: " + customTorrcFilename, e);
}
}
TorSettings torSettings = new JavaTorSettings(cliConfig.getCliProxy(), customTorrc);
return torSettings;
}
}
......@@ -7,9 +7,16 @@ import java.util.Optional;
public class JavaTorSettings extends DefaultSettings {
private CliProxy cliProxy;
private String customTorrc;
public JavaTorSettings(Optional<CliProxy> cliProxy) {
public JavaTorSettings(Optional<CliProxy> cliProxy, String customTorrc) {
this.cliProxy = cliProxy.orElse(null);
this.customTorrc = customTorrc;
}
@Override
public String getCustomTorrc() {
return customTorrc;
}
@Override
......
......@@ -362,6 +362,7 @@ public abstract class CliConfigFile {
private CliTorExecutableMode executableMode;
@NotEmpty private boolean onionServer;
@NotEmpty private boolean onionBackend;
private String customTorrc;
public TorConfig() {}
......@@ -369,6 +370,7 @@ public abstract class CliConfigFile {
this.executable = copy.executable;
this.onionServer = copy.onionServer;
this.onionBackend = copy.onionBackend;
this.customTorrc = copy.customTorrc;
}
public String getExecutable() {
......@@ -404,11 +406,20 @@ public abstract class CliConfigFile {
this.onionBackend = onionBackend;
}
public String getCustomTorrc() {
return customTorrc;
}
public void setCustomTorrc(String customTorrc) {
this.customTorrc = customTorrc;
}
public Map<String, String> getConfigInfo() {
Map<String, String> configInfo = new HashMap<>();
configInfo.put("cli/tor/executable", executable);
configInfo.put("cli/tor/onionServer", Boolean.toString(onionServer));
configInfo.put("cli/tor/onionBackend", Boolean.toString(onionBackend));
configInfo.put("cli/tor/customTorrc", customTorrc != null ? customTorrc : "null");
return configInfo;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment