Mercurial > dropbear
annotate cli-session.c @ 34:e2a1eaa19f22
Client mostly works up to password auth
Need to rework algo-choosing etc, since server is now broken.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 28 Jul 2004 16:44:16 +0000 |
parents | f789045062e6 |
children | 0ad5fb979f42 |
rev | line source |
---|---|
26 | 1 #include "includes.h" |
2 #include "session.h" | |
3 #include "dbutil.h" | |
4 #include "kex.h" | |
5 #include "ssh.h" | |
6 #include "packet.h" | |
7 #include "tcpfwd-direct.h" | |
8 #include "tcpfwd-remote.h" | |
9 #include "channel.h" | |
10 #include "random.h" | |
33 | 11 #include "service.h" |
26 | 12 |
13 static void cli_remoteclosed(); | |
14 static void cli_sessionloop(); | |
33 | 15 static void cli_session_init(); |
26 | 16 |
17 struct clientsession cli_ses; /* GLOBAL */ | |
18 | |
19 static const packettype cli_packettypes[] = { | |
20 /* TYPE, AUTHREQUIRED, FUNCTION */ | |
21 {SSH_MSG_KEXINIT, recv_msg_kexinit}, | |
22 {SSH_MSG_KEXDH_REPLY, recv_msg_kexdh_reply}, // client | |
23 {SSH_MSG_NEWKEYS, recv_msg_newkeys}, | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
24 {SSH_MSG_SERVICE_ACCEPT, recv_msg_service_accept}, // client |
26 | 25 {SSH_MSG_CHANNEL_DATA, recv_msg_channel_data}, |
26 {SSH_MSG_CHANNEL_WINDOW_ADJUST, recv_msg_channel_window_adjust}, | |
27 {SSH_MSG_GLOBAL_REQUEST, recv_msg_global_request_remotetcp}, | |
28 {SSH_MSG_CHANNEL_REQUEST, recv_msg_channel_request}, | |
29 {SSH_MSG_CHANNEL_OPEN, recv_msg_channel_open}, | |
30 {SSH_MSG_CHANNEL_EOF, recv_msg_channel_eof}, | |
31 {SSH_MSG_CHANNEL_CLOSE, recv_msg_channel_close}, | |
32 {SSH_MSG_CHANNEL_OPEN_CONFIRMATION, recv_msg_channel_open_confirmation}, | |
33 {SSH_MSG_CHANNEL_OPEN_FAILURE, recv_msg_channel_open_failure}, | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
34 {SSH_MSG_USERAUTH_FAILURE, recv_msg_userauth_failure}, // client |
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
35 {SSH_MSG_USERAUTH_SUCCESS, recv_msg_userauth_success}, // client |
26 | 36 {0, 0} /* End */ |
37 }; | |
38 | |
39 static const struct ChanType *cli_chantypes[] = { | |
40 // &clichansess, | |
41 /* &chan_tcpdirect etc, though need to only allow if we've requested | |
42 * that forwarding */ | |
43 NULL /* Null termination */ | |
44 }; | |
33 | 45 |
26 | 46 void cli_session(int sock, char* remotehost) { |
47 | |
48 crypto_init(); | |
49 common_session_init(sock, remotehost); | |
50 | |
51 chaninitialise(cli_chantypes); | |
52 | |
53 | |
33 | 54 /* Set up cli_ses vars */ |
55 cli_session_init(); | |
26 | 56 |
57 /* Ready to go */ | |
58 sessinitdone = 1; | |
59 | |
60 /* Exchange identification */ | |
61 session_identification(); | |
62 | |
63 seedrandom(); | |
64 | |
65 send_msg_kexinit(); | |
66 | |
67 /* XXX here we do stuff differently */ | |
68 | |
69 session_loop(cli_sessionloop); | |
70 | |
71 /* Not reached */ | |
72 | |
33 | 73 } |
26 | 74 |
33 | 75 static void cli_session_init() { |
76 | |
77 cli_ses.state = STATE_NOTHING; | |
78 cli_ses.kex_state = KEX_NOTHING; | |
79 | |
80 /* For printing "remote host closed" for the user */ | |
81 ses.remoteclosed = cli_remoteclosed; | |
82 ses.buf_match_algo = cli_buf_match_algo; | |
83 | |
84 /* packet handlers */ | |
85 ses.packettypes = cli_packettypes; | |
26 | 86 } |
87 | |
33 | 88 /* This function drives the progress of the session - it initiates KEX, |
89 * service, userauth and channel requests */ | |
26 | 90 static void cli_sessionloop() { |
91 | |
33 | 92 TRACE(("enter cli_sessionloop")); |
93 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
94 if (ses.lastpacket == SSH_MSG_KEXINIT && cli_ses.kex_state == KEX_NOTHING) { |
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
95 cli_ses.kex_state = KEXINIT_RCVD; |
33 | 96 } |
97 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
98 if (cli_ses.kex_state == KEXINIT_RCVD) { |
33 | 99 |
100 /* We initiate the KEXDH. If DH wasn't the correct type, the KEXINIT | |
101 * negotiation would have failed. */ | |
102 send_msg_kexdh_init(); | |
103 cli_ses.kex_state = KEXDH_INIT_SENT; | |
104 TRACE(("leave cli_sessionloop: done with KEXINIT_RCVD")); | |
105 return; | |
106 } | |
107 | |
108 /* A KEX has finished, so we should go back to our KEX_NOTHING state */ | |
109 if (cli_ses.kex_state != KEX_NOTHING && ses.kexstate.recvkexinit == 0 | |
110 && ses.kexstate.sentkexinit == 0) { | |
111 cli_ses.kex_state = KEX_NOTHING; | |
112 } | |
113 | |
114 /* We shouldn't do anything else if a KEX is in progress */ | |
115 if (cli_ses.kex_state != KEX_NOTHING) { | |
116 TRACE(("leave cli_sessionloop: kex_state != KEX_NOTHING")); | |
117 return; | |
118 } | |
119 | |
120 /* We should exit if we haven't donefirstkex: we shouldn't reach here | |
121 * in normal operation */ | |
122 if (ses.kexstate.donefirstkex == 0) { | |
123 TRACE(("XXX XXX might be bad! leave cli_sessionloop: haven't donefirstkex")); | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
124 return; |
33 | 125 } |
126 | |
26 | 127 switch (cli_ses.state) { |
128 | |
33 | 129 case STATE_NOTHING: |
130 /* We've got the transport layer sorted, we now need to request | |
131 * userauth */ | |
132 send_msg_service_request(SSH_SERVICE_USERAUTH); | |
133 cli_ses.state = SERVICE_AUTH_REQ_SENT; | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
134 TRACE(("leave cli_sessionloop: sent userauth service req")); |
33 | 135 return; |
26 | 136 |
33 | 137 /* userauth code */ |
138 case SERVICE_AUTH_ACCEPT_RCVD: | |
139 cli_get_user(); | |
140 cli_auth_getmethods(); | |
141 cli_ses.state = USERAUTH_METHODS_SENT; | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
142 TRACE(("leave cli_sessionloop: sent userauth methods req")); |
33 | 143 return; |
144 | |
145 case USERAUTH_FAIL_RCVD: | |
146 cli_auth_try(); | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
147 TRACE(("leave cli_sessionloop: cli_auth_try")); |
33 | 148 return; |
149 | |
150 /* XXX more here needed */ | |
151 | |
152 | |
153 default: | |
154 break; | |
26 | 155 } |
156 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
157 TRACE(("leave cli_sessionloop: fell out")); |
26 | 158 |
159 } | |
160 | |
161 /* called when the remote side closes the connection */ | |
162 static void cli_remoteclosed() { | |
163 | |
164 /* XXX TODO perhaps print a friendlier message if we get this but have | |
165 * already sent/received disconnect message(s) ??? */ | |
166 close(ses.sock); | |
167 ses.sock = -1; | |
33 | 168 dropbear_exit("remote closed the connection"); |
26 | 169 } |