annotate src/ch/ethz/ssh2/ServerConnection.java @ 368:b198ea5c5ffd

debug kex error
author Carl Byington <carl@five-ten-sg.com>
date Mon, 04 Aug 2014 11:05:00 -0700
parents 37f4a3b506d9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 * Copyright (c) 2012-2013 Christian Plattner. All rights reserved.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 * Please refer to the LICENSE.txt for licensing details.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 package ch.ethz.ssh2;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 import java.io.CharArrayWriter;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 import java.io.File;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 import java.io.FileReader;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 import java.io.IOException;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 import java.net.Socket;
301
ca5dd224a87b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 300
diff changeset
13 import java.util.List;
ca5dd224a87b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 300
diff changeset
14 import java.util.ArrayList;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 import ch.ethz.ssh2.crypto.CryptoWishList;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 import ch.ethz.ssh2.crypto.PEMDecoder;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 import ch.ethz.ssh2.server.ServerConnectionState;
281
b4ca341c318d start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
19 import java.security.KeyPair;
b4ca341c318d start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
20 import java.security.PrivateKey;
b4ca341c318d start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
21 import java.security.interfaces.DSAPrivateKey;
b4ca341c318d start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 278
diff changeset
22 import java.security.interfaces.ECPrivateKey;
278
d7e088fa2123 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 273
diff changeset
23 import java.security.interfaces.RSAPrivateKey;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 import ch.ethz.ssh2.transport.ServerTransportManager;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 * A server-side SSH-2 connection.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 * @author Christian
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 *
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 */
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
32 public class ServerConnection {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
33 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
34 * The softwareversion presented to the SSH-2 client.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
35 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
36 private String softwareversion = String.format("Ganymed_SSHD_%s", Version.getSpecification());
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
38 private final ServerConnectionState state = new ServerConnectionState(this);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
40 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
41 * Creates a new <code>ServerConnection</code> that will communicate
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
42 * with the client over the given <code>Socket</code>.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
43 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
44 * Note: you need to call {@link #connect()} or {@link #connect(int)} to
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
45 * perform the initial handshake and establish the encrypted communication.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
46 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
47 * @see #connect(int)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
48 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
49 * @param s The socket
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
50 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
51 public ServerConnection(Socket s) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
52 this(s, null, null, null);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
53 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 public ServerConnection(Socket s, String softwareversion) {
301
ca5dd224a87b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 300
diff changeset
56 this(s, null, null, null);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 this.softwareversion = softwareversion;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 /**
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
61 * Creates a new <code>ServerConnection</code> that will communicate
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
62 * with the client over the given <code>Socket</code>.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
63 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
64 * Note: you need to call {@link #connect()} or {@link #connect(int)} to
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
65 * perform the initial handshake and establish the encrypted communication.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
66 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
67 * Please read the javadoc for the {@link #connect(int)} method.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
68 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
69 * @see #connect(int)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
70 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
71 * @param s The socket
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
72 * @param dsa_key The DSA hostkey, may be <code>NULL</code>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
73 * @param rsa_key The RSA hostkey, may be <code>NULL</code>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
74 * @param ec_key The EC hostkey, may be <code>NULL</code>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
75 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
76 public ServerConnection(Socket s, KeyPair dsa_key, KeyPair rsa_key, KeyPair ec_key) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
77 state.s = s;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
78 state.softwareversion = softwareversion;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
79 state.next_dsa_key = dsa_key;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
80 state.next_rsa_key = rsa_key;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
81 state.next_ec_key = ec_key;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
82 fixCryptoWishList(state.next_cryptoWishList, state.next_dsa_key, state.next_rsa_key, state.next_ec_key);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
83 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
85 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
86 * Establish the connection and block until the first handshake has completed.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
87 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
88 * Note: this is a wrapper that calls <code>connect(0)</code> (i.e., connect with no timeout).
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
89 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
90 * Please read the javadoc for the {@link #connect(int)} method.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
91 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
92 * @see #connect(int)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
93 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
94 * @throws IOException
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
95 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
96
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
97 public synchronized void connect() throws IOException {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
98 connect(0);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
99 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
101 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
102 * Establish the connection and block until the first handshake has completed.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
103 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
104 * Note 1: at least one DSA, RSA or EC hostkey must be set before calling this method.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
105 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
106 * Note 2: You must set the callbacks for authentication ({@link #setAuthenticationCallback(ServerAuthenticationCallback)})
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
107 * and connection events ({@link #setServerConnectionCallback(ServerConnectionCallback)}).
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
108 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
109 * @see #setPEMHostKey(char[], String)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
110 * @see #setPEMHostKey(File, String)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
111 * @see #setRsaHostKey(RSAPrivateKey)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
112 * @see #setDsaHostKey(DSAPrivateKey)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
113 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
114 * @param timeout_milliseconds Timeout in milliseconds, <code>0</code> means no timeout.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
115 * @throws IOException
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
116 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
118 public synchronized void connect(int timeout_milliseconds) throws IOException {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
119 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
120 if (state.cb_conn == null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
121 throw new IllegalStateException("The callback for connection events has not been set.");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
122
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
123 if (state.cb_auth == null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
124 throw new IllegalStateException("The callback for authentication events has not been set.");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
125
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
126 if (state.tm != null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
127 throw new IllegalStateException("The initial handshake has already been started.");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
128
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
129 if ((state.next_dsa_key == null) && (state.next_rsa_key == null) && (state.next_ec_key == null))
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
130 throw new IllegalStateException("Neither an RSA nor a DSA nor an EC host key has been specified!");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
132 state.tm = new ServerTransportManager(state.s);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
133 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
135 state.tm.connect(state);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
136 /* Wait until first KEX has finished */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
137 state.tm.getConnectionInfo(1);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
138 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
140 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
141 * Retrieve the underlying socket.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
142 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
143 * @return the socket that has been passed to the constructor.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
144 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
145 public Socket getSocket() {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
146 return state.s;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
147 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
149 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
150 * Force an asynchronous key re-exchange (the call does not block). The
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
151 * latest values set for MAC, Cipher and DH group exchange parameters will
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
152 * be used. If a key exchange is currently in progress, then this method has
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
153 * the only effect that the so far specified parameters will be used for the
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
154 * next (client driven) key exchange. You may call this method only after
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
155 * the initial key exchange has been established.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
156 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
157 * Note: This implementation will never start automatically a key exchange (other than the initial one)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
158 * unless you or the connected SSH-2 client ask for it.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
159 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
160 * @throws IOException
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
161 * In case of any failure behind the scenes.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
162 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
164 public synchronized void forceKeyExchange() throws IOException {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
165 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
166 if (state.tm == null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
167 throw new IllegalStateException(
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
168 "Cannot force another key exchange, you need to start the key exchange first.");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
169
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
170 state.tm.forceKeyExchange(state.next_cryptoWishList, null, state.next_dsa_key, state.next_rsa_key, state.next_ec_key);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
171 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
172 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
173
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
174 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
175 * Returns a {@link ConnectionInfo} object containing the details of
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
176 * the connection. May be called as soon as the first key exchange has been
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
177 * started. The method blocks in case the first key exchange has not been completed.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
178 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
179 * Note: upon return of this method, authentication may still be pending.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
180 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
181 * @return A {@link ConnectionInfo} object.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
182 * @throws IOException
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
183 * In case of any failure behind the scenes; e.g., first key exchange was aborted.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
184 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
186 public synchronized ConnectionInfo getConnectionInfo() throws IOException {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
187 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
188 if (state.tm == null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
189 throw new IllegalStateException(
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
190 "Cannot get details of connection, you need to start the key exchange first.");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
191 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
192
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
193 return state.tm.getConnectionInfo(1);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
194 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
195
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
196 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
197 * Change the current DSA hostkey. Either a DSA or RSA or EC private key must be set for a successful handshake with
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
198 * the client.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
199 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
200 * Note: You can change an existing DSA hostkey after the initial kex exchange (the new value will
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
201 * be used during the next server initiated key exchange), but you cannot remove (i.e., set to <code>null</code>) the
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
202 * current DSA key, otherwise the next key exchange may fail in case the client supports only DSA hostkeys.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
203 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
204 * @param dsa_hostkey
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
205 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
207 public synchronized void setDsaHostKey(KeyPair dsa_hostkey) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
208 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
209 if ((dsa_hostkey == null) && (state.next_dsa_key != null) && (state.tm != null))
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
210 throw new IllegalStateException("Cannot remove DSA hostkey after first key exchange.");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
211
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
212 state.next_dsa_key = dsa_hostkey;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
213 fixCryptoWishList(state.next_cryptoWishList, state.next_dsa_key, state.next_rsa_key, state.next_ec_key);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
214 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
215 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
217 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
218 * Change the current RSA hostkey. Either a DSA or RSA or EC private key must be set for a successful handshake with
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
219 * the client.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
220 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
221 * Note: You can change an existing RSA hostkey after the initial kex exchange (the new value will
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
222 * be used during the next server initiated key exchange), but you cannot remove (i.e., set to <code>null</code>) the
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
223 * current RSA key, otherwise the next key exchange may fail in case the client supports only RSA hostkeys.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
224 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
225 * @param rsa_hostkey
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
226 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
227
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
228 public synchronized void setRsaHostKey(KeyPair rsa_hostkey) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
229 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
230 if ((rsa_hostkey == null) && (state.next_rsa_key != null) && (state.tm != null))
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
231 throw new IllegalStateException("Cannot remove RSA hostkey after first key exchange.");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
232
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
233 state.next_rsa_key = rsa_hostkey;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
234 fixCryptoWishList(state.next_cryptoWishList, state.next_dsa_key, state.next_rsa_key, state.next_ec_key);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
235 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
236 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
238 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
239 * Change the current EC hostkey. Either a DSA or RSA or EC private key must be set for a successful handshake with
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
240 * the client.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
241 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
242 * Note: You can change an existing EC hostkey after the initial kex exchange (the new value will
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
243 * be used during the next server initiated key exchange), but you cannot remove (i.e., set to <code>null</code>) the
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
244 * current EC key, otherwise the next key exchange may fail in case the client supports only EC hostkeys.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
245 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
246 * @param rsa_hostkey
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
247 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
248
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
249 public synchronized void setEcHostKey(KeyPair ec_hostkey) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
250 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
251 if ((ec_hostkey == null) && (state.next_ec_key != null) && (state.tm != null))
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
252 throw new IllegalStateException("Cannot remove EC hostkey after first key exchange.");
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 289
diff changeset
253
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
254 state.next_ec_key = ec_hostkey;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
255 fixCryptoWishList(state.next_cryptoWishList, state.next_dsa_key, state.next_rsa_key, state.next_ec_key);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
256 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
257 }
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 289
diff changeset
258
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
259 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
260 * Utility method that loads a PEM based hostkey (either RSA or DSA based) and
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
261 * calls either <code>setRsaHostKey()</code> or <code>setDsaHostKey()</code>.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
262 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
263 * @param pemdata The PEM data
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
264 * @param password Password, may be null in case the PEM data is not password protected
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
265 * @throws IOException In case of any error.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
266 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
267 public void setPEMHostKey(char[] pemdata, String password) throws IOException {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
268 KeyPair pair = PEMDecoder.decode(pemdata, password);
289
d2ee20d9dff1 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
269 PrivateKey key = pair.getPrivate();
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
270
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
271 if (key instanceof DSAPrivateKey) setDsaHostKey(pair);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
272
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
273 if (key instanceof RSAPrivateKey) setRsaHostKey(pair);
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 289
diff changeset
274
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 289
diff changeset
275 if (key instanceof ECPrivateKey) setEcHostKey(pair);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
276 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
277
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
278 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
279 * Utility method that loads a hostkey from a PEM file (either RSA or DSA based) and
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
280 * calls either <code>setRsaHostKey()</code> or <code>setDsaHostKey()</code>.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
281 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
282 * @param pemFile The PEM file
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
283 * @param password Password, may be null in case the PEM file is not password protected
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
284 * @throws IOException
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
285 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
286 public void setPEMHostKey(File pemFile, String password) throws IOException {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
287 if (pemFile == null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
288 throw new IllegalArgumentException("pemfile argument is null");
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
289
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
290 char[] buff = new char[256];
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
291 CharArrayWriter cw = new CharArrayWriter();
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
292 FileReader fr = new FileReader(pemFile);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
293
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
294 while (true) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
295 int len = fr.read(buff);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
296
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
297 if (len < 0)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
298 break;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
299
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
300 cw.write(buff, 0, len);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
301 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
302
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
303 fr.close();
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
304 setPEMHostKey(cw.toCharArray(), password);
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
305 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
306
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
307 private void fixCryptoWishList(CryptoWishList next_cryptoWishList, KeyPair next_dsa_key, KeyPair next_rsa_key, KeyPair next_ec_key) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
308 List<String> algos = new ArrayList<String>();
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
309
358
37f4a3b506d9 move nist ec curves to lower priority
Carl Byington <carl@five-ten-sg.com>
parents: 321
diff changeset
310 if (next_rsa_key != null) algos.add("ssh-rsa");
37f4a3b506d9 move nist ec curves to lower priority
Carl Byington <carl@five-ten-sg.com>
parents: 321
diff changeset
311 if (next_dsa_key != null) algos.add("ssh-dss");
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
312 if (next_ec_key != null) algos.add("ecdsa-sha2-nistp521");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
313 if (next_ec_key != null) algos.add("ecdsa-sha2-nistp384");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
314 if (next_ec_key != null) algos.add("ecdsa-sha2-nistp256");
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
315
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
316 next_cryptoWishList.serverHostKeyAlgorithms = new String[algos.size()];
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 289
diff changeset
317 algos.toArray(next_cryptoWishList.serverHostKeyAlgorithms);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
318 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
320 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
321 * Callback interface with methods that will be called upon events
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
322 * generated by the client (e.g., client opens a new Session which results in a <code>ServerSession</code>).
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
323 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
324 * Note: This must be set before the first handshake.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
325 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
326 * @param cb The callback implementation
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
327 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
328
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
329 public synchronized void setServerConnectionCallback(ServerConnectionCallback cb) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
330 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
331 state.cb_conn = cb;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
332 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
333 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
334
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
335 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
336 * Callback interface with methods that will be called upon authentication events.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
337 * <p>
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
338 * Note: This must be set before the first handshake.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
339 *
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
340 * @param cb The callback implementation
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
341 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
342
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
343 public synchronized void setAuthenticationCallback(ServerAuthenticationCallback cb) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
344 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
345 state.cb_auth = cb;
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
346 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
347 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
348
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
349 /**
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
350 * Close the connection to the SSH-2 server. All assigned sessions will be
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
351 * closed, too. Can be called at any time. Don't forget to call this once
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
352 * you don't need a connection anymore - otherwise the receiver thread may
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
353 * run forever.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
354 */
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
355 public void close() {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
356 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
357 if (state.cm != null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
358 state.cm.closeAllChannels();
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
359
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
360 if (state.tm != null) {
321
c19b24adf6c9 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
361 state.tm.close(new Throwable("Closed due to user request."), false);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
362 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
363 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
364 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
366 public void close(IOException t) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
367 synchronized (state) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
368 if (state.cm != null)
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
369 state.cm.closeAllChannels();
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
371 if (state.tm != null) {
321
c19b24adf6c9 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
372 state.tm.close(t, false);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
373 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
374 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
375 }
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
376 }