tinfoil
Class TorLib

java.lang.Object
  extended by tinfoil.TorLib

public class TorLib
extends java.lang.Object

The Onion Router(Tor) Java Library routines
It is part of the TinFoil RFID Privacy/Security system.
These methods allow us to setup an anonymized TCP socket through the Tor network and do safe anonymized DNS lookups.
This code was written with the help of Roger Dingledine and Nick Mathewson.
The code is open-source under the MIT X11 license.
Documentation on the API can be found at http://web.mit.edu/foley/www/TinFoil/Docs/

Version:
1.0

Author:
Joe Foley, MIT AutoID Labs

Field Summary
(package private) static java.lang.String proxyAddr
          Default TOR Proxy hostaddr.
(package private) static int proxyPort
          Default TOR Proxy port.
(package private) static byte SOCKS_DELIM
          SOCKS uses Nulls as field delimiters
(package private) static byte SOCKS_VERSION
          Constant indicates what SOCKS version are talking Either SOCKS4 or SOCKS4a
(package private) static int SOCKS4A_FAKEIP
          Setting the IP field to 0.0.0.1 causes SOCKS4a to be enabled.
(package private) static byte TOR_CONNECT
          Constant tells SOCKS4/4a to connect.
(package private) static byte TOR_RESOLVE
          Constant tells TOR to do a DNS resolve.
 
Constructor Summary
TorLib()
           
 
Method Summary
static void main(java.lang.String[] args)
          This method allows you to demo/access the resolver/socket generation from the command line.
(package private) static java.lang.String ParseSOCKSStatus(byte status)
          This helper method allows us to decode the SOCKS4 status codes into Human readible input.
Based upon info from http://archive.socks.permeo.com/protocol/socks4.protocol
(package private) static java.lang.String TorResolve(java.lang.String targetHostname)
          This method opens a TOR socket, and does an anonymous DNS resolve through it.
(package private) static java.net.Socket TorSocket(java.lang.String targetHostname, int targetPort)
          This method creates a socket to the target host and port using TorSocketPre, then reads the SOCKS information.
(package private) static java.net.Socket TorSocketPre(java.lang.String targetHostname, int targetPort, byte req)
          This method Creates a socket, then sends the inital SOCKS request info It stops before reading so that other methods may differently interpret the results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proxyPort

static int proxyPort
Default TOR Proxy port.


proxyAddr

static java.lang.String proxyAddr
Default TOR Proxy hostaddr.


TOR_CONNECT

static final byte TOR_CONNECT
Constant tells SOCKS4/4a to connect. Use it in the req parameter.

See Also:
Constant Field Values

TOR_RESOLVE

static final byte TOR_RESOLVE
Constant tells TOR to do a DNS resolve. Use it in the req parameter.

See Also:
Constant Field Values

SOCKS_VERSION

static final byte SOCKS_VERSION
Constant indicates what SOCKS version are talking Either SOCKS4 or SOCKS4a

See Also:
Constant Field Values

SOCKS_DELIM

static final byte SOCKS_DELIM
SOCKS uses Nulls as field delimiters

See Also:
Constant Field Values

SOCKS4A_FAKEIP

static final int SOCKS4A_FAKEIP
Setting the IP field to 0.0.0.1 causes SOCKS4a to be enabled.

See Also:
Constant Field Values
Constructor Detail

TorLib

public TorLib()
Method Detail

main

public static void main(java.lang.String[] args)
This method allows you to demo/access the resolver/socket generation from the command line. Run with "-h" to get the help menu.

Parameters:
args - Command line arguments for test main method.

TorSocketPre

static java.net.Socket TorSocketPre(java.lang.String targetHostname,
                                    int targetPort,
                                    byte req)
                             throws java.io.IOException
This method Creates a socket, then sends the inital SOCKS request info It stops before reading so that other methods may differently interpret the results. It returns the open socket.

Parameters:
targetHostname - The hostname of the destination host.
targetPort - The port to connect to
req - SOCKS/TOR request code
Returns:
An open Socket that has been sent the SOCK4a init codes.
Throws:
java.io.IOException - from any Socket problems

TorSocket

static java.net.Socket TorSocket(java.lang.String targetHostname,
                                 int targetPort)
                          throws java.io.IOException
This method creates a socket to the target host and port using TorSocketPre, then reads the SOCKS information.

Parameters:
targetHostname - Hostname of destination host.
targetPort - Port on remote destination host.
Returns:
Fully initialized TCP Socket that tunnels to the target Host/Port via the Tor Proxy host/port.
Throws:
java.io.IOException - when Socket and Read/Write exceptions occur.

TorResolve

static java.lang.String TorResolve(java.lang.String targetHostname)
This method opens a TOR socket, and does an anonymous DNS resolve through it. Since Tor caches things, this is a very fast lookup if we've already connected there The resolve does a gethostbyname() on the exit node.

Parameters:
targetHostname - String containing the hostname to look up.
Returns:
String representation of the IP address: "x.x.x.x"

ParseSOCKSStatus

static java.lang.String ParseSOCKSStatus(byte status)
This helper method allows us to decode the SOCKS4 status codes into Human readible input.
Based upon info from http://archive.socks.permeo.com/protocol/socks4.protocol

Parameters:
status - Byte containing the status code.
Returns:
String human-readible representation of the error.