comparison app/src/main/java/ch/ethz/ssh2/transport/ClientTransportManager.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/transport/ClientTransportManager.java@63b23b7c840d
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 package ch.ethz.ssh2.transport;
2
3 import java.io.IOException;
4 import java.net.InetSocketAddress;
5 import java.net.Socket;
6 import java.security.SecureRandom;
7
8 import ch.ethz.ssh2.DHGexParameters;
9 import ch.ethz.ssh2.ServerHostKeyVerifier;
10 import ch.ethz.ssh2.crypto.CryptoWishList;
11
12 /**
13 * @version $Id: ClientTransportManager.java 151 2014-04-28 10:03:39Z dkocher@sudo.ch $
14 */
15 public class ClientTransportManager extends TransportManager {
16
17 private final Socket sock;
18
19 public ClientTransportManager(final Socket socket) {
20 super(socket);
21 this.sock = socket;
22 }
23
24 public void setTcpNoDelay(boolean state) throws IOException {
25 sock.setTcpNoDelay(state);
26 }
27
28 public void setSoTimeout(int timeout) throws IOException {
29 sock.setSoTimeout(timeout);
30 }
31
32 public void connect(String hostname, int port, String softwareversion, CryptoWishList cwl,
33 ServerHostKeyVerifier verifier, DHGexParameters dhgex, int connectTimeout, SecureRandom rnd)
34 throws IOException {
35 // Establish the TCP connection to the SSH-2 server
36 this.connect(hostname, port, connectTimeout);
37 // Parse the server line and say hello - important: this information is later needed for the
38 // key exchange (to stop man-in-the-middle attacks) - that is why we wrap it into an object
39 // for later use.
40 ClientServerHello csh = ClientServerHello.clientHello(softwareversion, sock.getInputStream(),
41 sock.getOutputStream());
42 TransportConnection tc = new TransportConnection(sock.getInputStream(), sock.getOutputStream(), rnd);
43 KexManager km = new ClientKexManager(this, csh, cwl, hostname, port, verifier, rnd);
44 super.init(tc, km);
45 km.initiateKEX(cwl, dhgex, null, null, null);
46 this.startReceiver();
47 }
48
49 protected void connect(String hostname, int port, int connectTimeout) throws IOException {
50 log.debug(String.format("client transport manager connecting to %s:%d", hostname, port));
51 sock.connect(new InetSocketAddress(hostname, port), connectTimeout);
52 log.debug(String.format("client transport manager connected to %s:%d", hostname, port));
53 }
54 }