Mercurial > 510Connectbot
annotate app/src/main/java/ch/ethz/ssh2/transport/ClientKexManager.java @ 524:609b142218bc
Added tag stable-1.9.4-7 for changeset 775a81a78a2b
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 31 May 2024 21:14:55 -0600 |
parents | 7953570e5210 |
children |
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; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
9 import java.security.SecureRandom; |
305
d2b303406d63
remove extra override annotations that generate eclipse compiler errors
Carl Byington <carl@five-ten-sg.com>
parents:
298
diff
changeset
|
10 import java.security.interfaces.DSAPublicKey; |
d2b303406d63
remove extra override annotations that generate eclipse compiler errors
Carl Byington <carl@five-ten-sg.com>
parents:
298
diff
changeset
|
11 import java.security.interfaces.ECPublicKey; |
d2b303406d63
remove extra override annotations that generate eclipse compiler errors
Carl Byington <carl@five-ten-sg.com>
parents:
298
diff
changeset
|
12 import java.security.interfaces.RSAPublicKey; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
13 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
14 import ch.ethz.ssh2.ConnectionInfo; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
15 import ch.ethz.ssh2.PacketTypeException; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
16 import ch.ethz.ssh2.ServerHostKeyVerifier; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
17 import ch.ethz.ssh2.compression.CompressionFactory; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
18 import ch.ethz.ssh2.compression.Compressor; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
19 import ch.ethz.ssh2.crypto.CryptoWishList; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
20 import ch.ethz.ssh2.crypto.cipher.BlockCipher; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
21 import ch.ethz.ssh2.crypto.cipher.BlockCipherFactory; |
310
9e42082d1f93
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
308
diff
changeset
|
22 import ch.ethz.ssh2.crypto.dh.GenericDhExchange; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
23 import ch.ethz.ssh2.crypto.dh.DhGroupExchange; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
24 import ch.ethz.ssh2.crypto.digest.MAC; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
25 import ch.ethz.ssh2.packets.PacketKexDHInit; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
26 import ch.ethz.ssh2.packets.PacketKexDHReply; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
27 import ch.ethz.ssh2.packets.PacketKexDhGexGroup; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
28 import ch.ethz.ssh2.packets.PacketKexDhGexInit; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
29 import ch.ethz.ssh2.packets.PacketKexDhGexReply; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
30 import ch.ethz.ssh2.packets.PacketKexDhGexRequest; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
31 import ch.ethz.ssh2.packets.PacketKexDhGexRequestOld; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
32 import ch.ethz.ssh2.packets.PacketKexInit; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
33 import ch.ethz.ssh2.packets.Packets; |
281
b4ca341c318d
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
278
diff
changeset
|
34 import ch.ethz.ssh2.signature.DSASHA1Verify; |
282
c3019725b123
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
281
diff
changeset
|
35 import ch.ethz.ssh2.signature.ECDSASHA2Verify; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
36 import ch.ethz.ssh2.signature.RSASHA1Verify; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
37 |
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 * @version $Id: ClientKexManager.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
|
40 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
41 public class ClientKexManager extends KexManager { |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
42 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
43 private final ServerHostKeyVerifier verifier; |
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 private final String hostname; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
46 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
47 private final int port; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
48 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
49 public ClientKexManager(TransportManager tm, ClientServerHello csh, CryptoWishList initialCwl, String hostname, int port, |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
50 ServerHostKeyVerifier keyVerifier, SecureRandom rnd) { |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
51 super(tm, csh, initialCwl, rnd); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
52 this.hostname = hostname; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
53 this.port = port; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
54 this.verifier = keyVerifier; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
55 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
56 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
57 protected boolean verifySignature(byte[] sig, byte[] hostkey) throws IOException { |
284
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
58 if (kxs.np.server_host_key_algo.startsWith("ecdsa-sha2-")) { |
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
59 byte[] rs = ECDSASHA2Verify.decodeSSHECDSASignature(sig); |
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
60 ECPublicKey epk = ECDSASHA2Verify.decodeSSHECDSAPublicKey(hostkey); |
287
db9b028016de
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
285
diff
changeset
|
61 log.debug("Verifying ecdsa signature"); |
284
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
62 return ECDSASHA2Verify.verifySignature(kxs.H, rs, epk); |
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
63 } |
298
ab3a99f11a36
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
287
diff
changeset
|
64 |
284
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
65 if (kxs.np.server_host_key_algo.equals("ssh-rsa")) { |
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
66 byte[] rs = RSASHA1Verify.decodeSSHRSASignature(sig); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
67 RSAPublicKey rpk = RSASHA1Verify.decodeSSHRSAPublicKey(hostkey); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
68 log.debug("Verifying ssh-rsa signature"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
69 return RSASHA1Verify.verifySignature(kxs.H, rs, rpk); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
70 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
71 |
284
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
72 if (kxs.np.server_host_key_algo.equals("ssh-dss")) { |
4ec87de11e71
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
282
diff
changeset
|
73 byte[] ds = DSASHA1Verify.decodeSSHDSASignature(sig); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
74 DSAPublicKey dpk = DSASHA1Verify.decodeSSHDSAPublicKey(hostkey); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
75 log.debug("Verifying ssh-dss signature"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
76 return DSASHA1Verify.verifySignature(kxs.H, ds, dpk); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
77 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
78 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
79 throw new IOException("Unknown server host key algorithm '" + kxs.np.server_host_key_algo + "'"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
80 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
81 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
82 public void handleFailure(final IOException failure) { |
330 | 83 synchronized (accessLock) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
84 connectionClosed = true; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
85 accessLock.notifyAll(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
86 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
87 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
88 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
89 public synchronized void handleMessage(byte[] msg) throws IOException { |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
90 PacketKexInit kip; |
366
098bb036e0a7
fix typo in key exchange hash algorithm type
Carl Byington <carl@five-ten-sg.com>
parents:
333
diff
changeset
|
91 |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
92 if (msg == null) { |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
93 synchronized (accessLock) { |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
94 connectionClosed = true; |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
95 accessLock.notifyAll(); |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
96 return; |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
97 } |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
98 } |
366
098bb036e0a7
fix typo in key exchange hash algorithm type
Carl Byington <carl@five-ten-sg.com>
parents:
333
diff
changeset
|
99 |
333
d835e842d158
still hangs during connection
Carl Byington <carl@five-ten-sg.com>
parents:
330
diff
changeset
|
100 log.debug(String.format("client kex manager, packet type %d", msg[0])); |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
101 |
330 | 102 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
|
103 throw new PacketTypeException(msg[0]); |
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 |
330 | 106 if (ignore_next_kex_packet) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
107 ignore_next_kex_packet = false; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
108 return; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
109 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
110 |
330 | 111 if (msg[0] == Packets.SSH_MSG_KEXINIT) { |
112 if ((kxs != null) && (kxs.state != 0)) { | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
113 throw new PacketTypeException(msg[0]); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
114 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
115 |
330 | 116 if (kxs == null) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
117 /* |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
118 * Ah, OK, peer wants to do KEX. Let's be nice and play |
330 | 119 * together. |
120 */ | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
121 kxs = new KexState(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
122 kxs.dhgexParameters = nextKEXdhgexParameters; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
123 kip = new PacketKexInit(nextKEXcryptoWishList, rnd); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
124 kxs.localKEX = kip; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
125 tm.sendKexMessage(kip.getPayload()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
126 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
127 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
128 kip = new PacketKexInit(msg); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
129 kxs.remoteKEX = kip; |
329
6896bfafa510
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
130 kxs.np = mergeKexParameters(kxs.localKEX.getKexParameters(), kxs.remoteKEX.getKexParameters()); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
131 |
329
6896bfafa510
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
132 if (kxs.np == null) |
6896bfafa510
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
133 throw new IOException("Cannot negotiate, proposals do not match."); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
134 |
330 | 135 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
|
136 // 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
|
137 ignore_next_kex_packet = true; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
138 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
139 |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
140 if (kxs.np.kex_algo.equals("diffie-hellman-group-exchange-sha1") || |
330 | 141 kxs.np.kex_algo.equals("diffie-hellman-group-exchange-sha256")) { |
142 if (kxs.dhgexParameters.getMin_group_len() == 0) { | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
143 PacketKexDhGexRequestOld dhgexreq = new PacketKexDhGexRequestOld(kxs.dhgexParameters); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
144 tm.sendKexMessage(dhgexreq.getPayload()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
145 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
146 else { |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
147 PacketKexDhGexRequest dhgexreq = new PacketKexDhGexRequest(kxs.dhgexParameters); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
148 tm.sendKexMessage(dhgexreq.getPayload()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
149 } |
330 | 150 |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
151 if (kxs.np.kex_algo.endsWith("sha1")) { |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
152 kxs.hashAlgo = "SHA1"; |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
153 } |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
154 else { |
366
098bb036e0a7
fix typo in key exchange hash algorithm type
Carl Byington <carl@five-ten-sg.com>
parents:
333
diff
changeset
|
155 kxs.hashAlgo = "SHA2"; |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
156 } |
330 | 157 |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
158 kxs.state = 1; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
159 return; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
160 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
161 |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
162 if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1") || |
373 | 163 kxs.np.kex_algo.equals("diffie-hellman-group14-sha1") || |
510
7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
164 kxs.np.kex_algo.equals("diffie-hellman-group14-sha256") || |
7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
165 kxs.np.kex_algo.equals("diffie-hellman-group16-sha512") || |
7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
166 kxs.np.kex_algo.equals("diffie-hellman-group18-sha512") || |
373 | 167 kxs.np.kex_algo.equals("ecdh-sha2-nistp256") || |
168 kxs.np.kex_algo.equals("ecdh-sha2-nistp384") || | |
169 kxs.np.kex_algo.equals("ecdh-sha2-nistp521")) { | |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
170 kxs.dhx = GenericDhExchange.getInstance(kxs.np.kex_algo); |
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
171 kxs.dhx.init(kxs.np.kex_algo); |
329
6896bfafa510
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
172 kxs.hashAlgo = kxs.dhx.getHashAlgo(); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
173 PacketKexDHInit kp = new PacketKexDHInit(kxs.dhx.getE()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
174 tm.sendKexMessage(kp.getPayload()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
175 kxs.state = 1; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
176 return; |
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 throw new IllegalStateException("Unkown KEX method!"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
180 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
181 |
329
6896bfafa510
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
182 if (msg[0] == Packets.SSH_MSG_NEWKEYS) { |
6896bfafa510
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
314
diff
changeset
|
183 if (km == null) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
184 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
|
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 BlockCipher cbc; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
188 MAC mac; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
189 Compressor comp; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
190 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
191 try { |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
192 cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_server_to_client, false, |
330 | 193 km.enc_key_server_to_client, km.initial_iv_server_to_client); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
194 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
195 try { |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
196 mac = new MAC(kxs.np.mac_algo_server_to_client, km.integrity_key_server_to_client); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
197 } |
330 | 198 catch (DigestException e) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
199 throw new IOException(e); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
200 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
201 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
202 comp = CompressionFactory.createCompressor(kxs.np.comp_algo_server_to_client); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
203 } |
330 | 204 catch (IllegalArgumentException e) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
205 throw new IOException(e.getMessage()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
206 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
207 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
208 tm.changeRecvCipher(cbc, mac); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
209 tm.changeRecvCompression(comp); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
210 ConnectionInfo sci = new ConnectionInfo(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
211 kexCount++; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
212 sci.keyExchangeAlgorithm = kxs.np.kex_algo; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
213 sci.keyExchangeCounter = kexCount; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 sci.serverHostKey = kxs.remote_hostkey; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
220 |
330 | 221 synchronized (accessLock) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
222 lastConnInfo = sci; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
223 accessLock.notifyAll(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
224 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
225 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
226 kxs = null; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
227 return; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
228 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
229 |
330 | 230 if ((kxs == null) || (kxs.state == 0)) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
231 throw new IOException("Unexpected Kex submessage!"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
232 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
233 |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
234 if (kxs.np.kex_algo.equals("diffie-hellman-group-exchange-sha1") || |
330 | 235 kxs.np.kex_algo.equals("diffie-hellman-group-exchange-sha256")) { |
236 if (kxs.state == 1) { | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
237 PacketKexDhGexGroup dhgexgrp = new PacketKexDhGexGroup(msg); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
238 kxs.dhgx = new DhGroupExchange(dhgexgrp.getP(), dhgexgrp.getG()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
239 kxs.dhgx.init(rnd); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
240 PacketKexDhGexInit dhgexinit = new PacketKexDhGexInit(kxs.dhgx.getE()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
241 tm.sendKexMessage(dhgexinit.getPayload()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
242 kxs.state = 2; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
243 return; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
244 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
245 |
330 | 246 if (kxs.state == 2) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
247 PacketKexDhGexReply dhgexrpl = new PacketKexDhGexReply(msg); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
248 kxs.remote_hostkey = dhgexrpl.getHostKey(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
249 |
330 | 250 if (verifier != null) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
251 try { |
330 | 252 if (!verifier.verifyServerHostKey(hostname, port, kxs.np.server_host_key_algo, kxs.remote_hostkey)) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
253 throw new IOException("The server host key was not accepted by the verifier callback"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
254 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
255 } |
330 | 256 catch (Exception e) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
257 throw new IOException( |
330 | 258 "The server host key was not accepted by the verifier callback.", e); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
259 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
260 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
261 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
262 kxs.dhgx.setF(dhgexrpl.getF()); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
263 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
264 try { |
313
1d400fd78e4a
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
312
diff
changeset
|
265 kxs.H = kxs.dhgx.calculateH(kxs.hashAlgo, csh.getClientString(), csh.getServerString(), |
330 | 266 kxs.localKEX.getPayload(), kxs.remoteKEX.getPayload(), dhgexrpl.getHostKey(), |
267 kxs.dhgexParameters); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
268 } |
330 | 269 catch (IllegalArgumentException e) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
270 throw new IOException("KEX error.", e); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
271 } |
330 | 272 |
273 if (!verifySignature(dhgexrpl.getSignature(), kxs.remote_hostkey)) { | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
274 throw new IOException("Invalid remote host key signature"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
275 } |
330 | 276 |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
277 kxs.K = kxs.dhgx.getK(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
278 finishKex(true); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
279 kxs.state = -1; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
280 return; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
281 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
282 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
283 throw new IllegalStateException("Illegal State in KEX Exchange!"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
284 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
285 |
306
90e47d99ea54
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
305
diff
changeset
|
286 if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1") || |
330 | 287 kxs.np.kex_algo.equals("diffie-hellman-group14-sha1") || |
510
7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
288 kxs.np.kex_algo.equals("diffie-hellman-group14-sha256") || |
7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
289 kxs.np.kex_algo.equals("diffie-hellman-group16-sha512") || |
7953570e5210
update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
290 kxs.np.kex_algo.equals("diffie-hellman-group18-sha512") || |
330 | 291 kxs.np.kex_algo.equals("ecdh-sha2-nistp256") || |
292 kxs.np.kex_algo.equals("ecdh-sha2-nistp384") || | |
293 kxs.np.kex_algo.equals("ecdh-sha2-nistp521")) { | |
294 if (kxs.state == 1) { | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
295 PacketKexDHReply dhr = new PacketKexDHReply(msg); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
296 kxs.remote_hostkey = dhr.getHostKey(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
297 |
330 | 298 if (verifier != null) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
299 try { |
330 | 300 if (!verifier.verifyServerHostKey(hostname, port, kxs.np.server_host_key_algo, kxs.remote_hostkey)) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
301 throw new IOException("The server host key was not accepted by the verifier callback"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
302 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
303 } |
330 | 304 catch (Exception e) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
305 throw new IOException("The server host key was not accepted by the verifier callback", e); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
306 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
307 } |
330 | 308 |
313
1d400fd78e4a
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
312
diff
changeset
|
309 kxs.dhx.setF(dhr.getF().toByteArray()); |
330 | 310 |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
311 try { |
314
d85bc45139f2
add ecdsa key support everywhere
Carl Byington <carl@five-ten-sg.com>
parents:
313
diff
changeset
|
312 kxs.H = kxs.dhx.calculateH(csh.getClientString(), csh.getServerString(), kxs.localKEX.getPayload(), |
330 | 313 kxs.remoteKEX.getPayload(), dhr.getHostKey()); |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
314 } |
330 | 315 catch (IllegalArgumentException e) { |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
316 throw new IOException("KEX error.", e); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
317 } |
330 | 318 |
319 if (!verifySignature(dhr.getSignature(), kxs.remote_hostkey)) { | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
320 throw new IOException("Invalid remote host key signature"); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
321 } |
330 | 322 |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
323 kxs.K = kxs.dhx.getK(); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
324 finishKex(true); |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
325 kxs.state = -1; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
326 return; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
327 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
328 } |
330 | 329 |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
330 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
|
331 } |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
332 } |