Merge branch '161-hidden-service-directory' into 'master'

Create hidden service in a subdirectory. #161

The permissions for the parent directory are too permissive (775) for Tor 0.2.7.5. Store the hidden service hostname and private key in a subdirectory with permissions 700.

See merge request !5
This commit is contained in:
akwizgran
2015-12-09 13:21:54 +00:00

View File

@@ -108,7 +108,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
configFile = new File(torDirectory, "torrc"); configFile = new File(torDirectory, "torrc");
doneFile = new File(torDirectory, "done"); doneFile = new File(torDirectory, "done");
cookieFile = new File(torDirectory, ".tor/control_auth_cookie"); cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
hostnameFile = new File(torDirectory, "hostname"); hostnameFile = new File(torDirectory, "hs/hostname");
circuitBuilt = new AtomicBoolean(false); circuitBuilt = new AtomicBoolean(false);
} }
@@ -140,7 +140,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
} }
// Install the GeoIP database and config file if necessary // Install the GeoIP database and config file if necessary
if (!isConfigInstalled() && !installConfig()) { if (!isConfigInstalled() && !installConfig()) {
LOG.info("Could not install Tor config"); LOG.warning("Could not install Tor config");
return false; return false;
} }
LOG.info("Starting Tor"); LOG.info("Starting Tor");
@@ -354,6 +354,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
tryToClose(ss); tryToClose(ss);
return;
} }
if (!running) { if (!running) {
tryToClose(ss); tryToClose(ss);
@@ -391,14 +392,15 @@ class TorPlugin implements DuplexPlugin, EventHandler {
LOG.info("Creating hidden service"); LOG.info("Creating hidden service");
try { try {
// Watch for the hostname file being created/updated // Watch for the hostname file being created/updated
hostnameFile.getParentFile().mkdirs(); File serviceDirectory = hostnameFile.getParentFile();
serviceDirectory.mkdirs();
hostnameFile.createNewFile(); hostnameFile.createNewFile();
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
FileObserver obs = new WriteObserver(hostnameFile, latch); FileObserver obs = new WriteObserver(hostnameFile, latch);
obs.startWatching(); obs.startWatching();
// Use the control connection to update the Tor config // Use the control connection to update the Tor config
List<String> config = Arrays.asList( List<String> config = Arrays.asList(
"HiddenServiceDir " + torDirectory.getAbsolutePath(), "HiddenServiceDir " + serviceDirectory.getAbsolutePath(),
"HiddenServicePort 80 127.0.0.1:" + port); "HiddenServicePort 80 127.0.0.1:" + port);
controlConnection.setConf(config); controlConnection.setConf(config);
controlConnection.saveConf(); controlConnection.saveConf();