EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Java - problems with dynamic port forwarding

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#29500
Posted: 05/20/2014 11:34:59
by  Max
Hello, I am trying to use SecureBlackbox to do dynamic port forwarding. However, I cannot seem to be able to create a local SOCKS server. Here is my code:

Code
        TElSSHLocalPortForwarding Client;
        int SSHPort, forwardedPort;
        String host, username, password;
        
        Client = null;
        SSHPort = 22;
        forwardedPort = 9150;
        host = "<SSH server>";
        username = "<login>";
        password = "<password>";
        
        try {
            Client = new TElSSHLocalPortForwarding();
            Client.SetAddress(host);
            Client.SetPort(SSHPort);

            Client.SetUsername(username);
            Client.SetPassword(password);

            Client.SetUseDynamicForwarding(true);
            Client.SetForwardedPort(forwardedPort);
            
            Client.SetSocketTimeout(1000);
            Client.SetOnKeyValidate(new TSSHKeyValidateEvent(new TSSHKeyValidateEvent.Callback() {
                @Override
                public boolean TSSHKeyValidateEventCallback(TObject arg0, TElSSHKey arg1) {
                    System.out.println("Server key received");
                    return true;
                }
            }));
            Client.Open();
        } catch (Exception exc) {
            System.out.println("BlackBox SSH: " + exc.toString());
        }

        BufferedReader reader;
        try {
            HttpsURLConnection con = connectFunctions.request("https://google.com", "GET", null, "", null, "", connectFunctions.connectToProxy("127.0.0.1:" + forwardedPort, "socks"));
            reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            for (String line; (line = reader.readLine()) != null;){
                System.out.println(line);
            }
        } catch (java.io.IOException exc) {
            System.out.println("Connection: " + exc.toString());
        }


As you see, I'm trying to create a dynamic port forwarding connection to the server and then connect to the created local SOCKS port to with HttpsURLConnection. However, this doesn't work. It seems that the SOCKS server wasn't up. The error gets thrown up in the second try block on reader = new BufferedReader(new InputStreamReader(con.getInputStream())); and it is java.net.SocketException: Connection refused: connect.
Any clue on what might be wrong with my code? I thought I followed the sample code more or less well... =(
#29501
Posted: 05/20/2014 11:49:09
by Eugene Mayevski (EldoS Corp.)

We don't sell our software to russia.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 382 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!