Mercurial > 510Connectbot
diff 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 |
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/transport/ServerKexManager.java Wed Jul 30 12:09:51 2014 -0700 +++ b/src/ch/ethz/ssh2/transport/ServerKexManager.java Wed Jul 30 14:16:58 2014 -0700 @@ -44,7 +44,7 @@ } public void handleFailure(final IOException failure) { - synchronized(accessLock) { + synchronized (accessLock) { connectionClosed = true; accessLock.notifyAll(); } @@ -53,25 +53,25 @@ public void handleMessage(byte[] msg) throws IOException { PacketKexInit kip; - if((kxs == null) && (msg[0] != Packets.SSH_MSG_KEXINIT)) { + if ((kxs == null) && (msg[0] != Packets.SSH_MSG_KEXINIT)) { throw new PacketTypeException(msg[0]); } - if(ignore_next_kex_packet) { + if (ignore_next_kex_packet) { ignore_next_kex_packet = false; return; } - if(msg[0] == Packets.SSH_MSG_KEXINIT) { - if((kxs != null) && (kxs.state != 0)) { + if (msg[0] == Packets.SSH_MSG_KEXINIT) { + if ((kxs != null) && (kxs.state != 0)) { throw new PacketTypeException(msg[0]); } - if(kxs == null) { + if (kxs == null) { /* * Ah, OK, peer wants to do KEX. Let's be nice and play - * together. - */ + * together. + */ kxs = new KexState(); kxs.local_dsa_key = nextKEXdsakey; kxs.local_rsa_key = nextKEXrsakey; @@ -84,19 +84,18 @@ kip = new PacketKexInit(msg); kxs.remoteKEX = kip; - kxs.np = mergeKexParameters(kxs.remoteKEX.getKexParameters(), kxs.localKEX.getKexParameters()); - if(kxs.remoteKEX.isFirst_kex_packet_follows() && (kxs.np.guessOK == false)) { + if (kxs.remoteKEX.isFirst_kex_packet_follows() && (kxs.np.guessOK == false)) { // Guess was wrong, we need to ignore the next kex packet. ignore_next_kex_packet = true; } - if(kxs.np.kex_algo.equals("diffie-hellman-group1-sha1") + if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1") || kxs.np.kex_algo.equals("diffie-hellman-group14-sha1")) { kxs.dhx = new DhExchange(); - if(kxs.np.kex_algo.equals("diffie-hellman-group1-sha1")) { + if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1")) { kxs.dhx.serverInit(1, rnd); } else { @@ -110,8 +109,8 @@ throw new IllegalStateException("Unkown KEX method!"); } - if(msg[0] == Packets.SSH_MSG_NEWKEYS) { - if(km == null) { + if (msg[0] == Packets.SSH_MSG_NEWKEYS) { + if (km == null) { throw new IOException("Peer sent SSH_MSG_NEWKEYS, but I have no key material ready!"); } @@ -120,26 +119,22 @@ try { cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_client_to_server, false, - km.enc_key_client_to_server, km.initial_iv_client_to_server); + km.enc_key_client_to_server, km.initial_iv_client_to_server); try { mac = new MAC(kxs.np.mac_algo_client_to_server, km.integrity_key_client_to_server); } - catch(DigestException e) { + catch (DigestException e) { throw new IOException(e); } - } - catch(IllegalArgumentException e) { + catch (IllegalArgumentException e) { throw new IOException(e); } tm.changeRecvCipher(cbc, mac); - ConnectionInfo sci = new ConnectionInfo(); - kexCount++; - sci.keyExchangeAlgorithm = kxs.np.kex_algo; sci.keyExchangeCounter = kexCount; sci.clientToServerCryptoAlgorithm = kxs.np.enc_algo_client_to_server; @@ -149,7 +144,7 @@ sci.serverHostKeyAlgorithm = kxs.np.server_host_key_algo; sci.serverHostKey = kxs.remote_hostkey; - synchronized(accessLock) { + synchronized (accessLock) { lastConnInfo = sci; accessLock.notifyAll(); } @@ -158,41 +153,38 @@ return; } - if((kxs == null) || (kxs.state == 0)) { + if ((kxs == null) || (kxs.state == 0)) { throw new IOException("Unexpected Kex submessage!"); } - if(kxs.np.kex_algo.equals("diffie-hellman-group1-sha1") + if (kxs.np.kex_algo.equals("diffie-hellman-group1-sha1") || kxs.np.kex_algo.equals("diffie-hellman-group14-sha1")) { - if(kxs.state == 1) { + if (kxs.state == 1) { PacketKexDHInit dhi = new PacketKexDHInit(msg); - kxs.dhx.setE(dhi.getE()); - byte[] hostKey = null; if (kxs.np.server_host_key_algo.startsWith("ecdsa-sha2-")) { hostKey = ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey)kxs.local_ec_key.getPublic()); } - if(kxs.np.server_host_key_algo.equals("ssh-rsa")) { + if (kxs.np.server_host_key_algo.equals("ssh-rsa")) { hostKey = RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey)kxs.local_rsa_key.getPublic()); } - if(kxs.np.server_host_key_algo.equals("ssh-dss")) { + if (kxs.np.server_host_key_algo.equals("ssh-dss")) { hostKey = DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey)kxs.local_dsa_key.getPublic()); } try { kxs.H = kxs.dhx.calculateH(csh.getClientString(), csh.getServerString(), - kxs.remoteKEX.getPayload(), kxs.localKEX.getPayload(), hostKey); + kxs.remoteKEX.getPayload(), kxs.localKEX.getPayload(), hostKey); } - catch(IllegalArgumentException e) { + catch (IllegalArgumentException e) { throw new IOException("KEX error.", e); } kxs.K = kxs.dhx.getK(); - byte[] signature = null; if (kxs.np.server_host_key_algo.startsWith("ecdsa-sha2-")) { @@ -213,11 +205,10 @@ PacketKexDHReply dhr = new PacketKexDHReply(hostKey, kxs.dhx.getF(), signature); tm.sendKexMessage(dhr.getPayload()); - finishKex(false); kxs.state = -1; - if(authenticationStarted == false) { + if (authenticationStarted == false) { authenticationStarted = true; state.am = new ServerAuthenticationManager(state); } @@ -225,6 +216,7 @@ return; } } + throw new IllegalStateException(String.format("Unknown KEX method %s", kxs.np.kex_algo)); } }