Class Proxy


  • public class Proxy
    extends java.lang.Object
    Redirects incoming TCP connections to other hosts/ports. All redirections are defined in a file as for example
     127.0.0.1:8888=www.ibm.com:80
     localhost:80=pop.mail.yahoo.com:110
     
    The first line forwards all requests to port 8888 on to www.ibm.com at port 80 (it also forwards the HTTP response back to the sender. The second line essentially provides a POP-3 service on port 8110, using Yahoo's POP service. This is neat when you're behind a firewall and one of the few services in the outside world that are not blocked is port 80 (HHTP).
    Note that JDK 1.4 is required for this class. Also, concurrent.jar has to be on the classpath. Note that you also need to include jsse.jar/jce.jar (same location as rt.jar) if you want SSL sockets.
    To create SSLServerSockets you'll need to do the following: Generate a certificate as follows:
     keytool -genkey -keystore /home/bela/.keystore -keyalg rsa -alias bela -storepass  -keypass 
     
    Start the Proxy as follows:
     java -Djavax.net.ssl.keyStore=/home/bela/.keystore -Djavax.net.ssl.keyStorePassword=
          -Djavax.net.ssl.trustStore=/home/bela/.keystore -Djavax.net.ssl.trustStorePassword=
          org.jgroups.util.Proxy -file /home/bela/map.properties
     
    Start client as follows:
     java -Djavax.net.ssl.trustStore=/home/bela/.keystore -Djavax.net.ssl.trustStorePassword= sslclient
     

    To import a certificate into the keystore, use the following steps:
     openssl x509 -in server.crt -out server.crt.der -outform DER
     keytool -import -trustcacerts -alias  -file server.crt.der
     
    This will store the server's certificate in the ${user.home}/.keystore key store.
    Note that an SSL client or server can be debugged by starting it as follows:
    -Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol -Djavax.net.debug=ssl

    If you run a web browser, simply enter https://: as URL to connect to an SSLServerSocket
    Note that we cannot use JDK 1.4's selectors for SSL sockets, as getChannel() on an SSL socket doesn't seem to work.
    Author:
    Bela Ban
    To do:
    Check whether SSLSocket.getChannel() or SSLServerSocket.getChannel() works.
    • Constructor Summary

      Constructors 
      Constructor Description
      Proxy​(java.net.InetAddress local, int local_port, java.net.InetAddress remote, int remote_port, boolean verbose, boolean debug)  
      Proxy​(java.net.InetAddress local, int local_port, java.net.InetAddress remote, int remote_port, boolean verbose, boolean debug, java.lang.String mapping_file)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String[] args)  
      void start()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Proxy

        public Proxy​(java.net.InetAddress local,
                     int local_port,
                     java.net.InetAddress remote,
                     int remote_port,
                     boolean verbose,
                     boolean debug)
      • Proxy

        public Proxy​(java.net.InetAddress local,
                     int local_port,
                     java.net.InetAddress remote,
                     int remote_port,
                     boolean verbose,
                     boolean debug,
                     java.lang.String mapping_file)
    • Method Detail

      • start

        public void start()
                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • main

        public static void main​(java.lang.String[] args)