Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 753 lines (654 sloc) 21.993 kb
f33d7b8f » dtucker
2006-11-07 - markus@cvs.openbsd.org 2006/11/06 21:25:28
1 /* $OpenBSD: sshconnect1.c,v 1.70 2006/11/06 21:25:28 markus Exp $ */
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
2 /*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved
6 * Code to connect to a remote host, and to perform the client side of the
7 * login (authentication) dialog.
8 *
5dcef222 » djm
2000-09-16 - (djm) Merge OpenBSD changes:
9 * As far as I am concerned, the code I have written for this software
10 * can be used freely for any purpose. Any derived versions of this
11 * software must be clearly marked as such, and if the derived work is
12 * incompatible with the protocol description in the RFC file, it must be
13 * called by a name other than "ssh" or "Secure Shell".
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
14 */
15
16 #include "includes.h"
17
b8fed377 » djm
2006-08-05 - deraadt@cvs.openbsd.org 2006/08/03 03:34:42
18 #include <sys/types.h>
19 #include <sys/socket.h>
20
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
21 #include <openssl/bn.h>
dda63352 » djm
2002-02-13 - markus@cvs.openbsd.org 2002/02/11 16:15:46
22 #include <openssl/md5.h>
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
23
b6db0b7d » djm
2006-09-01 - (djm) [audit-bsm.c audit.c auth-bsdauth.c auth-chall.c auth-pam.c]
24 #include <stdarg.h>
60397fe7 » djm
2006-08-05 - stevesk@cvs.openbsd.org 2006/08/01 23:22:48
25 #include <stdio.h>
d4ac79c3 » djm
2006-08-05 - stevesk@cvs.openbsd.org 2006/07/26 13:57:17
26 #include <stdlib.h>
c4c7a1e1 » djm
2006-07-24 - stevesk@cvs.openbsd.org 2006/07/22 20:48:23
27 #include <string.h>
b8fed377 » djm
2006-08-05 - deraadt@cvs.openbsd.org 2006/08/03 03:34:42
28 #include <signal.h>
29 #include <pwd.h>
c4c7a1e1 » djm
2006-07-24 - stevesk@cvs.openbsd.org 2006/07/22 20:48:23
30
b8fed377 » djm
2006-08-05 - deraadt@cvs.openbsd.org 2006/08/03 03:34:42
31 #include "xmalloc.h"
87cd6512 » mouring
2001-01-22 Hopefully things did not get mixed around too much. It compiles under
32 #include "ssh.h"
33 #include "ssh1.h"
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
34 #include "rsa.h"
35 #include "buffer.h"
36 #include "packet.h"
b8fed377 » djm
2006-08-05 - deraadt@cvs.openbsd.org 2006/08/03 03:34:42
37 #include "key.h"
38 #include "cipher.h"
333a4d62 » dtucker
2004-05-13 - djm@cvs.openbsd.org 2004/05/09 01:19:28
39 #include "kex.h"
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
40 #include "uidswap.h"
87cd6512 » mouring
2001-01-22 Hopefully things did not get mixed around too much. It compiles under
41 #include "log.h"
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
42 #include "readconf.h"
c49c72c7 » djm
2000-07-21 - (djm) OpenBSD CVS updates:
43 #include "authfd.h"
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
44 #include "sshconnect.h"
45 #include "authfile.h"
56359cea » dtucker
2004-05-13 - djm@cvs.openbsd.org 2004/05/08 00:21:31
46 #include "misc.h"
87cd6512 » mouring
2001-01-22 Hopefully things did not get mixed around too much. It compiles under
47 #include "canohost.h"
b8fed377 » djm
2006-08-05 - deraadt@cvs.openbsd.org 2006/08/03 03:34:42
48 #include "hostfile.h"
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
49 #include "auth.h"
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
50
51 /* Session id for the current session. */
6e9d635f » mouring
2000-12-22 One way to massive patch. <sigh> It compiles and works under Linux..
52 u_char session_id[16];
53 u_int supported_authentications = 0;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
54
55 extern Options options;
56 extern char *__progname;
57
58 /*
59 * Checks if the user has an authentication agent, and if so, tries to
60 * authenticate using the agent.
61 */
46c2f2e4 » mouring
2001-06-25 - itojun@cvs.openbsd.org 2001/06/23 15:12:20
62 static int
8d39bf8f » mouring
2001-02-09 - itojun@cvs.openbsd.org 2001/02/08 19:30:52
63 try_agent_authentication(void)
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
64 {
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
65 int type;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
66 char *comment;
67 AuthenticationConnection *auth;
6e9d635f » mouring
2000-12-22 One way to massive patch. <sigh> It compiles and works under Linux..
68 u_char response[16];
69 u_int i;
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
70 Key *key;
71 BIGNUM *challenge;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
72
73 /* Get connection to the agent. */
74 auth = ssh_get_authentication_connection();
75 if (!auth)
76 return 0;
77
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
78 if ((challenge = BN_new()) == NULL)
79 fatal("try_agent_authentication: BN_new failed");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
80 /* Loop through identities served by the agent. */
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
81 for (key = ssh_get_first_identity(auth, &comment, 1);
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
82 key != NULL;
83 key = ssh_get_next_identity(auth, &comment, 1)) {
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
84
85 /* Try this identity. */
86 debug("Trying RSA authentication via agent with '%.100s'", comment);
87 xfree(comment);
88
89 /* Tell the server that we are willing to authenticate using this key. */
90 packet_start(SSH_CMSG_AUTH_RSA);
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
91 packet_put_bignum(key->rsa->n);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
92 packet_send();
93 packet_write_wait();
94
95 /* Wait for server's response. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
96 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
97
fc42feb4 » djm
2005-11-05 - djm@cvs.openbsd.org 2005/10/30 08:52:18
98 /* The server sends failure if it doesn't like our key or
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
99 does not support RSA authentication. */
100 if (type == SSH_SMSG_FAILURE) {
101 debug("Server refused our key.");
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
102 key_free(key);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
103 continue;
104 }
105 /* Otherwise it should have sent a challenge. */
106 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
107 packet_disconnect("Protocol error during RSA authentication: %d",
108 type);
109
79838b1a » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 13:57:33
110 packet_get_bignum(challenge);
91ff6634 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 20:39:58
111 packet_check_eom();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
112
113 debug("Received RSA challenge from server.");
114
115 /* Ask the agent to decrypt the challenge. */
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
116 if (!ssh_decrypt_challenge(auth, key, challenge, session_id, 1, response)) {
117 /*
118 * The agent failed to authenticate this identifier
119 * although it advertised it supports this. Just
120 * return a wrong value.
121 */
e0b8a6dd » djm
2003-04-09 *** empty log message ***
122 logit("Authentication agent failed to decrypt challenge.");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
123 memset(response, 0, sizeof(response));
124 }
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
125 key_free(key);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
126 debug("Sending response to RSA challenge.");
127
128 /* Send the decrypted challenge back to the server. */
129 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
130 for (i = 0; i < 16; i++)
131 packet_put_char(response[i]);
132 packet_send();
133 packet_write_wait();
134
135 /* Wait for response from the server. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
136 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
137
138 /* The server returns success if it accepted the authentication. */
139 if (type == SSH_SMSG_SUCCESS) {
0d32322d » mouring
2001-01-09 - (bal) OpenBSD Sync
140 ssh_close_authentication_connection(auth);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
141 BN_clear_free(challenge);
3b879a08 » djm
2000-08-23 - (djm) Pick up LOGIN_PROGRAM from environment or PATH if not set by…
142 debug("RSA authentication accepted by server.");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
143 return 1;
144 }
145 /* Otherwise it should return failure. */
146 if (type != SSH_SMSG_FAILURE)
147 packet_disconnect("Protocol error waiting RSA auth response: %d",
148 type);
149 }
0d32322d » mouring
2001-01-09 - (bal) OpenBSD Sync
150 ssh_close_authentication_connection(auth);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
151 BN_clear_free(challenge);
152 debug("RSA authentication using agent refused.");
153 return 0;
154 }
155
156 /*
157 * Computes the proper response to a RSA challenge, and sends the response to
158 * the server.
159 */
46c2f2e4 » mouring
2001-06-25 - itojun@cvs.openbsd.org 2001/06/23 15:12:20
160 static void
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
161 respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv)
162 {
6e9d635f » mouring
2000-12-22 One way to massive patch. <sigh> It compiles and works under Linux..
163 u_char buf[32], response[16];
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
164 MD5_CTX md;
165 int i, len;
166
167 /* Decrypt the challenge using the private key. */
1647920b » djm
2001-01-29 - (djm) OpenBSD CVS Sync:
168 /* XXX think about Bleichenbacher, too */
169 if (rsa_private_decrypt(challenge, challenge, prv) <= 0)
170 packet_disconnect(
171 "respond_to_rsa_challenge: rsa_private_decrypt failed");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
172
173 /* Compute the response. */
174 /* The response is MD5 of decrypted challenge plus session id. */
175 len = BN_num_bytes(challenge);
f0513c08 » djm
2005-06-17 - djm@cvs.openbsd.org 2005/06/17 02:44:33
176 if (len <= 0 || (u_int)len > sizeof(buf))
1647920b » djm
2001-01-29 - (djm) OpenBSD CVS Sync:
177 packet_disconnect(
178 "respond_to_rsa_challenge: bad challenge length %d", len);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
179
180 memset(buf, 0, sizeof(buf));
181 BN_bn2bin(challenge, buf + sizeof(buf) - len);
182 MD5_Init(&md);
183 MD5_Update(&md, buf, 32);
184 MD5_Update(&md, session_id, 16);
185 MD5_Final(response, &md);
186
187 debug("Sending response to host key RSA challenge.");
188
189 /* Send the response back to the server. */
190 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
191 for (i = 0; i < 16; i++)
192 packet_put_char(response[i]);
193 packet_send();
194 packet_write_wait();
195
196 memset(buf, 0, sizeof(buf));
197 memset(response, 0, sizeof(response));
198 memset(&md, 0, sizeof(md));
199 }
200
201 /*
202 * Checks if the user has authentication file, and if so, tries to authenticate
203 * the user using it.
204 */
46c2f2e4 » mouring
2001-06-25 - itojun@cvs.openbsd.org 2001/06/23 15:12:20
205 static int
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
206 try_rsa_authentication(int idx)
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
207 {
208 BIGNUM *challenge;
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
209 Key *public, *private;
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
210 char buf[300], *passphrase, *comment, *authfile;
07a9ba7b » dtucker
2006-05-06 - dtucker@cvs.openbsd.org 2006/04/25 08:02:27
211 int i, perm_ok = 1, type, quit;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
212
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
213 public = options.identity_keys[idx];
214 authfile = options.identity_files[idx];
215 comment = xstrdup(authfile);
216
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
217 debug("Trying RSA authentication with key '%.100s'", comment);
218
219 /* Tell the server that we are willing to authenticate using this key. */
220 packet_start(SSH_CMSG_AUTH_RSA);
221 packet_put_bignum(public->rsa->n);
222 packet_send();
223 packet_write_wait();
224
225 /* Wait for server's response. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
226 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
227
228 /*
fc42feb4 » djm
2005-11-05 - djm@cvs.openbsd.org 2005/10/30 08:52:18
229 * The server responds with failure if it doesn't like our key or
230 * doesn't support RSA authentication.
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
231 */
232 if (type == SSH_SMSG_FAILURE) {
233 debug("Server refused our key.");
234 xfree(comment);
235 return 0;
236 }
237 /* Otherwise, the server should respond with a challenge. */
238 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
239 packet_disconnect("Protocol error during RSA authentication: %d", type);
240
241 /* Get the challenge from the packet. */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
242 if ((challenge = BN_new()) == NULL)
243 fatal("try_rsa_authentication: BN_new failed");
79838b1a » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 13:57:33
244 packet_get_bignum(challenge);
91ff6634 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 20:39:58
245 packet_check_eom();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
246
247 debug("Received RSA challenge from server.");
248
249 /*
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
250 * If the key is not stored in external hardware, we have to
251 * load the private key. Try first with empty passphrase; if it
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
252 * fails, ask for a passphrase.
253 */
f96c3546 » mouring
2002-08-20 - aaron@cvs.openbsd.org 2002/08/08 13:50:23
254 if (public->flags & KEY_FLAG_EXT)
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
255 private = public;
256 else
07a9ba7b » dtucker
2006-05-06 - dtucker@cvs.openbsd.org 2006/04/25 08:02:27
257 private = key_load_private_type(KEY_RSA1, authfile, "", NULL,
258 &perm_ok);
259 if (private == NULL && !options.batch_mode && perm_ok) {
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
260 snprintf(buf, sizeof(buf),
261 "Enter passphrase for RSA key '%.100s': ", comment);
262 for (i = 0; i < options.number_of_password_prompts; i++) {
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
263 passphrase = read_passphrase(buf, 0);
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
264 if (strcmp(passphrase, "") != 0) {
265 private = key_load_private_type(KEY_RSA1,
07a9ba7b » dtucker
2006-05-06 - dtucker@cvs.openbsd.org 2006/04/25 08:02:27
266 authfile, passphrase, NULL, NULL);
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
267 quit = 0;
268 } else {
269 debug2("no passphrase given, try next key");
270 quit = 1;
271 }
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
272 memset(passphrase, 0, strlen(passphrase));
273 xfree(passphrase);
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
274 if (private != NULL || quit)
275 break;
276 debug2("bad passphrase given, try again...");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
277 }
278 }
279 /* We no longer need the comment. */
280 xfree(comment);
281
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
282 if (private == NULL) {
07a9ba7b » dtucker
2006-05-06 - dtucker@cvs.openbsd.org 2006/04/25 08:02:27
283 if (!options.batch_mode && perm_ok)
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
284 error("Bad passphrase.");
285
286 /* Send a dummy response packet to avoid protocol error. */
287 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
288 for (i = 0; i < 16; i++)
289 packet_put_char(0);
290 packet_send();
291 packet_write_wait();
292
293 /* Expect the server to reject it... */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
294 packet_read_expect(SSH_SMSG_FAILURE);
8178faa7 » mouring
2001-06-25 - markus@cvs.openbsd.org 2001/06/23 22:37:46
295 BN_clear_free(challenge);
296 return 0;
297 }
298
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
299 /* Compute and send a response to the challenge. */
300 respond_to_rsa_challenge(challenge, private->rsa);
301
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
302 /* Destroy the private key unless it in external hardware. */
303 if (!(private->flags & KEY_FLAG_EXT))
304 key_free(private);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
305
306 /* We no longer need the challenge. */
307 BN_clear_free(challenge);
308
309 /* Wait for response from the server. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
310 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
311 if (type == SSH_SMSG_SUCCESS) {
312 debug("RSA authentication accepted by server.");
313 return 1;
314 }
315 if (type != SSH_SMSG_FAILURE)
316 packet_disconnect("Protocol error waiting RSA auth response: %d", type);
317 debug("RSA authentication refused.");
318 return 0;
319 }
320
321 /*
322 * Tries to authenticate the user using combined rhosts or /etc/hosts.equiv
323 * authentication and RSA host authentication.
324 */
46c2f2e4 » mouring
2001-06-25 - itojun@cvs.openbsd.org 2001/06/23 15:12:20
325 static int
8e1c9c5d » mouring
2001-03-26 - markus@cvs.openbsd.org 2001/03/26 08:07:09
326 try_rhosts_rsa_authentication(const char *local_user, Key * host_key)
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
327 {
328 int type;
329 BIGNUM *challenge;
330
331 debug("Trying rhosts or /etc/hosts.equiv with RSA host authentication.");
332
333 /* Tell the server that we are willing to authenticate using this key. */
334 packet_start(SSH_CMSG_AUTH_RHOSTS_RSA);
1df8433e » mouring
2001-06-09 - markus@cvs.openbsd.org 2001/06/07 20:23:05
335 packet_put_cstring(local_user);
8e1c9c5d » mouring
2001-03-26 - markus@cvs.openbsd.org 2001/03/26 08:07:09
336 packet_put_int(BN_num_bits(host_key->rsa->n));
337 packet_put_bignum(host_key->rsa->e);
338 packet_put_bignum(host_key->rsa->n);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
339 packet_send();
340 packet_write_wait();
341
342 /* Wait for server's response. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
343 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
344
345 /* The server responds with failure if it doesn't admit our
346 .rhosts authentication or doesn't know our host key. */
347 if (type == SSH_SMSG_FAILURE) {
348 debug("Server refused our rhosts authentication or host key.");
349 return 0;
350 }
351 /* Otherwise, the server should respond with a challenge. */
352 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
353 packet_disconnect("Protocol error during RSA authentication: %d", type);
354
355 /* Get the challenge from the packet. */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
356 if ((challenge = BN_new()) == NULL)
357 fatal("try_rhosts_rsa_authentication: BN_new failed");
79838b1a » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 13:57:33
358 packet_get_bignum(challenge);
91ff6634 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 20:39:58
359 packet_check_eom();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
360
361 debug("Received RSA challenge for host key from server.");
362
363 /* Compute a response to the challenge. */
8e1c9c5d » mouring
2001-03-26 - markus@cvs.openbsd.org 2001/03/26 08:07:09
364 respond_to_rsa_challenge(challenge, host_key->rsa);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
365
366 /* We no longer need the challenge. */
367 BN_clear_free(challenge);
368
369 /* Wait for response from the server. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
370 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
371 if (type == SSH_SMSG_SUCCESS) {
372 debug("Rhosts or /etc/hosts.equiv with RSA host authentication accepted by server.");
373 return 1;
374 }
375 if (type != SSH_SMSG_FAILURE)
376 packet_disconnect("Protocol error waiting RSA auth response: %d", type);
377 debug("Rhosts or /etc/hosts.equiv with RSA host authentication refused.");
378 return 0;
379 }
380
381 /*
382 * Tries to authenticate with any string-based challenge/response system.
383 * Note that the client code is not tied to s/key or TIS.
384 */
46c2f2e4 » mouring
2001-06-25 - itojun@cvs.openbsd.org 2001/06/23 15:12:20
385 static int
0bf2c7fd » mouring
2001-06-05 - markus@cvs.openbsd.org 2001/05/18 14:13:29
386 try_challenge_response_authentication(void)
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
387 {
388 int type, i;
6e9d635f » mouring
2000-12-22 One way to massive patch. <sigh> It compiles and works under Linux..
389 u_int clen;
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
390 char prompt[1024];
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
391 char *challenge, *response;
281733aa » mouring
2001-10-03 - markus@cvs.openbsd.org 2001/09/27 15:31:17
392
393 debug("Doing challenge response authentication.");
394
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
395 for (i = 0; i < options.number_of_password_prompts; i++) {
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
396 /* request a challenge */
397 packet_start(SSH_CMSG_AUTH_TIS);
398 packet_send();
399 packet_write_wait();
400
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
401 type = packet_read();
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
402 if (type != SSH_SMSG_FAILURE &&
403 type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
404 packet_disconnect("Protocol error: got %d in response "
8a6fac32 » mouring
2001-01-23 - markus@cvs.openbsd.org 2001/01/22 23:06:39
405 "to SSH_CMSG_AUTH_TIS", type);
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
406 }
407 if (type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
8a6fac32 » mouring
2001-01-23 - markus@cvs.openbsd.org 2001/01/22 23:06:39
408 debug("No challenge.");
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
409 return 0;
410 }
411 challenge = packet_get_string(&clen);
91ff6634 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 20:39:58
412 packet_check_eom();
ed6dd227 » mouring
2001-01-19 Please grep through the source and look for 'ISSUE' comments and verify
413 snprintf(prompt, sizeof prompt, "%s%s", challenge,
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
414 strchr(challenge, '\n') ? "" : "\nResponse: ");
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
415 xfree(challenge);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
416 if (i != 0)
417 error("Permission denied, please try again.");
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
418 if (options.cipher == SSH_CIPHER_NONE)
e0b8a6dd » djm
2003-04-09 *** empty log message ***
419 logit("WARNING: Encryption is disabled! "
5092538e » djm
2002-04-23 - stevesk@cvs.openbsd.org 2002/04/21 16:25:06
420 "Response will be transmitted in clear text.");
81681025 » mouring
2000-12-10 - (bal) OpenBSD CVS update
421 response = read_passphrase(prompt, 0);
422 if (strcmp(response, "") == 0) {
423 xfree(response);
424 break;
425 }
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
426 packet_start(SSH_CMSG_AUTH_TIS_RESPONSE);
7e8706ca » djm
2001-02-16 - (djm) OpenBSD CVS:
427 ssh_put_password(response);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
428 memset(response, 0, strlen(response));
429 xfree(response);
430 packet_send();
431 packet_write_wait();
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
432 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
433 if (type == SSH_SMSG_SUCCESS)
434 return 1;
435 if (type != SSH_SMSG_FAILURE)
436 packet_disconnect("Protocol error: got %d in response "
8a6fac32 » mouring
2001-01-23 - markus@cvs.openbsd.org 2001/01/22 23:06:39
437 "to SSH_CMSG_AUTH_TIS_RESPONSE", type);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
438 }
439 /* failure */
440 return 0;
441 }
442
443 /*
444 * Tries to authenticate with plain passwd authentication.
445 */
46c2f2e4 » mouring
2001-06-25 - itojun@cvs.openbsd.org 2001/06/23 15:12:20
446 static int
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
447 try_password_authentication(char *prompt)
448 {
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
449 int type, i;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
450 char *password;
451
452 debug("Doing password authentication.");
453 if (options.cipher == SSH_CIPHER_NONE)
e0b8a6dd » djm
2003-04-09 *** empty log message ***
454 logit("WARNING: Encryption is disabled! Password will be transmitted in clear text.");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
455 for (i = 0; i < options.number_of_password_prompts; i++) {
456 if (i != 0)
457 error("Permission denied, please try again.");
458 password = read_passphrase(prompt, 0);
459 packet_start(SSH_CMSG_AUTH_PASSWORD);
7e8706ca » djm
2001-02-16 - (djm) OpenBSD CVS:
460 ssh_put_password(password);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
461 memset(password, 0, strlen(password));
462 xfree(password);
463 packet_send();
464 packet_write_wait();
465
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
466 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
467 if (type == SSH_SMSG_SUCCESS)
468 return 1;
469 if (type != SSH_SMSG_FAILURE)
470 packet_disconnect("Protocol error: got %d in response to passwd auth", type);
471 }
472 /* failure */
473 return 0;
474 }
475
476 /*
477 * SSH1 key exchange
478 */
479 void
480 ssh_kex(char *host, struct sockaddr *hostaddr)
481 {
482 int i;
483 BIGNUM *key;
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
484 Key *host_key, *server_key;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
485 int bits, rbits;
486 int ssh_cipher_default = SSH_CIPHER_3DES;
6e9d635f » mouring
2000-12-22 One way to massive patch. <sigh> It compiles and works under Linux..
487 u_char session_key[SSH_SESSION_KEY_LENGTH];
488 u_char cookie[8];
489 u_int supported_ciphers;
490 u_int server_flags, client_flags;
15cb3d76 » dtucker
2004-06-22 - avsm@cvs.openbsd.org 2004/06/21 17:36:31
491 u_int32_t rnd = 0;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
492
493 debug("Waiting for server public key.");
494
495 /* Wait for a public key packet from the server. */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
496 packet_read_expect(SSH_SMSG_PUBLIC_KEY);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
497
498 /* Get cookie from the packet. */
499 for (i = 0; i < 8; i++)
500 cookie[i] = packet_get_char();
501
502 /* Get the public key. */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
503 server_key = key_new(KEY_RSA1);
504 bits = packet_get_int();
79838b1a » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 13:57:33
505 packet_get_bignum(server_key->rsa->e);
506 packet_get_bignum(server_key->rsa->n);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
507
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
508 rbits = BN_num_bits(server_key->rsa->n);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
509 if (bits != rbits) {
e0b8a6dd » djm
2003-04-09 *** empty log message ***
510 logit("Warning: Server lies about size of server public key: "
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
511 "actual size is %d bits vs. announced %d.", rbits, bits);
e0b8a6dd » djm
2003-04-09 *** empty log message ***
512 logit("Warning: This may be due to an old implementation of ssh.");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
513 }
514 /* Get the host key. */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
515 host_key = key_new(KEY_RSA1);
516 bits = packet_get_int();
79838b1a » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 13:57:33
517 packet_get_bignum(host_key->rsa->e);
518 packet_get_bignum(host_key->rsa->n);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
519
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
520 rbits = BN_num_bits(host_key->rsa->n);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
521 if (bits != rbits) {
e0b8a6dd » djm
2003-04-09 *** empty log message ***
522 logit("Warning: Server lies about size of server host key: "
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
523 "actual size is %d bits vs. announced %d.", rbits, bits);
e0b8a6dd » djm
2003-04-09 *** empty log message ***
524 logit("Warning: This may be due to an old implementation of ssh.");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
525 }
526
527 /* Get protocol flags. */
528 server_flags = packet_get_int();
529 packet_set_protocol_flags(server_flags);
530
531 supported_ciphers = packet_get_int();
532 supported_authentications = packet_get_int();
91ff6634 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 20:39:58
533 packet_check_eom();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
534
535 debug("Received server public key (%d bits) and host key (%d bits).",
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
536 BN_num_bits(server_key->rsa->n), BN_num_bits(host_key->rsa->n));
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
537
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
538 if (verify_host_key(host, hostaddr, host_key) == -1)
7cef5bdc » djm
2001-10-10 - markus@cvs.openbsd.org 2001/10/06 11:18:19
539 fatal("Host key verification failed.");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
540
541 client_flags = SSH_PROTOFLAG_SCREEN_NUMBER | SSH_PROTOFLAG_HOST_IN_FWD_OPEN;
542
333a4d62 » dtucker
2004-05-13 - djm@cvs.openbsd.org 2004/05/09 01:19:28
543 derive_ssh1_session_id(host_key->rsa->n, server_key->rsa->n, cookie, session_id);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
544
545 /* Generate a session key. */
546 arc4random_stir();
547
548 /*
549 * Generate an encryption key for the session. The key is a 256 bit
550 * random number, interpreted as a 32-byte key, with the least
551 * significant 8 bits being the first byte of the key.
552 */
553 for (i = 0; i < 32; i++) {
554 if (i % 4 == 0)
15cb3d76 » dtucker
2004-06-22 - avsm@cvs.openbsd.org 2004/06/21 17:36:31
555 rnd = arc4random();
556 session_key[i] = rnd & 0xff;
557 rnd >>= 8;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
558 }
559
560 /*
561 * According to the protocol spec, the first byte of the session key
562 * is the highest byte of the integer. The session key is xored with
563 * the first 16 bytes of the session id.
564 */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
565 if ((key = BN_new()) == NULL)
f33d7b8f » dtucker
2006-11-07 - markus@cvs.openbsd.org 2006/11/06 21:25:28
566 fatal("ssh_kex: BN_new failed");
567 if (BN_set_word(key, 0) == 0)
568 fatal("ssh_kex: BN_set_word failed");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
569 for (i = 0; i < SSH_SESSION_KEY_LENGTH; i++) {
f33d7b8f » dtucker
2006-11-07 - markus@cvs.openbsd.org 2006/11/06 21:25:28
570 if (BN_lshift(key, key, 8) == 0)
571 fatal("ssh_kex: BN_lshift failed");
572 if (i < 16) {
573 if (BN_add_word(key, session_key[i] ^ session_id[i])
574 == 0)
575 fatal("ssh_kex: BN_add_word failed");
576 } else {
577 if (BN_add_word(key, session_key[i]) == 0)
578 fatal("ssh_kex: BN_add_word failed");
579 }
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
580 }
581
582 /*
583 * Encrypt the integer using the public key and host key of the
584 * server (key with smaller modulus first).
585 */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
586 if (BN_cmp(server_key->rsa->n, host_key->rsa->n) < 0) {
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
587 /* Public key has smaller modulus. */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
588 if (BN_num_bits(host_key->rsa->n) <
589 BN_num_bits(server_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
590 fatal("respond_to_rsa_challenge: host_key %d < server_key %d + "
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
591 "SSH_KEY_BITS_RESERVED %d",
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
592 BN_num_bits(host_key->rsa->n),
593 BN_num_bits(server_key->rsa->n),
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
594 SSH_KEY_BITS_RESERVED);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
595 }
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
596 rsa_public_encrypt(key, key, server_key->rsa);
597 rsa_public_encrypt(key, key, host_key->rsa);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
598 } else {
599 /* Host key has smaller modulus (or they are equal). */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
600 if (BN_num_bits(server_key->rsa->n) <
601 BN_num_bits(host_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
602 fatal("respond_to_rsa_challenge: server_key %d < host_key %d + "
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
603 "SSH_KEY_BITS_RESERVED %d",
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
604 BN_num_bits(server_key->rsa->n),
605 BN_num_bits(host_key->rsa->n),
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
606 SSH_KEY_BITS_RESERVED);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
607 }
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
608 rsa_public_encrypt(key, key, host_key->rsa);
609 rsa_public_encrypt(key, key, server_key->rsa);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
610 }
611
612 /* Destroy the public keys since we no longer need them. */
c3ed7915 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/27 18:22:16
613 key_free(server_key);
614 key_free(host_key);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
615
d602c776 » djm
2000-11-29 - (djm) OpenBSD CVS updates:
616 if (options.cipher == SSH_CIPHER_NOT_SET) {
617 if (cipher_mask_ssh1(1) & supported_ciphers & (1 << ssh_cipher_default))
618 options.cipher = ssh_cipher_default;
b0b80f43 » dtucker
2004-08-12 - markus@cvs.openbsd.org 2004/07/28 09:40:29
619 } else if (options.cipher == SSH_CIPHER_INVALID ||
d602c776 » djm
2000-11-29 - (djm) OpenBSD CVS updates:
620 !(cipher_mask_ssh1(1) & (1 << options.cipher))) {
e0b8a6dd » djm
2003-04-09 *** empty log message ***
621 logit("No valid SSH1 cipher, using %.100s instead.",
fa6c9c51 » djm
2000-10-14 - (djm) Big OpenBSD sync:
622 cipher_name(ssh_cipher_default));
623 options.cipher = ssh_cipher_default;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
624 }
625 /* Check that the selected cipher is supported. */
626 if (!(supported_ciphers & (1 << options.cipher)))
627 fatal("Selected cipher type %.100s not supported by server.",
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
628 cipher_name(options.cipher));
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
629
630 debug("Encryption type: %.100s", cipher_name(options.cipher));
631
632 /* Send the encrypted session key to the server. */
633 packet_start(SSH_CMSG_SESSION_KEY);
634 packet_put_char(options.cipher);
635
636 /* Send the cookie back to the server. */
637 for (i = 0; i < 8; i++)
638 packet_put_char(cookie[i]);
639
640 /* Send and destroy the encrypted encryption key integer. */
641 packet_put_bignum(key);
642 BN_clear_free(key);
643
644 /* Send protocol flags. */
645 packet_put_int(client_flags);
646
647 /* Send the packet now. */
648 packet_send();
649 packet_write_wait();
650
651 debug("Sent encrypted session key.");
652
653 /* Set the encryption key. */
654 packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, options.cipher);
655
656 /* We will no longer need the session key here. Destroy any extra copies. */
657 memset(session_key, 0, sizeof(session_key));
658
659 /*
660 * Expect a success message from the server. Note that this message
661 * will be received in encrypted form.
662 */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
663 packet_read_expect(SSH_SMSG_SUCCESS);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
664
665 debug("Received encrypted confirmation.");
666 }
667
668 /*
669 * Authenticate user
670 */
671 void
f23e2391 » mouring
2001-04-12 - markus@cvs.openbsd.org 2001/04/12 19:15:26
672 ssh_userauth1(const char *local_user, const char *server_user, char *host,
cf3298db » mouring
2002-06-06 - markus@cvs.openbsd.org 2002/05/23 19:24:30
673 Sensitive *sensitive)
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
674 {
675 int i, type;
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
676
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
677 if (supported_authentications == 0)
f23e2391 » mouring
2001-04-12 - markus@cvs.openbsd.org 2001/04/12 19:15:26
678 fatal("ssh_userauth1: server supports no auth methods");
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
679
680 /* Send the name of the user to log in as on the server. */
681 packet_start(SSH_CMSG_USER);
1df8433e » mouring
2001-06-09 - markus@cvs.openbsd.org 2001/06/07 20:23:05
682 packet_put_cstring(server_user);
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
683 packet_send();
684 packet_write_wait();
685
686 /*
687 * The server should respond with success if no authentication is
688 * needed (the user has no password). Otherwise the server responds
689 * with failure.
690 */
ea1aba71 » djm
2002-01-22 - markus@cvs.openbsd.org 2001/12/28 14:50:54
691 type = packet_read();
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
692
693 /* check whether the connection was accepted without authentication. */
694 if (type == SSH_SMSG_SUCCESS)
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
695 goto success;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
696 if (type != SSH_SMSG_FAILURE)
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
697 packet_disconnect("Protocol error: got %d in response to SSH_CMSG_USER", type);
4da568dd » djm
2001-12-21 - deraadt@cvs.openbsd.org 2001/12/19 07:18:56
698
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
699 /*
700 * Try .rhosts or /etc/hosts.equiv authentication with RSA host
701 * authentication.
702 */
703 if ((supported_authentications & (1 << SSH_AUTH_RHOSTS_RSA)) &&
f23e2391 » mouring
2001-04-12 - markus@cvs.openbsd.org 2001/04/12 19:15:26
704 options.rhosts_rsa_authentication) {
cf3298db » mouring
2002-06-06 - markus@cvs.openbsd.org 2002/05/23 19:24:30
705 for (i = 0; i < sensitive->nkeys; i++) {
706 if (sensitive->keys[i] != NULL &&
707 sensitive->keys[i]->type == KEY_RSA1 &&
708 try_rhosts_rsa_authentication(local_user,
709 sensitive->keys[i]))
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
710 goto success;
f23e2391 » mouring
2001-04-12 - markus@cvs.openbsd.org 2001/04/12 19:15:26
711 }
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
712 }
713 /* Try RSA authentication if the server supports it. */
714 if ((supported_authentications & (1 << SSH_AUTH_RSA)) &&
715 options.rsa_authentication) {
716 /*
717 * Try RSA authentication using the authentication agent. The
718 * agent is tried first because no passphrase is needed for
719 * it, whereas identity files may require passphrases.
720 */
721 if (try_agent_authentication())
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
722 goto success;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
723
724 /* Try RSA authentication for each identity. */
725 for (i = 0; i < options.num_identity_files; i++)
eb5d7353 » mouring
2001-03-09 - markus@cvs.openbsd.org 2001/03/08 21:42:33
726 if (options.identity_keys[i] != NULL &&
727 options.identity_keys[i]->type == KEY_RSA1 &&
ec3975d3 » mouring
2001-07-04 - markus@cvs.openbsd.org 2001/06/26 20:14:11
728 try_rsa_authentication(i))
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
729 goto success;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
730 }
8a6fac32 » mouring
2001-01-23 - markus@cvs.openbsd.org 2001/01/22 23:06:39
731 /* Try challenge response authentication if the server supports it. */
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
732 if ((supported_authentications & (1 << SSH_AUTH_TIS)) &&
0bf2c7fd » mouring
2001-06-05 - markus@cvs.openbsd.org 2001/05/18 14:13:29
733 options.challenge_response_authentication && !options.batch_mode) {
734 if (try_challenge_response_authentication())
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
735 goto success;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
736 }
737 /* Try password authentication if the server supports it. */
738 if ((supported_authentications & (1 << SSH_AUTH_PASSWORD)) &&
739 options.password_authentication && !options.batch_mode) {
740 char prompt[80];
741
bb71eb66 » mouring
2001-02-11 - itojun@cvs.opebsd.org 2001/02/08 10:47:05
742 snprintf(prompt, sizeof(prompt), "%.30s@%.128s's password: ",
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
743 server_user, host);
744 if (try_password_authentication(prompt))
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
745 goto success;
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
746 }
747 /* All authentication methods have failed. Exit with an error message. */
748 fatal("Permission denied.");
749 /* NOTREACHED */
c8f5d68e » mouring
2001-07-04 - dugsong@cvs.openbsd.org 2001/06/26 16:15:25
750
751 success:
871e7755 » djm
2001-07-14 - OpenBSD CVS Sync
752 return; /* need statement after label */
5f114f04 » damien
2000-04-29 - Merge big update to OpenSSH-2.0 from OpenBSD CVS
753 }
Something went wrong with that request. Please try again.