Java Socks Proxy in Applets – Tor

This is an example of remotely loading an image from a Tor Hidden Service into a Java applet to display for a user not using the Tor Client.

Let’s start with the web server set up. This is where the applet and Tor Client/Privoxy will be hosted.

Step 1) With a web server of your choosing Apache, Nginx, PHP, install and configure a Tor Client and Privoxy Service on this web server. This is what our applet will use to access the image on the .onion service.

apt-get install tor
apt-get install privoxy

Edit /etc/privoxy/config add the following

forward-socks4a / localhost:9050 .

Also change the listen-address for privoxy to the webserver IP.

listen-address  xx.xxx.xxx.xxx:8118

Step 2) Configure a Tor hidden web service on another system preferably another network and place an image that will be requested by the applet.

You will need the .onion domain address for the applet. See the Tor docs on configuring a Tor hidden service.

Step 3) On your development system compile and self sign the Java code (the code will be posted below).

Quick guide to self sign the code

javac LoadImage.java
jar cvf LoadImage.jar LoadImage.class
keytool -genkey -validity 3650 -keystore pKeyStore -alias keyName
keytool -selfcert -keystore pKeyStore -alias keyName -validity 3650
jarsigner -keystore pKeyStore LoadImage.jar keyName

Upload and embed the jar file in an html page on the web server. View the web page and accept any security issues that occur by self signed applets. You will likely need to approve the IP or Domain for the web server the applet will be hosted on in your JRE security settings. To do this on a windows system: Go To *Start Menu >> Java >> Configure Java >> Security >> Edit site list >> copy and paste your web server IP/Domain with http

LoadImage.java

import java.awt.Image;
import javax.imageio.*;
import java.io.*;
import java.net.*;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.lang.*;

public class LoadImage extends JApplet 
{
	Image image;
	public LoadImage()
	{
		try {	
			SocketAddress address = new InetSocketAddress("xx.xx.xxx.xx", 8118);
			Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
		
			URL url = new URL("http://1234ABCD.onion/mabo/static/mountains.png");
			URLConnection conn = url.openConnection(proxy);
            
			InputStream inStream = conn.getInputStream();
                        BufferedImage image = ImageIO.read(inStream);
			
			JLabel label = new JLabel(new ImageIcon(image));
			label.setMinimumSize(new Dimension(200, 200));
			
			this.add(label);
			setVisible(true);
		}
		catch (Exception e) {
                        e.printStackTrace();
                }
	}
}

The HTML code used to display the jarred applet

<applet archive="LoadImage.jar" codebase="http://tofolderwithapplet/cryaboutit/static/" code="LoadImage.class" width="420" height="280"></applet>

———————–

All articles from bottom(start) to top(end)

http://www.techshinobi.com/index.php/actionscript-pycurl-socks-part-3/
http://www.techshinobi.com/index.php/actionscript-pycurl-socks-part-2/
http://www.techshinobi.com/index.php/actionscript-pycurl-and-socks/
http://www.techshinobi.com/index.php/java-socks-proxy-in-applets-tor/