2

Is it possible to use Tor network for Java application usage? For example, can I program socket program in Java to use Tor network to hide application data package exchange?

1
  • Actually all you need is SOCKS5+DNS wrapper, not a special components.
    – Alexey Vesnin
    Commented Dec 27, 2015 at 3:46

2 Answers 2

2

SilverTunnel-NG is able to provide access to the Tor Network on a Socket level.

You can checkout the Sample code here

The easiest way is to use maven and include the following dependency into your pom.xml:

<dependency>
  <groupId>org.silvertunnel-ng</groupId>
  <artifactId>netlib</artifactId>
  <version>0.0.4</version>
</dependency>
1
  • Probably don't use the project. It doesn't appear to use entry guards or many other sane protections.
    – cacahuatl
    Commented Jan 4, 2017 at 0:53
0

I use the following code to have TOR on my Java applications.

System.setProperty("java.net.preferIPv4Stack" , "true");
System.setProperty("socksProxyHost", TOR_IP);
System.setProperty("socksProxyPort", TOR_PORT);

The TOR_IP and TOR_PORT should be "127.0.0.1" and "9150" by default if you didn't mess with TOR.

I also managed to find some really old code on how to communicate with TOR to ask for a new identity through Java and created a class for it.

TorControl.java (You should change the constant COOKIE_FILE since I hard coded it)

TorReader.java

It is used like this.

TorControl tc=null;
try {
    tc = new TorControl();
    tc.authenticate();
    tc.useProxy();
} catch (Exception e) {
    System.out.println("Couldn't connect to the TOR control port "+CONTROLPORT);
}

And then when you want to change your identity simply do tc.newIdentity()

Note: tc.useProxy() will already run the first snippet I posted to make Java run with TOR.

3
  • You can use PROTOCOLINFO to discover the path of a cookie file, if one is present, rather than hardcoding the path.
    – cacahuatl
    Commented Jan 4, 2017 at 0:45
  • Also, are you aware if java handles socks5 properly, IE that it doesn't do the DNS lookups locally? Also there is already github.com/guardianproject/jtorctl for using Tor's control port which you might find more useful, and currently maintained.
    – cacahuatl
    Commented Jan 4, 2017 at 1:01
  • I don't remember if this is the one I found, but I remember that I tried to use one but it wouldn't compile, so I just rewrote the part that interested me (new identity). And about the DNS I don't really know. I never looked it up because I only used TOR to get new IPs.
    – user15719
    Commented Jan 4, 2017 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .