Giter Site home page Giter Site logo

tor-research-framework's Introduction

tor-research-framework

by Gareth Owen ([email protected] - www.ghowen.me)

LICENCE: GNU GPL v3

Contributors

Introduction

The framework is a Java Tor client that is designed to be easy to read and modify at the code level. There are a number of examples in the examples directory on how to use the framework. Modifying the core framework code should be relatively straight forward for someone loosely familiar with the Tor protocol.

The easiest way to get started is to import the project into IntelliJ and hopefully maven should fetch all the dependencies for you. IntelliJ will require the tor module's Language Level to be set to at least 7.0 to compile the multi-catch statements used by the project (File-Project Structure-Language Level). Additionally, you need to add the project root to the class path so that the logging library picks up the configuration file, this can be done under File->Project Structure->Modules->Dependancies and click the + on the far right.

Before you do anything, you'll need a copy of the Consensus from a directory authority (which contains a list of nodes in the Tor network). Code:

Consensus con = Consensus.getConsensus();

After this, you need to pick a guard node.

OnionRouter guard = con.getRouterByName("southsea0");

Now you can connect into the tor network using TorSocket:

TorSocket sock = new TorSocket(guard);

and now, presumably, you'll want to build a circuit:

TorCircuit circ = sock.createCircuit(true);

the true option makes most calls to circ blocking until they have succeeded, you'll know if you want this or not (if you don't use blocking, you can optionally use circ.waitForState()). At this stage, a circuit isn't built, for that you can take one of two approaches as shown below:

circ.createRoute("tor26,turtles");

OR

circ.create()
// .. optionally more extends ..
// circ.extend(con.getORWithFlag("Running");
circ.extend(con.getORWithFlag("Exit,Running".split(","), port);

Once you've got a circuit built, you can create a TorStream:

TorStream stream = circ.createStream("hostname", port, optionalListenerForEvents);

If you choose not to use the listener, you can use stream.waitForState() to wait for it to be in various states before reading. If its READY then the connection is established, and if its DESTROYED the the connection was closed. Note, do not perform blocking reads inside the listener, or any other time consuming activity as you'll be blocking the main Tor receive thread.

Now you can use the traditional Java Input/OutputStream pattern:

stream.getInputStream();
stream.getOutputStream();

see SimpleExample for a complete example.

Hidden Service Usage

See the example provided. Lots of useful functions in HiddenService class.

Output

We use the Apache log4j2 library for logging output which allows you to configure the amount of output the library produces and where this output goes (e.g. to Console/file/socket/etc). The logging level is set the in log4j2.xml file (WHICH MUST BE IN CLASSPATH!), and valid log levels are: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE.

By default, the log level is set to DEBUG, output is sent to ERR and each message will show the class and method that produced that output. Trace shows the highest level, including received and sent packets.

You can do filtering of log messages - for more info please see the log4j2 homepage.

Advanced Usage

TorSocket creates one thread in TorSocket constructor to process incoming cells, which it'll then automatically handle by passing them off to the respective TorCircuit.handleReceived(). TorCircuit.handleReceived() will pass them to the appropriate TorStream() if necessary.

To send a custom packet down a circuit, you can use:

circ.send(payload, RELAY_*, false, (short)streamID);

This will package the payload in a RELAY cell and encrypt it all the way to the last hop and then send it.

To send a raw cell to the first hop, construct a Cell(circId, cmdId, payload) object and call TorSocket.sendCell().

Troubleshooting

You need the following dependencies installed: apache commons and bouncycastle.

Routers go up and down, if you're just trying the examples, then be aware the hardcoded routers might be offline. Other routers may provide unexpected responses, or refuse connections temporarily. Try running the example again.

tor-research-framework's People

Contributors

owenson avatar twilsonb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.