Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/transport/ClientServerHello.java @ 307:071eccdff8ea ganymed
fix java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:16:58 -0700 |
parents | 91a31873c42a |
children | 097cfe8770dd |
comparison
equal
deleted
inserted
replaced
305:d2b303406d63 | 307:071eccdff8ea |
---|---|
25 this.client_line = client_line; | 25 this.client_line = client_line; |
26 this.server_line = server_line; | 26 this.server_line = server_line; |
27 } | 27 } |
28 | 28 |
29 public static ClientServerHello clientHello(String softwareversion, InputStream bi, OutputStream bo) | 29 public static ClientServerHello clientHello(String softwareversion, InputStream bi, OutputStream bo) |
30 throws IOException { | 30 throws IOException { |
31 return exchange(softwareversion, bi, bo, true); | 31 return exchange(softwareversion, bi, bo, true); |
32 } | 32 } |
33 | 33 |
34 public static ClientServerHello serverHello(String softwareversion, InputStream bi, OutputStream bo) | 34 public static ClientServerHello serverHello(String softwareversion, InputStream bi, OutputStream bo) |
35 throws IOException { | 35 throws IOException { |
36 return exchange(softwareversion, bi, bo, false); | 36 return exchange(softwareversion, bi, bo, false); |
37 } | 37 } |
38 | 38 |
39 private static ClientServerHello exchange(String softwareversion, InputStream bi, OutputStream bo, boolean clientMode) | 39 private static ClientServerHello exchange(String softwareversion, InputStream bi, OutputStream bo, boolean clientMode) |
40 throws IOException { | 40 throws IOException { |
41 String localIdentifier = String.format("SSH-2.0-%s", softwareversion); | 41 String localIdentifier = String.format("SSH-2.0-%s", softwareversion); |
42 | |
43 bo.write(StringEncoder.GetBytes(String.format("%s\r\n", localIdentifier))); | 42 bo.write(StringEncoder.GetBytes(String.format("%s\r\n", localIdentifier))); |
44 bo.flush(); | 43 bo.flush(); |
45 | |
46 // Expect SSH-protoversion-softwareversion SP comments CR LF | 44 // Expect SSH-protoversion-softwareversion SP comments CR LF |
47 String remoteIdentifier = new LineNumberReader(new InputStreamReader(bi)).readLine(); | 45 String remoteIdentifier = new LineNumberReader(new InputStreamReader(bi)).readLine(); |
48 if(null == remoteIdentifier) { | 46 |
47 if (null == remoteIdentifier) { | |
49 throw new IOException("Premature connection close"); | 48 throw new IOException("Premature connection close"); |
50 } | 49 } |
51 if(!remoteIdentifier.startsWith("SSH-")) { | 50 |
51 if (!remoteIdentifier.startsWith("SSH-")) { | |
52 throw new IOException(String.format("Malformed SSH identification %s", remoteIdentifier)); | 52 throw new IOException(String.format("Malformed SSH identification %s", remoteIdentifier)); |
53 } | 53 } |
54 if(!remoteIdentifier.startsWith("SSH-1.99-") | 54 |
55 if (!remoteIdentifier.startsWith("SSH-1.99-") | |
55 && !remoteIdentifier.startsWith("SSH-2.0-")) { | 56 && !remoteIdentifier.startsWith("SSH-2.0-")) { |
56 throw new IOException(String.format("Incompatible remote protocol version %s", remoteIdentifier)); | 57 throw new IOException(String.format("Incompatible remote protocol version %s", remoteIdentifier)); |
57 } | 58 } |
58 if(clientMode) { | 59 |
60 if (clientMode) { | |
59 return new ClientServerHello(localIdentifier, remoteIdentifier); | 61 return new ClientServerHello(localIdentifier, remoteIdentifier); |
60 } | 62 } |
61 else { | 63 else { |
62 return new ClientServerHello(remoteIdentifier, localIdentifier); | 64 return new ClientServerHello(remoteIdentifier, localIdentifier); |
63 } | 65 } |