diff --git a/components/net/sf/briar/plugins/tor/TorPlugin.java b/components/net/sf/briar/plugins/tor/TorPlugin.java index fb9fbee5f55ec3cec0c597c52b0862fc6f30cc1d..96130acf8c6809f1b70e3a47e1d061b60068cf94 100644 --- a/components/net/sf/briar/plugins/tor/TorPlugin.java +++ b/components/net/sf/briar/plugins/tor/TorPlugin.java @@ -26,7 +26,6 @@ import org.silvertunnel.netlib.api.util.TcpipNetAddress; import org.silvertunnel.netlib.layer.tor.TorHiddenServicePortPrivateNetAddress; import org.silvertunnel.netlib.layer.tor.TorHiddenServicePrivateNetAddress; import org.silvertunnel.netlib.layer.tor.TorNetLayerUtil; -import org.silvertunnel.netlib.layer.tor.TorNetServerSocket; import org.silvertunnel.netlib.layer.tor.util.Encryption; import org.silvertunnel.netlib.layer.tor.util.RSAKeyPair; @@ -94,9 +93,9 @@ class TorPlugin implements DuplexPlugin { NetLayer nl = netFactory.getNetLayerById(NetLayerIDs.TOR); nl.waitUntilReady(); // Publish the hidden service - TorNetServerSocket ss; + NetServerSocket ss; try { - ss = (TorNetServerSocket) nl.createNetServerSocket(null, addrPort); + ss = nl.createNetServerSocket(null, addrPort); } catch(IOException e) { if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); return; diff --git a/test/net/sf/briar/plugins/tor/TorPluginTest.java b/test/net/sf/briar/plugins/tor/TorPluginTest.java index 9f25e82f697ec9d4a03c4f1395367c46cf0c7926..c7f3fef756e88f8c86db8a56203a3f68184209fb 100644 --- a/test/net/sf/briar/plugins/tor/TorPluginTest.java +++ b/test/net/sf/briar/plugins/tor/TorPluginTest.java @@ -49,6 +49,37 @@ public class TorPluginTest extends BriarTestCase { clientPlugin.stop(); } + @Test + public void testStoreAndRetrievePrivateKey() throws Exception { + Executor e = Executors.newCachedThreadPool(); + // Start a plugin instance with no private key + Callback callback = new Callback(); + TorPlugin plugin = new TorPlugin(e, callback, 0L); + plugin.start(); + // The plugin should create a hidden service... eventually + callback.latch.await(5, TimeUnit.MINUTES); + String onion = callback.local.get("onion"); + assertNotNull(onion); + assertTrue(onion.endsWith(".onion")); + // Get the PEM-encoded private key and stop the plugin + String privateKey = callback.config.get("privateKey"); + assertNotNull(privateKey); + plugin.stop(); + // Start another instance, reusing the private key + callback = new Callback(); + callback.config.put("privateKey", privateKey); + plugin = new TorPlugin(e, callback, 0L); + plugin.start(); + // The plugin should create a hidden service... eventually + callback.latch.await(5, TimeUnit.MINUTES); + // The onion URL should be the same + assertEquals(onion, callback.local.get("onion")); + // The private key should be the same + assertEquals(privateKey, callback.config.get("privateKey")); + // Stop the plugin + plugin.stop(); + } + private static class Callback implements DuplexPluginCallback { private final Map<ContactId, TransportProperties> remote =