comparison cli-session.c @ 747:077bbe1eb220

merge kexguess branch
author Matt Johnston <matt@ucc.asn.au>
date Wed, 03 Apr 2013 00:49:24 +0800
parents 619b1ed837fd 465fefc4f6e0
children a813e2752fdb
comparison
equal deleted inserted replaced
736:0b854ab00333 747:077bbe1eb220
109 109
110 /* Not reached */ 110 /* Not reached */
111 111
112 } 112 }
113 113
114 #ifdef USE_KEX_FIRST_FOLLOWS
115 static void cli_send_kex_first_guess() {
116 send_msg_kexdh_init();
117 dropbear_log(LOG_INFO, "kexdh_init guess sent");
118 }
119 #endif
120
114 static void cli_session_init() { 121 static void cli_session_init() {
115 122
116 cli_ses.state = STATE_NOTHING; 123 cli_ses.state = STATE_NOTHING;
117 cli_ses.kex_state = KEX_NOTHING; 124 cli_ses.kex_state = KEX_NOTHING;
118 125
142 cli_ses.cipher_none_after_auth = 0; 149 cli_ses.cipher_none_after_auth = 0;
143 #endif 150 #endif
144 151
145 /* For printing "remote host closed" for the user */ 152 /* For printing "remote host closed" for the user */
146 ses.remoteclosed = cli_remoteclosed; 153 ses.remoteclosed = cli_remoteclosed;
154
147 ses.extra_session_cleanup = cli_session_cleanup; 155 ses.extra_session_cleanup = cli_session_cleanup;
148 ses.buf_match_algo = cli_buf_match_algo;
149 156
150 /* packet handlers */ 157 /* packet handlers */
151 ses.packettypes = cli_packettypes; 158 ses.packettypes = cli_packettypes;
152 159
153 ses.isserver = 0; 160 ses.isserver = 0;
161
162 #ifdef USE_KEX_FIRST_FOLLOWS
163 ses.send_kex_first_guess = cli_send_kex_first_guess;
164 #endif
165
154 } 166 }
155 167
156 static void send_msg_service_request(char* servicename) { 168 static void send_msg_service_request(char* servicename) {
157 169
158 TRACE(("enter send_msg_service_request: servicename='%s'", servicename)) 170 TRACE(("enter send_msg_service_request: servicename='%s'", servicename))
174 * service, userauth and channel requests */ 186 * service, userauth and channel requests */
175 static void cli_sessionloop() { 187 static void cli_sessionloop() {
176 188
177 TRACE2(("enter cli_sessionloop")) 189 TRACE2(("enter cli_sessionloop"))
178 190
191 if (ses.lastpacket == 0) {
192 TRACE2(("exit cli_sessionloop: no real packets yet"))
193 return;
194 }
195
179 if (ses.lastpacket == SSH_MSG_KEXINIT && cli_ses.kex_state == KEX_NOTHING) { 196 if (ses.lastpacket == SSH_MSG_KEXINIT && cli_ses.kex_state == KEX_NOTHING) {
180 cli_ses.kex_state = KEXINIT_RCVD;
181 }
182
183 if (cli_ses.kex_state == KEXINIT_RCVD) {
184
185 /* We initiate the KEXDH. If DH wasn't the correct type, the KEXINIT 197 /* We initiate the KEXDH. If DH wasn't the correct type, the KEXINIT
186 * negotiation would have failed. */ 198 * negotiation would have failed. */
187 send_msg_kexdh_init(); 199 if (!ses.kexstate.our_first_follows_matches) {
188 cli_ses.kex_state = KEXDH_INIT_SENT; 200 dropbear_log(LOG_INFO, "kexdh_init after remote's kexinit");
201 send_msg_kexdh_init();
202 }
203 cli_ses.kex_state = KEXDH_INIT_SENT;
189 TRACE(("leave cli_sessionloop: done with KEXINIT_RCVD")) 204 TRACE(("leave cli_sessionloop: done with KEXINIT_RCVD"))
190 return; 205 return;
191 } 206 }
192 207
193 /* A KEX has finished, so we should go back to our KEX_NOTHING state */ 208 /* A KEX has finished, so we should go back to our KEX_NOTHING state */
200 if (cli_ses.kex_state != KEX_NOTHING) { 215 if (cli_ses.kex_state != KEX_NOTHING) {
201 TRACE(("leave cli_sessionloop: kex_state != KEX_NOTHING")) 216 TRACE(("leave cli_sessionloop: kex_state != KEX_NOTHING"))
202 return; 217 return;
203 } 218 }
204 219
205 /* We should exit if we haven't donefirstkex: we shouldn't reach here
206 * in normal operation */
207 if (ses.kexstate.donefirstkex == 0) { 220 if (ses.kexstate.donefirstkex == 0) {
208 TRACE(("XXX XXX might be bad! leave cli_sessionloop: haven't donefirstkex")) 221 /* We might reach here if we have partial packet reads or have
222 * received SSG_MSG_IGNORE etc. Just skip it */
209 return; 223 return;
210 } 224 }
211 225
212 switch (cli_ses.state) { 226 switch (cli_ses.state) {
213 227