Ganymed library patch 75/2475/2
authorRobert Gallas <rgallas@cisco.com>
Thu, 7 Nov 2013 07:13:31 +0000 (08:13 +0100)
committerRobert Gallas <rgallas@cisco.com>
Thu, 7 Nov 2013 07:26:01 +0000 (08:26 +0100)
SSH client patch of Ganymed library to accept
to accept precreated socket.

Change-Id: Icbccba360e9a86be41cc65a04f1e7aca8c4bffca
Signed-off-by: Robert Gallas <rgallas@cisco.com>
third-party/ganymed/src/main/java/ch/ethz/ssh2/Connection.java
third-party/ganymed/src/main/java/ch/ethz/ssh2/transport/TransportManager.java

index bf742c5..786f81c 100644 (file)
@@ -60,6 +60,14 @@ public class Connection
 
     private SecureRandom generator;
 
+    private Socket precreatedSocket;
+
+    public Connection(Socket socket) {
+        this.precreatedSocket = socket;
+        this.hostname = socket.getInetAddress().getHostName();
+        this.port = socket.getPort();
+    }
+
     /**
      * Unless you know what you are doing, you will never need this.
      *
@@ -745,8 +753,14 @@ public class Connection
 
             try
             {
-                tm.clientInit(hostname, port, softwareversion, cryptoWishList, verifier, dhgexpara, connectTimeout,
-                        getOrCreateSecureRND(), proxyData);
+
+                if (precreatedSocket != null) {
+                    tm.clientInit(precreatedSocket, softwareversion, cryptoWishList, verifier, dhgexpara,
+                            getOrCreateSecureRND());
+                } else {
+                    tm.clientInit(hostname, port, softwareversion, cryptoWishList, verifier, dhgexpara, connectTimeout,
+                            getOrCreateSecureRND(), proxyData);
+                }
             }
             catch (SocketTimeoutException se)
             {
index 50e9b28..9632670 100644 (file)
@@ -551,6 +551,31 @@ public class TransportManager
         receiveThread.start();
     }
 
+    public void clientInit(Socket socket, String softwareversion, CryptoWishList cwl,
+                           ServerHostKeyVerifier verifier, DHGexParameters dhgex, SecureRandom rnd) throws IOException
+    {
+               /* First, establish the TCP connection to the SSH-2 server */
+
+        sock = socket;
+
+               /* Parse the server line and say hello - important: this information is later needed for the
+                * key exchange (to stop man-in-the-middle attacks) - that is why we wrap it into an object
+                * for later use.
+                */
+
+        ClientServerHello csh = ClientServerHello.clientHello(softwareversion, sock.getInputStream(),
+                sock.getOutputStream());
+
+        tc = new TransportConnection(sock.getInputStream(), sock.getOutputStream(), rnd);
+        String hostname = sock.getInetAddress().getHostName();
+        int port = sock.getPort();
+
+        km = new ClientKexManager(this, csh, cwl, hostname, port, verifier, rnd);
+        km.initiateKEX(cwl, dhgex, null, null);
+
+        startReceiver();
+    }
+
     public void clientInit(String hostname, int port, String softwareversion, CryptoWishList cwl,
                            ServerHostKeyVerifier verifier, DHGexParameters dhgex, int connectTimeout, SecureRandom rnd,
                            ProxyData proxyData) throws IOException