annotate src/ch/ethz/ssh2/transport/ServerKexManager.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 d2b303406d63
children 42b15aaa7ac7
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) 2006-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 package ch.ethz.ssh2.transport;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 import java.io.IOException;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 import java.security.DigestException;
287
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
9 import java.security.interfaces.DSAPrivateKey;
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
10 import java.security.interfaces.DSAPublicKey;
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
11 import java.security.interfaces.ECPrivateKey;
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
12 import java.security.interfaces.ECPublicKey;
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
13 import java.security.interfaces.RSAPrivateKey;
db9b028016de start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 285
diff changeset
14 import java.security.interfaces.RSAPublicKey;
305
d2b303406d63 remove extra override annotations that generate eclipse compiler errors
Carl Byington <carl@five-ten-sg.com>
parents: 302
diff changeset
15
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 import ch.ethz.ssh2.ConnectionInfo;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 import ch.ethz.ssh2.PacketTypeException;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 import ch.ethz.ssh2.auth.ServerAuthenticationManager;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 import ch.ethz.ssh2.crypto.cipher.BlockCipher;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 import ch.ethz.ssh2.crypto.cipher.BlockCipherFactory;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 import ch.ethz.ssh2.crypto.dh.DhExchange;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 import ch.ethz.ssh2.crypto.digest.MAC;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 import ch.ethz.ssh2.packets.PacketKexDHInit;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 import ch.ethz.ssh2.packets.PacketKexDHReply;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 import ch.ethz.ssh2.packets.PacketKexInit;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 import ch.ethz.ssh2.packets.Packets;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 import ch.ethz.ssh2.server.ServerConnectionState;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 import ch.ethz.ssh2.signature.DSASHA1Verify;
283
3855f58ffd2b start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 281
diff changeset
29 import ch.ethz.ssh2.signature.ECDSASHA2Verify;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 import ch.ethz.ssh2.signature.RSASHA1Verify;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 /**
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 * @version $Id: ServerKexManager.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 */
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 public class ServerKexManager extends KexManager {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 private final ServerConnectionState state;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 private boolean authenticationStarted = false;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 public ServerKexManager(ServerConnectionState state) {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 super(state.tm, state.csh, state.next_cryptoWishList, state.generator);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 this.state = state;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 public void handleFailure(final IOException failure) {
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
47 synchronized (accessLock) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 connectionClosed = true;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 accessLock.notifyAll();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 public void handleMessage(byte[] msg) throws IOException {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 PacketKexInit kip;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
56 if ((kxs == null) && (msg[0] != Packets.SSH_MSG_KEXINIT)) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 throw new PacketTypeException(msg[0]);
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
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
60 if (ignore_next_kex_packet) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 ignore_next_kex_packet = false;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 return;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
65 if (msg[0] == Packets.SSH_MSG_KEXINIT) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
66 if ((kxs != null) && (kxs.state != 0)) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 throw new PacketTypeException(msg[0]);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
70 if (kxs == null) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 /*
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 * Ah, OK, peer wants to do KEX. Let's be nice and play
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
73 * together.
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
74 */
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 kxs = new KexState();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 kxs.local_dsa_key = nextKEXdsakey;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 kxs.local_rsa_key = nextKEXrsakey;
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
78 kxs.local_ec_key = nextKEXeckey;
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 kxs.dhgexParameters = nextKEXdhgexParameters;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 kip = new PacketKexInit(nextKEXcryptoWishList, rnd);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 kxs.localKEX = kip;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 tm.sendKexMessage(kip.getPayload());
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 kip = new PacketKexInit(msg);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 kxs.remoteKEX = kip;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 kxs.np = mergeKexParameters(kxs.remoteKEX.getKexParameters(), kxs.localKEX.getKexParameters());
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
89 if (kxs.remoteKEX.isFirst_kex_packet_follows() && (kxs.np.guessOK == false)) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 // Guess was wrong, we need to ignore the next kex packet.
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 ignore_next_kex_packet = true;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
94 if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1")
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 || kxs.np.kex_algo.equals("diffie-hellman-group14-sha1")) {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 kxs.dhx = new DhExchange();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
98 if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1")) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 kxs.dhx.serverInit(1, rnd);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 else {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102 kxs.dhx.serverInit(14, rnd);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 kxs.state = 1;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 return;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 throw new IllegalStateException("Unkown KEX method!");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
111
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
112 if (msg[0] == Packets.SSH_MSG_NEWKEYS) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
113 if (km == null) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114 throw new IOException("Peer sent SSH_MSG_NEWKEYS, but I have no key material ready!");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 BlockCipher cbc;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 MAC mac;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 try {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_client_to_server, false,
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
122 km.enc_key_client_to_server, km.initial_iv_client_to_server);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 try {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 mac = new MAC(kxs.np.mac_algo_client_to_server, km.integrity_key_client_to_server);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
127 catch (DigestException e) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 throw new IOException(e);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
131 catch (IllegalArgumentException e) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 throw new IOException(e);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135 tm.changeRecvCipher(cbc, mac);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 ConnectionInfo sci = new ConnectionInfo();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 kexCount++;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 sci.keyExchangeAlgorithm = kxs.np.kex_algo;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139 sci.keyExchangeCounter = kexCount;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140 sci.clientToServerCryptoAlgorithm = kxs.np.enc_algo_client_to_server;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 sci.serverToClientCryptoAlgorithm = kxs.np.enc_algo_server_to_client;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 sci.clientToServerMACAlgorithm = kxs.np.mac_algo_client_to_server;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143 sci.serverToClientMACAlgorithm = kxs.np.mac_algo_server_to_client;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 sci.serverHostKeyAlgorithm = kxs.np.server_host_key_algo;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145 sci.serverHostKey = kxs.remote_hostkey;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
147 synchronized (accessLock) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148 lastConnInfo = sci;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149 accessLock.notifyAll();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152 kxs = null;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 return;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
155
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
156 if ((kxs == null) || (kxs.state == 0)) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 throw new IOException("Unexpected Kex submessage!");
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
159
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
160 if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1")
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
161 || kxs.np.kex_algo.equals("diffie-hellman-group14-sha1")) {
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
162 if (kxs.state == 1) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163 PacketKexDHInit dhi = new PacketKexDHInit(msg);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 kxs.dhx.setE(dhi.getE());
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165 byte[] hostKey = null;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
167 if (kxs.np.server_host_key_algo.startsWith("ecdsa-sha2-")) {
302
beaccc9df37b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 298
diff changeset
168 hostKey = ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey)kxs.local_ec_key.getPublic());
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
169 }
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
170
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
171 if (kxs.np.server_host_key_algo.equals("ssh-rsa")) {
285
486df527ddc5 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 284
diff changeset
172 hostKey = RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey)kxs.local_rsa_key.getPublic());
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
173 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
175 if (kxs.np.server_host_key_algo.equals("ssh-dss")) {
285
486df527ddc5 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 284
diff changeset
176 hostKey = DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey)kxs.local_dsa_key.getPublic());
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
179 try {
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
180 kxs.H = kxs.dhx.calculateH(csh.getClientString(), csh.getServerString(),
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
181 kxs.remoteKEX.getPayload(), kxs.localKEX.getPayload(), hostKey);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
182 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
183 catch (IllegalArgumentException e) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
184 throw new IOException("KEX error.", e);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
185 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
186
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
187 kxs.K = kxs.dhx.getK();
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
188 byte[] signature = null;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
189
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
190 if (kxs.np.server_host_key_algo.startsWith("ecdsa-sha2-")) {
302
beaccc9df37b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 298
diff changeset
191 ECPrivateKey pk = (ECPrivateKey)kxs.local_ec_key.getPrivate();
beaccc9df37b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 298
diff changeset
192 byte[] es = ECDSASHA2Verify.generateSignature(kxs.H, pk);
beaccc9df37b add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 298
diff changeset
193 signature = ECDSASHA2Verify.encodeSSHECDSASignature(es, pk.getParams());
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
194 }
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
195
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
196 if (kxs.np.server_host_key_algo.equals("ssh-rsa")) {
285
486df527ddc5 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 284
diff changeset
197 byte[] rs = RSASHA1Verify.generateSignature(kxs.H, (RSAPrivateKey)kxs.local_rsa_key.getPrivate());
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
198 signature = RSASHA1Verify.encodeSSHRSASignature(rs);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
199 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200
298
ab3a99f11a36 add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents: 287
diff changeset
201 if (kxs.np.server_host_key_algo.equals("ssh-dss")) {
285
486df527ddc5 start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents: 284
diff changeset
202 byte[] ds = DSASHA1Verify.generateSignature(kxs.H, (DSAPrivateKey)kxs.local_dsa_key.getPrivate(), rnd);
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203 signature = DSASHA1Verify.encodeSSHDSASignature(ds);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206 PacketKexDHReply dhr = new PacketKexDHReply(hostKey, kxs.dhx.getF(), signature);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 tm.sendKexMessage(dhr.getPayload());
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208 finishKex(false);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 kxs.state = -1;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
211 if (authenticationStarted == false) {
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212 authenticationStarted = true;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 state.am = new ServerAuthenticationManager(state);
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
215
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 return;
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 305
diff changeset
219
273
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 throw new IllegalStateException(String.format("Unknown KEX method %s", kxs.np.kex_algo));
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 }
91a31873c42a start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 }