From 35e68db438b049a9d11f763f59702e0570414a95 Mon Sep 17 00:00:00 2001 From: knaccc Date: Wed, 30 Jan 2019 16:42:37 +0000 Subject: [PATCH] provide option to allow server tunnel creation without having to create a directory for key storage --- README.md | 18 +++++++-------- .../org/getmonero/i2p/zero/TunnelControl.java | 22 ++++++++++++------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ffa4e6d..a268b8d 100755 --- a/README.md +++ b/README.md @@ -85,26 +85,26 @@ Note that it may take a short while for new tunnels to be set up. Call the `dist/linux/router/bin/tunnel-control.sh` script as follows to create and destroy tunnels: -#### Listen for i2p connections and forward them to the specified host and port, storing/reading the server key file in/from the specified directory. +#### Listen for I2P connections and forward them to the specified host and port. Returns the I2P base 32 destination address for the server tunnel created. -If the directory doesn't exist with a file named serverTunnelSecretKey in it, +Optionally, specify a directory for storing/reading the server key file. +If the directory doesn't exist with a file named *.b32.i2p.keys in it, returns a newly created destination address and writes the secret key for the -new address to a file called serverTunnelSecretKey in the specified directory. Otherwise, read the existing -secret key from that directory. The server tunnel will listen for i2p connections and forward them to the -specified host and port. Returns the I2P b32 destination address for the server tunnel (which deterministically depends - on the contents of the serverTunnelSecretKey file). +new address to a file called .keys in the specified directory. Otherwise, read the existing +secret key from that directory. The server tunnel will listen for I2P connections and forward them to the +specified host and port. Note that the base 32 I2P destination address deterministically depends on the contents of the .keys file). -`tunnel-control.sh server.create ` +`tunnel-control.sh server.create <(optional) directory>` #### Close the tunnel listening for connections on the specified destination public key. Returns "OK". -`tunnel-control.sh server.destroy ` +`tunnel-control.sh server.destroy ` #### Create a tunnel that listens for connections on localhost on the specified port and forwards connections over I2P to the specified destination public key. -`tunnel-control.sh client.create ` +`tunnel-control.sh client.create ` #### Close the tunnel listening for connections on the specified port. Returns "OK". diff --git a/org.getmonero.i2p.zero/src/org/getmonero/i2p/zero/TunnelControl.java b/org.getmonero.i2p.zero/src/org/getmonero/i2p/zero/TunnelControl.java index cd173f6..3d612b5 100644 --- a/org.getmonero.i2p.zero/src/org/getmonero/i2p/zero/TunnelControl.java +++ b/org.getmonero.i2p.zero/src/org/getmonero/i2p/zero/TunnelControl.java @@ -310,17 +310,23 @@ public class TunnelControl implements Runnable { case "server.create": { String destHost = args[1]; int destPort = Integer.parseInt(args[2]); - File serverTunnelConfigDir = new File(args[3]); + File serverTunnelConfigDir = null; + if(args.length>=4) serverTunnelConfigDir = new File(args[3]); File serverKeyFile; KeyPair keyPair; - if (!serverTunnelConfigDir.exists() || serverTunnelConfigDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".keys")).length == 0) { - serverTunnelConfigDir.mkdir(); + if(serverTunnelConfigDir!=null) { + if (!serverTunnelConfigDir.exists() || serverTunnelConfigDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".keys")).length == 0) { + serverTunnelConfigDir.mkdir(); + keyPair = KeyPair.gen(); + serverKeyFile = new File(serverTunnelConfigDir, keyPair.b32Dest + ".keys"); + keyPair.write(serverKeyFile.getPath()); + } else { + serverKeyFile = serverTunnelConfigDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".keys"))[0]; + keyPair = KeyPair.read(serverKeyFile.getPath()); + } + } + else { keyPair = KeyPair.gen(); - serverKeyFile = new File(serverTunnelConfigDir, keyPair.b32Dest + ".keys"); - keyPair.write(serverKeyFile.getPath()); - } else { - serverKeyFile = serverTunnelConfigDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".keys"))[0]; - keyPair = KeyPair.read(serverKeyFile.getPath()); } var tunnel = new ServerTunnel(destHost, destPort, keyPair, getTunnelControlTempDir()); tunnelList.addTunnel(tunnel);