Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
| 3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 4 | * All rights reserved |
| 5 | * Created: Fri Mar 17 17:09:28 1995 ylo |
| 6 | * This program is the ssh daemon. It listens for connections from clients, and |
| 7 | * performs authentication, executes use commands or shell, and forwards |
| 8 | * information to/from the application to the user client over an encrypted |
| 9 | * connection. This can also handle forwarding of X11, TCP/IP, and authentication |
| 10 | * agent connections. |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 11 | * |
| 12 | * SSH2 implementation, |
| 13 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 14 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 15 | |
| 16 | #include "includes.h" |
Damien Miller | bf7f466 | 2000-06-23 10:16:38 +1000 | [diff] [blame] | 17 | RCSID("$OpenBSD: sshd.c,v 1.119 2000/06/22 16:32:27 markus Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 18 | |
| 19 | #include "xmalloc.h" |
| 20 | #include "rsa.h" |
| 21 | #include "ssh.h" |
| 22 | #include "pty.h" |
| 23 | #include "packet.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 24 | #include "cipher.h" |
| 25 | #include "mpaux.h" |
| 26 | #include "servconf.h" |
| 27 | #include "uidswap.h" |
| 28 | #include "compat.h" |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 29 | #include "buffer.h" |
| 30 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 31 | #include "ssh2.h" |
Damien Miller | 5f05637 | 2000-04-16 12:31:48 +1000 | [diff] [blame] | 32 | #include <openssl/dh.h> |
| 33 | #include <openssl/bn.h> |
| 34 | #include <openssl/hmac.h> |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 35 | #include "kex.h" |
Damien Miller | 5f05637 | 2000-04-16 12:31:48 +1000 | [diff] [blame] | 36 | #include <openssl/dsa.h> |
| 37 | #include <openssl/rsa.h> |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 38 | #include "key.h" |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 39 | #include "dsa.h" |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 40 | |
| 41 | #include "auth.h" |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 42 | #include "myproposal.h" |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 43 | #include "authfile.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 44 | |
| 45 | #ifdef LIBWRAP |
| 46 | #include <tcpd.h> |
| 47 | #include <syslog.h> |
| 48 | int allow_severity = LOG_INFO; |
| 49 | int deny_severity = LOG_WARNING; |
| 50 | #endif /* LIBWRAP */ |
| 51 | |
| 52 | #ifndef O_NOCTTY |
| 53 | #define O_NOCTTY 0 |
| 54 | #endif |
| 55 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 56 | /* Server configuration options. */ |
| 57 | ServerOptions options; |
| 58 | |
| 59 | /* Name of the server configuration file. */ |
| 60 | char *config_file_name = SERVER_CONFIG_FILE; |
| 61 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 62 | /* |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 63 | * Flag indicating whether IPv4 or IPv6. This can be set on the command line. |
| 64 | * Default value is AF_UNSPEC means both IPv4 and IPv6. |
| 65 | */ |
Damien Miller | 7d80e34 | 2000-01-19 14:36:49 +1100 | [diff] [blame] | 66 | #ifdef IPV4_DEFAULT |
| 67 | int IPv4or6 = AF_INET; |
| 68 | #else |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 69 | int IPv4or6 = AF_UNSPEC; |
Damien Miller | 7d80e34 | 2000-01-19 14:36:49 +1100 | [diff] [blame] | 70 | #endif |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 71 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 72 | /* |
| 73 | * Debug mode flag. This can be set on the command line. If debug |
| 74 | * mode is enabled, extra debugging output will be sent to the system |
| 75 | * log, the daemon will not go to background, and will exit after processing |
| 76 | * the first connection. |
| 77 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 78 | int debug_flag = 0; |
| 79 | |
| 80 | /* Flag indicating that the daemon is being started from inetd. */ |
| 81 | int inetd_flag = 0; |
| 82 | |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 83 | /* debug goes to stderr unless inetd_flag is set */ |
| 84 | int log_stderr = 0; |
| 85 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 86 | /* argv[0] without path. */ |
| 87 | char *av0; |
| 88 | |
| 89 | /* Saved arguments to main(). */ |
| 90 | char **saved_argv; |
Damien Miller | b8c656e | 2000-06-28 15:22:41 +1000 | [diff] [blame^] | 91 | int saved_argc; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 92 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 93 | /* |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 94 | * The sockets that the server is listening; this is used in the SIGHUP |
| 95 | * signal handler. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 96 | */ |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 97 | #define MAX_LISTEN_SOCKS 16 |
| 98 | int listen_socks[MAX_LISTEN_SOCKS]; |
| 99 | int num_listen_socks = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 100 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 101 | /* |
| 102 | * the client's version string, passed by sshd2 in compat mode. if != NULL, |
| 103 | * sshd will skip the version-number exchange |
| 104 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 105 | char *client_version_string = NULL; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 106 | char *server_version_string = NULL; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 107 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 108 | /* |
| 109 | * Any really sensitive data in the application is contained in this |
| 110 | * structure. The idea is that this structure could be locked into memory so |
| 111 | * that the pages do not get written into swap. However, there are some |
| 112 | * problems. The private key contains BIGNUMs, and we do not (in principle) |
| 113 | * have access to the internals of them, and locking just the structure is |
| 114 | * not very useful. Currently, memory locking is not implemented. |
| 115 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 116 | struct { |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 117 | RSA *private_key; /* Private part of empheral server key. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 118 | RSA *host_key; /* Private part of host key. */ |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 119 | Key *dsa_host_key; /* Private DSA host key. */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 120 | } sensitive_data; |
| 121 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 122 | /* |
| 123 | * Flag indicating whether the current session key has been used. This flag |
| 124 | * is set whenever the key is used, and cleared when the key is regenerated. |
| 125 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 126 | int key_used = 0; |
| 127 | |
| 128 | /* This is set to true when SIGHUP is received. */ |
| 129 | int received_sighup = 0; |
| 130 | |
| 131 | /* Public side of the server key. This value is regenerated regularly with |
| 132 | the private key. */ |
| 133 | RSA *public_key; |
| 134 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 135 | /* session identifier, used by RSA-auth */ |
| 136 | unsigned char session_id[16]; |
| 137 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 138 | /* same for ssh2 */ |
| 139 | unsigned char *session_id2 = NULL; |
| 140 | int session_id2_len = 0; |
| 141 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 142 | /* Prototypes for various functions defined later in this file. */ |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 143 | void do_ssh1_kex(); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 144 | void do_ssh2_kex(); |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 145 | |
| 146 | /* |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 147 | * Close all listening sockets |
| 148 | */ |
| 149 | void |
| 150 | close_listen_socks(void) |
| 151 | { |
| 152 | int i; |
| 153 | for (i = 0; i < num_listen_socks; i++) |
| 154 | close(listen_socks[i]); |
| 155 | num_listen_socks = -1; |
| 156 | } |
| 157 | |
| 158 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 159 | * Signal handler for SIGHUP. Sshd execs itself when it receives SIGHUP; |
| 160 | * the effect is to reread the configuration file (and to regenerate |
| 161 | * the server key). |
| 162 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 163 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 164 | sighup_handler(int sig) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 165 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 166 | received_sighup = 1; |
| 167 | signal(SIGHUP, sighup_handler); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 168 | } |
| 169 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 170 | /* |
| 171 | * Called from the main program after receiving SIGHUP. |
| 172 | * Restarts the server. |
| 173 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 174 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 175 | sighup_restart() |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 176 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 177 | log("Received SIGHUP; restarting."); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 178 | close_listen_socks(); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 179 | execv(saved_argv[0], saved_argv); |
| 180 | log("RESTART FAILED: av0='%s', error: %s.", av0, strerror(errno)); |
| 181 | exit(1); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 182 | } |
| 183 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 184 | /* |
| 185 | * Generic signal handler for terminating signals in the master daemon. |
| 186 | * These close the listen socket; not closing it seems to cause "Address |
| 187 | * already in use" problems on some machines, which is inconvenient. |
| 188 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 189 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 190 | sigterm_handler(int sig) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 191 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 192 | log("Received signal %d; terminating.", sig); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 193 | close_listen_socks(); |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 194 | unlink(options.pid_file); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 195 | exit(255); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 196 | } |
| 197 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 198 | /* |
| 199 | * SIGCHLD handler. This is called whenever a child dies. This will then |
| 200 | * reap any zombies left by exited c. |
| 201 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 202 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 203 | main_sigchld_handler(int sig) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 204 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 205 | int save_errno = errno; |
| 206 | int status; |
Damien Miller | 431f66b | 1999-11-21 18:31:57 +1100 | [diff] [blame] | 207 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 208 | while (waitpid(-1, &status, WNOHANG) > 0) |
| 209 | ; |
Damien Miller | 431f66b | 1999-11-21 18:31:57 +1100 | [diff] [blame] | 210 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 211 | signal(SIGCHLD, main_sigchld_handler); |
| 212 | errno = save_errno; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 213 | } |
| 214 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 215 | /* |
| 216 | * Signal handler for the alarm after the login grace period has expired. |
| 217 | */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 218 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 219 | grace_alarm_handler(int sig) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 220 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 221 | /* Close the connection. */ |
| 222 | packet_close(); |
| 223 | |
| 224 | /* Log error and exit. */ |
| 225 | fatal("Timeout before authentication for %s.", get_remote_ipaddr()); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 226 | } |
| 227 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 228 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 229 | * Signal handler for the key regeneration alarm. Note that this |
| 230 | * alarm only occurs in the daemon waiting for connections, and it does not |
| 231 | * do anything with the private key or random state before forking. |
| 232 | * Thus there should be no concurrency control/asynchronous execution |
| 233 | * problems. |
| 234 | */ |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 235 | /* XXX do we really want this work to be done in a signal handler ? -m */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 236 | void |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 237 | key_regeneration_alarm(int sig) |
| 238 | { |
| 239 | int save_errno = errno; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 240 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 241 | /* Check if we should generate a new key. */ |
| 242 | if (key_used) { |
| 243 | /* This should really be done in the background. */ |
| 244 | log("Generating new %d bit RSA key.", options.server_key_bits); |
| 245 | |
| 246 | if (sensitive_data.private_key != NULL) |
| 247 | RSA_free(sensitive_data.private_key); |
| 248 | sensitive_data.private_key = RSA_new(); |
| 249 | |
| 250 | if (public_key != NULL) |
| 251 | RSA_free(public_key); |
| 252 | public_key = RSA_new(); |
| 253 | |
| 254 | rsa_generate_key(sensitive_data.private_key, public_key, |
| 255 | options.server_key_bits); |
| 256 | arc4random_stir(); |
| 257 | key_used = 0; |
| 258 | log("RSA key generation complete."); |
| 259 | } |
| 260 | /* Reschedule the alarm. */ |
| 261 | signal(SIGALRM, key_regeneration_alarm); |
| 262 | alarm(options.key_regeneration_time); |
| 263 | errno = save_errno; |
| 264 | } |
| 265 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 266 | void |
| 267 | sshd_exchange_identification(int sock_in, int sock_out) |
| 268 | { |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 269 | int i, mismatch; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 270 | int remote_major, remote_minor; |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 271 | int major, minor; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 272 | char *s; |
| 273 | char buf[256]; /* Must not be larger than remote_version. */ |
| 274 | char remote_version[256]; /* Must be at least as big as buf. */ |
| 275 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 276 | if ((options.protocol & SSH_PROTO_1) && |
| 277 | (options.protocol & SSH_PROTO_2)) { |
| 278 | major = PROTOCOL_MAJOR_1; |
| 279 | minor = 99; |
| 280 | } else if (options.protocol & SSH_PROTO_2) { |
| 281 | major = PROTOCOL_MAJOR_2; |
| 282 | minor = PROTOCOL_MINOR_2; |
| 283 | } else { |
| 284 | major = PROTOCOL_MAJOR_1; |
| 285 | minor = PROTOCOL_MINOR_1; |
| 286 | } |
| 287 | snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n", major, minor, SSH_VERSION); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 288 | server_version_string = xstrdup(buf); |
| 289 | |
| 290 | if (client_version_string == NULL) { |
| 291 | /* Send our protocol version identification. */ |
| 292 | if (atomicio(write, sock_out, server_version_string, strlen(server_version_string)) |
| 293 | != strlen(server_version_string)) { |
| 294 | log("Could not write ident string to %s.", get_remote_ipaddr()); |
| 295 | fatal_cleanup(); |
| 296 | } |
| 297 | |
| 298 | /* Read other side\'s version identification. */ |
| 299 | for (i = 0; i < sizeof(buf) - 1; i++) { |
Damien Miller | bf7f466 | 2000-06-23 10:16:38 +1000 | [diff] [blame] | 300 | if (atomicio(read, sock_in, &buf[i], 1) != 1) { |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 301 | log("Did not receive ident string from %s.", get_remote_ipaddr()); |
| 302 | fatal_cleanup(); |
| 303 | } |
| 304 | if (buf[i] == '\r') { |
| 305 | buf[i] = '\n'; |
| 306 | buf[i + 1] = 0; |
| 307 | continue; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 308 | } |
| 309 | if (buf[i] == '\n') { |
| 310 | /* buf[i] == '\n' */ |
| 311 | buf[i + 1] = 0; |
| 312 | break; |
| 313 | } |
| 314 | } |
| 315 | buf[sizeof(buf) - 1] = 0; |
| 316 | client_version_string = xstrdup(buf); |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * Check that the versions match. In future this might accept |
| 321 | * several versions and set appropriate flags to handle them. |
| 322 | */ |
| 323 | if (sscanf(client_version_string, "SSH-%d.%d-%[^\n]\n", |
| 324 | &remote_major, &remote_minor, remote_version) != 3) { |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 325 | s = "Protocol mismatch.\n"; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 326 | (void) atomicio(write, sock_out, s, strlen(s)); |
| 327 | close(sock_in); |
| 328 | close(sock_out); |
| 329 | log("Bad protocol version identification '%.100s' from %s", |
| 330 | client_version_string, get_remote_ipaddr()); |
| 331 | fatal_cleanup(); |
| 332 | } |
| 333 | debug("Client protocol version %d.%d; client software version %.100s", |
| 334 | remote_major, remote_minor, remote_version); |
| 335 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 336 | compat_datafellows(remote_version); |
| 337 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 338 | mismatch = 0; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 339 | switch(remote_major) { |
| 340 | case 1: |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 341 | if (remote_minor == 99) { |
| 342 | if (options.protocol & SSH_PROTO_2) |
| 343 | enable_compat20(); |
| 344 | else |
| 345 | mismatch = 1; |
| 346 | break; |
| 347 | } |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 348 | if (!(options.protocol & SSH_PROTO_1)) { |
| 349 | mismatch = 1; |
| 350 | break; |
| 351 | } |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 352 | if (remote_minor < 3) { |
| 353 | packet_disconnect("Your ssh version is too old and" |
| 354 | "is no longer supported. Please install a newer version."); |
| 355 | } else if (remote_minor == 3) { |
| 356 | /* note that this disables agent-forwarding */ |
| 357 | enable_compat13(); |
| 358 | } |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 359 | break; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 360 | case 2: |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 361 | if (options.protocol & SSH_PROTO_2) { |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 362 | enable_compat20(); |
| 363 | break; |
| 364 | } |
| 365 | /* FALLTHROUGH */ |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 366 | default: |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 367 | mismatch = 1; |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 368 | break; |
| 369 | } |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 370 | chop(server_version_string); |
| 371 | chop(client_version_string); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 372 | debug("Local version string %.200s", server_version_string); |
| 373 | |
| 374 | if (mismatch) { |
| 375 | s = "Protocol major versions differ.\n"; |
| 376 | (void) atomicio(write, sock_out, s, strlen(s)); |
| 377 | close(sock_in); |
| 378 | close(sock_out); |
| 379 | log("Protocol major versions differ for %s: %.200s vs. %.200s", |
| 380 | get_remote_ipaddr(), |
| 381 | server_version_string, client_version_string); |
| 382 | fatal_cleanup(); |
| 383 | } |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 384 | if (compat20) |
| 385 | packet_set_ssh2_format(); |
| 386 | } |
| 387 | |
| 388 | |
| 389 | void |
| 390 | destroy_sensitive_data(void) |
| 391 | { |
| 392 | /* Destroy the private and public keys. They will no longer be needed. */ |
Damien Miller | c4be7ce | 2000-05-17 23:02:03 +1000 | [diff] [blame] | 393 | if (public_key) |
| 394 | RSA_free(public_key); |
| 395 | if (sensitive_data.private_key) |
| 396 | RSA_free(sensitive_data.private_key); |
| 397 | if (sensitive_data.host_key) |
| 398 | RSA_free(sensitive_data.host_key); |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 399 | if (sensitive_data.dsa_host_key != NULL) |
| 400 | key_free(sensitive_data.dsa_host_key); |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 401 | } |
| 402 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 403 | /* |
| 404 | * Main program for the daemon. |
| 405 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 406 | int |
| 407 | main(int ac, char **av) |
| 408 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 409 | extern char *optarg; |
| 410 | extern int optind; |
Damien Miller | 166fca8 | 2000-04-20 07:42:21 +1000 | [diff] [blame] | 411 | int opt, sock_in = 0, sock_out = 0, newsock, i, fdsetsz, on = 1; |
| 412 | pid_t pid; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 413 | socklen_t fromlen; |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 414 | int silent = 0; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 415 | fd_set *fdset; |
| 416 | struct sockaddr_storage from; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 417 | const char *remote_ip; |
| 418 | int remote_port; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 419 | FILE *f; |
| 420 | struct linger linger; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 421 | struct addrinfo *ai; |
| 422 | char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
| 423 | int listen_sock, maxfd; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 424 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 425 | /* Save argv[0]. */ |
Damien Miller | b8c656e | 2000-06-28 15:22:41 +1000 | [diff] [blame^] | 426 | saved_argc = ac; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 427 | saved_argv = av; |
| 428 | if (strchr(av[0], '/')) |
| 429 | av0 = strrchr(av[0], '/') + 1; |
| 430 | else |
| 431 | av0 = av[0]; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 432 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 433 | /* Initialize configuration options to their default values. */ |
| 434 | initialize_server_options(&options); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 435 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 436 | /* Parse command-line arguments. */ |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 437 | while ((opt = getopt(ac, av, "f:p:b:k:h:g:V:diqQ46")) != EOF) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 438 | switch (opt) { |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 439 | case '4': |
| 440 | IPv4or6 = AF_INET; |
| 441 | break; |
| 442 | case '6': |
| 443 | IPv4or6 = AF_INET6; |
| 444 | break; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 445 | case 'f': |
| 446 | config_file_name = optarg; |
| 447 | break; |
| 448 | case 'd': |
| 449 | debug_flag = 1; |
| 450 | options.log_level = SYSLOG_LEVEL_DEBUG; |
| 451 | break; |
| 452 | case 'i': |
| 453 | inetd_flag = 1; |
| 454 | break; |
| 455 | case 'Q': |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 456 | silent = 1; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 457 | break; |
| 458 | case 'q': |
| 459 | options.log_level = SYSLOG_LEVEL_QUIET; |
| 460 | break; |
| 461 | case 'b': |
| 462 | options.server_key_bits = atoi(optarg); |
| 463 | break; |
| 464 | case 'p': |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 465 | options.ports_from_cmdline = 1; |
| 466 | if (options.num_ports >= MAX_PORTS) |
| 467 | fatal("too many ports.\n"); |
| 468 | options.ports[options.num_ports++] = atoi(optarg); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 469 | break; |
| 470 | case 'g': |
| 471 | options.login_grace_time = atoi(optarg); |
| 472 | break; |
| 473 | case 'k': |
| 474 | options.key_regeneration_time = atoi(optarg); |
| 475 | break; |
| 476 | case 'h': |
| 477 | options.host_key_file = optarg; |
| 478 | break; |
| 479 | case 'V': |
| 480 | client_version_string = optarg; |
| 481 | /* only makes sense with inetd_flag, i.e. no listen() */ |
| 482 | inetd_flag = 1; |
| 483 | break; |
| 484 | case '?': |
| 485 | default: |
| 486 | fprintf(stderr, "sshd version %s\n", SSH_VERSION); |
| 487 | fprintf(stderr, "Usage: %s [options]\n", av0); |
| 488 | fprintf(stderr, "Options:\n"); |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 489 | fprintf(stderr, " -f file Configuration file (default %s)\n", SERVER_CONFIG_FILE); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 490 | fprintf(stderr, " -d Debugging mode\n"); |
| 491 | fprintf(stderr, " -i Started from inetd\n"); |
| 492 | fprintf(stderr, " -q Quiet (no logging)\n"); |
| 493 | fprintf(stderr, " -p port Listen on the specified port (default: 22)\n"); |
| 494 | fprintf(stderr, " -k seconds Regenerate server key every this many seconds (default: 3600)\n"); |
| 495 | fprintf(stderr, " -g seconds Grace period for authentication (default: 300)\n"); |
| 496 | fprintf(stderr, " -b bits Size of server RSA key (default: 768 bits)\n"); |
| 497 | fprintf(stderr, " -h file File from which to read host key (default: %s)\n", |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 498 | HOST_KEY_FILE); |
| 499 | fprintf(stderr, " -4 Use IPv4 only\n"); |
| 500 | fprintf(stderr, " -6 Use IPv6 only\n"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 501 | exit(1); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 502 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 503 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 504 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 505 | /* |
| 506 | * Force logging to stderr until we have loaded the private host |
| 507 | * key (unless started from inetd) |
| 508 | */ |
| 509 | log_init(av0, |
| 510 | options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level, |
| 511 | options.log_facility == -1 ? SYSLOG_FACILITY_AUTH : options.log_facility, |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 512 | !silent && !inetd_flag); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 513 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 514 | /* Read server configuration options from the configuration file. */ |
| 515 | read_server_config(&options, config_file_name); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 516 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 517 | /* Fill in default values for those options not explicitly set. */ |
| 518 | fill_default_server_options(&options); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 519 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 520 | /* Check that there are no remaining arguments. */ |
| 521 | if (optind < ac) { |
| 522 | fprintf(stderr, "Extra argument %s.\n", av[optind]); |
| 523 | exit(1); |
| 524 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 525 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 526 | debug("sshd version %.100s", SSH_VERSION); |
Damien Miller | 2ccf661 | 1999-11-15 15:25:10 +1100 | [diff] [blame] | 527 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 528 | sensitive_data.dsa_host_key = NULL; |
| 529 | sensitive_data.host_key = NULL; |
| 530 | |
| 531 | /* check if RSA support exists */ |
| 532 | if ((options.protocol & SSH_PROTO_1) && |
| 533 | rsa_alive() == 0) { |
| 534 | log("no RSA support in libssl and libcrypto. See ssl(8)"); |
| 535 | log("Disabling protocol version 1"); |
| 536 | options.protocol &= ~SSH_PROTO_1; |
| 537 | } |
| 538 | /* Load the RSA/DSA host key. It must have empty passphrase. */ |
| 539 | if (options.protocol & SSH_PROTO_1) { |
| 540 | Key k; |
| 541 | sensitive_data.host_key = RSA_new(); |
| 542 | k.type = KEY_RSA; |
| 543 | k.rsa = sensitive_data.host_key; |
| 544 | errno = 0; |
| 545 | if (!load_private_key(options.host_key_file, "", &k, NULL)) { |
| 546 | error("Could not load host key: %.200s: %.100s", |
| 547 | options.host_key_file, strerror(errno)); |
| 548 | log("Disabling protocol version 1"); |
| 549 | options.protocol &= ~SSH_PROTO_1; |
| 550 | } |
| 551 | k.rsa = NULL; |
| 552 | } |
| 553 | if (options.protocol & SSH_PROTO_2) { |
| 554 | sensitive_data.dsa_host_key = key_new(KEY_DSA); |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 555 | if (!load_private_key(options.host_dsa_key_file, "", sensitive_data.dsa_host_key, NULL)) { |
| 556 | |
| 557 | error("Could not load DSA host key: %.200s", options.host_dsa_key_file); |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 558 | log("Disabling protocol version 2"); |
| 559 | options.protocol &= ~SSH_PROTO_2; |
| 560 | } |
| 561 | } |
| 562 | if (! options.protocol & (SSH_PROTO_1|SSH_PROTO_2)) { |
| 563 | if (silent == 0) |
| 564 | fprintf(stderr, "sshd: no hostkeys available -- exiting.\n"); |
| 565 | log("sshd: no hostkeys available -- exiting.\n"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 566 | exit(1); |
| 567 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 568 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 569 | /* Check certain values for sanity. */ |
| 570 | if (options.protocol & SSH_PROTO_1) { |
| 571 | if (options.server_key_bits < 512 || |
| 572 | options.server_key_bits > 32768) { |
| 573 | fprintf(stderr, "Bad server key size.\n"); |
| 574 | exit(1); |
| 575 | } |
| 576 | /* |
| 577 | * Check that server and host key lengths differ sufficiently. This |
| 578 | * is necessary to make double encryption work with rsaref. Oh, I |
| 579 | * hate software patents. I dont know if this can go? Niels |
| 580 | */ |
| 581 | if (options.server_key_bits > |
| 582 | BN_num_bits(sensitive_data.host_key->n) - SSH_KEY_BITS_RESERVED && |
| 583 | options.server_key_bits < |
| 584 | BN_num_bits(sensitive_data.host_key->n) + SSH_KEY_BITS_RESERVED) { |
| 585 | options.server_key_bits = |
| 586 | BN_num_bits(sensitive_data.host_key->n) + SSH_KEY_BITS_RESERVED; |
| 587 | debug("Forcing server key to %d bits to make it differ from host key.", |
| 588 | options.server_key_bits); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /* Initialize the log (it is reinitialized below in case we forked). */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 593 | if (debug_flag && !inetd_flag) |
| 594 | log_stderr = 1; |
| 595 | log_init(av0, options.log_level, options.log_facility, log_stderr); |
| 596 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 597 | /* |
| 598 | * If not in debugging mode, and not started from inetd, disconnect |
| 599 | * from the controlling terminal, and fork. The original process |
| 600 | * exits. |
| 601 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 602 | if (!debug_flag && !inetd_flag) { |
| 603 | #ifdef TIOCNOTTY |
| 604 | int fd; |
| 605 | #endif /* TIOCNOTTY */ |
| 606 | if (daemon(0, 0) < 0) |
| 607 | fatal("daemon() failed: %.200s", strerror(errno)); |
| 608 | |
| 609 | /* Disconnect from the controlling tty. */ |
| 610 | #ifdef TIOCNOTTY |
| 611 | fd = open("/dev/tty", O_RDWR | O_NOCTTY); |
| 612 | if (fd >= 0) { |
| 613 | (void) ioctl(fd, TIOCNOTTY, NULL); |
| 614 | close(fd); |
| 615 | } |
| 616 | #endif /* TIOCNOTTY */ |
| 617 | } |
| 618 | /* Reinitialize the log (because of the fork above). */ |
| 619 | log_init(av0, options.log_level, options.log_facility, log_stderr); |
| 620 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 621 | /* Do not display messages to stdout in RSA code. */ |
| 622 | rsa_set_verbose(0); |
| 623 | |
| 624 | /* Initialize the random number generator. */ |
| 625 | arc4random_stir(); |
| 626 | |
| 627 | /* Chdir to the root directory so that the current disk can be |
| 628 | unmounted if desired. */ |
| 629 | chdir("/"); |
| 630 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 631 | /* Start listening for a socket, unless started from inetd. */ |
| 632 | if (inetd_flag) { |
| 633 | int s1, s2; |
| 634 | s1 = dup(0); /* Make sure descriptors 0, 1, and 2 are in use. */ |
| 635 | s2 = dup(s1); |
| 636 | sock_in = dup(0); |
| 637 | sock_out = dup(1); |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 638 | /* |
| 639 | * We intentionally do not close the descriptors 0, 1, and 2 |
| 640 | * as our code for setting the descriptors won\'t work if |
| 641 | * ttyfd happens to be one of those. |
| 642 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 643 | debug("inetd sockets after dupping: %d, %d", sock_in, sock_out); |
| 644 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 645 | if (options.protocol & SSH_PROTO_1) { |
| 646 | public_key = RSA_new(); |
| 647 | sensitive_data.private_key = RSA_new(); |
| 648 | log("Generating %d bit RSA key.", options.server_key_bits); |
| 649 | rsa_generate_key(sensitive_data.private_key, public_key, |
| 650 | options.server_key_bits); |
| 651 | arc4random_stir(); |
| 652 | log("RSA key generation complete."); |
| 653 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 654 | } else { |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 655 | for (ai = options.listen_addrs; ai; ai = ai->ai_next) { |
| 656 | if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) |
| 657 | continue; |
| 658 | if (num_listen_socks >= MAX_LISTEN_SOCKS) |
| 659 | fatal("Too many listen sockets. " |
| 660 | "Enlarge MAX_LISTEN_SOCKS"); |
| 661 | if (getnameinfo(ai->ai_addr, ai->ai_addrlen, |
| 662 | ntop, sizeof(ntop), strport, sizeof(strport), |
| 663 | NI_NUMERICHOST|NI_NUMERICSERV) != 0) { |
| 664 | error("getnameinfo failed"); |
| 665 | continue; |
| 666 | } |
| 667 | /* Create socket for listening. */ |
| 668 | listen_sock = socket(ai->ai_family, SOCK_STREAM, 0); |
| 669 | if (listen_sock < 0) { |
| 670 | /* kernel may not support ipv6 */ |
| 671 | verbose("socket: %.100s", strerror(errno)); |
| 672 | continue; |
| 673 | } |
| 674 | if (fcntl(listen_sock, F_SETFL, O_NONBLOCK) < 0) { |
| 675 | error("listen_sock O_NONBLOCK: %s", strerror(errno)); |
| 676 | close(listen_sock); |
| 677 | continue; |
| 678 | } |
| 679 | /* |
| 680 | * Set socket options. We try to make the port |
| 681 | * reusable and have it close as fast as possible |
| 682 | * without waiting in unnecessary wait states on |
| 683 | * close. |
| 684 | */ |
| 685 | setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, |
| 686 | (void *) &on, sizeof(on)); |
| 687 | linger.l_onoff = 1; |
| 688 | linger.l_linger = 5; |
| 689 | setsockopt(listen_sock, SOL_SOCKET, SO_LINGER, |
| 690 | (void *) &linger, sizeof(linger)); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 691 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 692 | debug("Bind to port %s on %s.", strport, ntop); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 693 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 694 | /* Bind the socket to the desired port. */ |
Damien Miller | 3c7eeb2 | 2000-03-03 22:35:33 +1100 | [diff] [blame] | 695 | if ((bind(listen_sock, ai->ai_addr, ai->ai_addrlen) < 0) && |
| 696 | (!ai->ai_next)) { |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 697 | error("Bind to port %s on %s failed: %.200s.", |
| 698 | strport, ntop, strerror(errno)); |
| 699 | close(listen_sock); |
| 700 | continue; |
| 701 | } |
| 702 | listen_socks[num_listen_socks] = listen_sock; |
| 703 | num_listen_socks++; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 704 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 705 | /* Start listening on the port. */ |
| 706 | log("Server listening on %s port %s.", ntop, strport); |
| 707 | if (listen(listen_sock, 5) < 0) |
| 708 | fatal("listen: %.100s", strerror(errno)); |
| 709 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 710 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 711 | freeaddrinfo(options.listen_addrs); |
| 712 | |
| 713 | if (!num_listen_socks) |
| 714 | fatal("Cannot bind any address."); |
| 715 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 716 | if (!debug_flag) { |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 717 | /* |
| 718 | * Record our pid in /etc/sshd_pid to make it easier |
| 719 | * to kill the correct sshd. We don\'t want to do |
| 720 | * this before the bind above because the bind will |
| 721 | * fail if there already is a daemon, and this will |
| 722 | * overwrite any old pid in the file. |
| 723 | */ |
Damien Miller | 6f83b8e | 2000-05-02 09:23:45 +1000 | [diff] [blame] | 724 | f = fopen(options.pid_file, "w"); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 725 | if (f) { |
| 726 | fprintf(f, "%u\n", (unsigned int) getpid()); |
| 727 | fclose(f); |
| 728 | } |
| 729 | } |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 730 | if (options.protocol & SSH_PROTO_1) { |
| 731 | public_key = RSA_new(); |
| 732 | sensitive_data.private_key = RSA_new(); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 733 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 734 | log("Generating %d bit RSA key.", options.server_key_bits); |
| 735 | rsa_generate_key(sensitive_data.private_key, public_key, |
| 736 | options.server_key_bits); |
| 737 | arc4random_stir(); |
| 738 | log("RSA key generation complete."); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 739 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 740 | /* Schedule server key regeneration alarm. */ |
| 741 | signal(SIGALRM, key_regeneration_alarm); |
| 742 | alarm(options.key_regeneration_time); |
| 743 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 744 | |
| 745 | /* Arrange to restart on SIGHUP. The handler needs listen_sock. */ |
| 746 | signal(SIGHUP, sighup_handler); |
| 747 | signal(SIGTERM, sigterm_handler); |
| 748 | signal(SIGQUIT, sigterm_handler); |
| 749 | |
| 750 | /* Arrange SIGCHLD to be caught. */ |
| 751 | signal(SIGCHLD, main_sigchld_handler); |
| 752 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 753 | /* setup fd set for listen */ |
| 754 | maxfd = 0; |
| 755 | for (i = 0; i < num_listen_socks; i++) |
| 756 | if (listen_socks[i] > maxfd) |
| 757 | maxfd = listen_socks[i]; |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 758 | fdsetsz = howmany(maxfd, NFDBITS) * sizeof(fd_mask); |
| 759 | fdset = (fd_set *)xmalloc(fdsetsz); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 760 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 761 | /* |
| 762 | * Stay listening for connections until the system crashes or |
| 763 | * the daemon is killed with a signal. |
| 764 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 765 | for (;;) { |
| 766 | if (received_sighup) |
| 767 | sighup_restart(); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 768 | /* Wait in select until there is a connection. */ |
| 769 | memset(fdset, 0, fdsetsz); |
| 770 | for (i = 0; i < num_listen_socks; i++) |
| 771 | FD_SET(listen_socks[i], fdset); |
| 772 | if (select(maxfd + 1, fdset, NULL, NULL, NULL) < 0) { |
| 773 | if (errno != EINTR) |
| 774 | error("select: %.100s", strerror(errno)); |
Damien Miller | 50945fa | 1999-12-09 10:31:37 +1100 | [diff] [blame] | 775 | continue; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 776 | } |
| 777 | for (i = 0; i < num_listen_socks; i++) { |
| 778 | if (!FD_ISSET(listen_socks[i], fdset)) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 779 | continue; |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 780 | fromlen = sizeof(from); |
| 781 | newsock = accept(listen_socks[i], (struct sockaddr *)&from, |
| 782 | &fromlen); |
| 783 | if (newsock < 0) { |
| 784 | if (errno != EINTR && errno != EWOULDBLOCK) |
| 785 | error("accept: %.100s", strerror(errno)); |
| 786 | continue; |
| 787 | } |
| 788 | if (fcntl(newsock, F_SETFL, 0) < 0) { |
| 789 | error("newsock del O_NONBLOCK: %s", strerror(errno)); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 790 | continue; |
| 791 | } |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 792 | /* |
| 793 | * Got connection. Fork a child to handle it, unless |
| 794 | * we are in debugging mode. |
| 795 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 796 | if (debug_flag) { |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 797 | /* |
| 798 | * In debugging mode. Close the listening |
| 799 | * socket, and start processing the |
| 800 | * connection without forking. |
| 801 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 802 | debug("Server will not fork when running in debugging mode."); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 803 | close_listen_socks(); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 804 | sock_in = newsock; |
| 805 | sock_out = newsock; |
| 806 | pid = getpid(); |
| 807 | break; |
| 808 | } else { |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 809 | /* |
| 810 | * Normal production daemon. Fork, and have |
| 811 | * the child process the connection. The |
| 812 | * parent continues listening. |
| 813 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 814 | if ((pid = fork()) == 0) { |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 815 | /* |
| 816 | * Child. Close the listening socket, and start using the |
| 817 | * accepted socket. Reinitialize logging (since our pid has |
| 818 | * changed). We break out of the loop to handle the connection. |
| 819 | */ |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 820 | close_listen_socks(); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 821 | sock_in = newsock; |
| 822 | sock_out = newsock; |
| 823 | log_init(av0, options.log_level, options.log_facility, log_stderr); |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | /* Parent. Stay in the loop. */ |
| 829 | if (pid < 0) |
| 830 | error("fork: %.100s", strerror(errno)); |
| 831 | else |
| 832 | debug("Forked child %d.", pid); |
| 833 | |
| 834 | /* Mark that the key has been used (it was "given" to the child). */ |
| 835 | key_used = 1; |
| 836 | |
| 837 | arc4random_stir(); |
| 838 | |
| 839 | /* Close the new socket (the child is now taking care of it). */ |
| 840 | close(newsock); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 841 | } /* for (i = 0; i < num_listen_socks; i++) */ |
| 842 | /* child process check (or debug mode) */ |
| 843 | if (num_listen_socks < 0) |
| 844 | break; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
| 848 | /* This is the child processing a new connection. */ |
| 849 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 850 | /* |
| 851 | * Disable the key regeneration alarm. We will not regenerate the |
| 852 | * key since we are no longer in a position to give it to anyone. We |
| 853 | * will not restart on SIGHUP since it no longer makes sense. |
| 854 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 855 | alarm(0); |
| 856 | signal(SIGALRM, SIG_DFL); |
| 857 | signal(SIGHUP, SIG_DFL); |
| 858 | signal(SIGTERM, SIG_DFL); |
| 859 | signal(SIGQUIT, SIG_DFL); |
| 860 | signal(SIGCHLD, SIG_DFL); |
| 861 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 862 | /* |
| 863 | * Set socket options for the connection. We want the socket to |
| 864 | * close as fast as possible without waiting for anything. If the |
| 865 | * connection is not a socket, these will do nothing. |
| 866 | */ |
| 867 | /* setsockopt(sock_in, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 868 | linger.l_onoff = 1; |
| 869 | linger.l_linger = 5; |
| 870 | setsockopt(sock_in, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger)); |
| 871 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 872 | /* |
| 873 | * Register our connection. This turns encryption off because we do |
| 874 | * not have a key. |
| 875 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 876 | packet_set_connection(sock_in, sock_out); |
| 877 | |
| 878 | remote_port = get_remote_port(); |
| 879 | remote_ip = get_remote_ipaddr(); |
| 880 | |
| 881 | /* Check whether logins are denied from this host. */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 882 | #ifdef LIBWRAP |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 883 | /* XXX LIBWRAP noes not know about IPv6 */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 884 | { |
| 885 | struct request_info req; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 886 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 887 | request_init(&req, RQ_DAEMON, av0, RQ_FILE, sock_in, NULL); |
| 888 | fromhost(&req); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 889 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 890 | if (!hosts_access(&req)) { |
| 891 | close(sock_in); |
| 892 | close(sock_out); |
| 893 | refuse(&req); |
| 894 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 895 | /*XXX IPv6 verbose("Connection from %.500s port %d", eval_client(&req), remote_port); */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 896 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 897 | #endif /* LIBWRAP */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 898 | /* Log the connection. */ |
| 899 | verbose("Connection from %.500s port %d", remote_ip, remote_port); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 900 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 901 | /* |
| 902 | * We don\'t want to listen forever unless the other side |
| 903 | * successfully authenticates itself. So we set up an alarm which is |
| 904 | * cleared after successful authentication. A limit of zero |
| 905 | * indicates no limit. Note that we don\'t set the alarm in debugging |
| 906 | * mode; it is just annoying to have the server exit just when you |
| 907 | * are about to discover the bug. |
| 908 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 909 | signal(SIGALRM, grace_alarm_handler); |
| 910 | if (!debug_flag) |
| 911 | alarm(options.login_grace_time); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 912 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 913 | sshd_exchange_identification(sock_in, sock_out); |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 914 | /* |
| 915 | * Check that the connection comes from a privileged port. Rhosts- |
| 916 | * and Rhosts-RSA-Authentication only make sense from priviledged |
| 917 | * programs. Of course, if the intruder has root access on his local |
| 918 | * machine, he can connect from any port. So do not use these |
| 919 | * authentication methods from machines that you do not trust. |
| 920 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 921 | if (remote_port >= IPPORT_RESERVED || |
| 922 | remote_port < IPPORT_RESERVED / 2) { |
| 923 | options.rhosts_authentication = 0; |
| 924 | options.rhosts_rsa_authentication = 0; |
| 925 | } |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 926 | #ifdef KRB4 |
| 927 | if (!packet_connection_is_ipv4() && |
| 928 | options.kerberos_authentication) { |
| 929 | debug("Kerberos Authentication disabled, only available for IPv4."); |
| 930 | options.kerberos_authentication = 0; |
| 931 | } |
| 932 | #endif /* KRB4 */ |
| 933 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 934 | packet_set_nonblocking(); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 935 | |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 936 | /* perform the key exchange */ |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 937 | /* authenticate user and start session */ |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 938 | if (compat20) { |
| 939 | do_ssh2_kex(); |
| 940 | do_authentication2(); |
| 941 | } else { |
| 942 | do_ssh1_kex(); |
| 943 | do_authentication(); |
| 944 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 945 | |
| 946 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 947 | /* Cleanup user's ticket cache file. */ |
| 948 | if (options.kerberos_ticket_cleanup) |
| 949 | (void) dest_tkt(); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 950 | #endif /* KRB4 */ |
| 951 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 952 | /* The connection has been terminated. */ |
| 953 | verbose("Closing connection to %.100s", remote_ip); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 954 | |
Damien Miller | beb4ba5 | 1999-12-28 15:09:35 +1100 | [diff] [blame] | 955 | #ifdef USE_PAM |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 956 | finish_pam(); |
Damien Miller | beb4ba5 | 1999-12-28 15:09:35 +1100 | [diff] [blame] | 957 | #endif /* USE_PAM */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 958 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 959 | packet_close(); |
| 960 | exit(0); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 961 | } |
| 962 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 963 | /* |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 964 | * SSH1 key exchange |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 965 | */ |
Damien Miller | 2ccf661 | 1999-11-15 15:25:10 +1100 | [diff] [blame] | 966 | void |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 967 | do_ssh1_kex() |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 968 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 969 | int i, len; |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 970 | int plen, slen; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 971 | BIGNUM *session_key_int; |
| 972 | unsigned char session_key[SSH_SESSION_KEY_LENGTH]; |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 973 | unsigned char cookie[8]; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 974 | unsigned int cipher_type, auth_mask, protocol_flags; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 975 | u_int32_t rand = 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 976 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 977 | /* |
| 978 | * Generate check bytes that the client must send back in the user |
| 979 | * packet in order for it to be accepted; this is used to defy ip |
| 980 | * spoofing attacks. Note that this only works against somebody |
| 981 | * doing IP spoofing from a remote machine; any machine on the local |
| 982 | * network can still see outgoing packets and catch the random |
| 983 | * cookie. This only affects rhosts authentication, and this is one |
| 984 | * of the reasons why it is inherently insecure. |
| 985 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 986 | for (i = 0; i < 8; i++) { |
| 987 | if (i % 4 == 0) |
| 988 | rand = arc4random(); |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 989 | cookie[i] = rand & 0xff; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 990 | rand >>= 8; |
| 991 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 992 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 993 | /* |
| 994 | * Send our public key. We include in the packet 64 bits of random |
| 995 | * data that must be matched in the reply in order to prevent IP |
| 996 | * spoofing. |
| 997 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 998 | packet_start(SSH_SMSG_PUBLIC_KEY); |
| 999 | for (i = 0; i < 8; i++) |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 1000 | packet_put_char(cookie[i]); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1001 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1002 | /* Store our public server RSA key. */ |
| 1003 | packet_put_int(BN_num_bits(public_key->n)); |
| 1004 | packet_put_bignum(public_key->e); |
| 1005 | packet_put_bignum(public_key->n); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1006 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1007 | /* Store our public host RSA key. */ |
| 1008 | packet_put_int(BN_num_bits(sensitive_data.host_key->n)); |
| 1009 | packet_put_bignum(sensitive_data.host_key->e); |
| 1010 | packet_put_bignum(sensitive_data.host_key->n); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1011 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1012 | /* Put protocol flags. */ |
| 1013 | packet_put_int(SSH_PROTOFLAG_HOST_IN_FWD_OPEN); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1014 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1015 | /* Declare which ciphers we support. */ |
Damien Miller | 1383bd8 | 2000-04-06 12:32:37 +1000 | [diff] [blame] | 1016 | packet_put_int(cipher_mask1()); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1017 | |
| 1018 | /* Declare supported authentication types. */ |
| 1019 | auth_mask = 0; |
| 1020 | if (options.rhosts_authentication) |
| 1021 | auth_mask |= 1 << SSH_AUTH_RHOSTS; |
| 1022 | if (options.rhosts_rsa_authentication) |
| 1023 | auth_mask |= 1 << SSH_AUTH_RHOSTS_RSA; |
| 1024 | if (options.rsa_authentication) |
| 1025 | auth_mask |= 1 << SSH_AUTH_RSA; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1026 | #ifdef KRB4 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1027 | if (options.kerberos_authentication) |
| 1028 | auth_mask |= 1 << SSH_AUTH_KERBEROS; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1029 | #endif |
| 1030 | #ifdef AFS |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1031 | if (options.kerberos_tgt_passing) |
| 1032 | auth_mask |= 1 << SSH_PASS_KERBEROS_TGT; |
| 1033 | if (options.afs_token_passing) |
| 1034 | auth_mask |= 1 << SSH_PASS_AFS_TOKEN; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1035 | #endif |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1036 | #ifdef SKEY |
| 1037 | if (options.skey_authentication == 1) |
| 1038 | auth_mask |= 1 << SSH_AUTH_TIS; |
| 1039 | #endif |
| 1040 | if (options.password_authentication) |
| 1041 | auth_mask |= 1 << SSH_AUTH_PASSWORD; |
| 1042 | packet_put_int(auth_mask); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1043 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1044 | /* Send the packet and wait for it to be sent. */ |
| 1045 | packet_send(); |
| 1046 | packet_write_wait(); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1047 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1048 | debug("Sent %d bit public key and %d bit host key.", |
| 1049 | BN_num_bits(public_key->n), BN_num_bits(sensitive_data.host_key->n)); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1050 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1051 | /* Read clients reply (cipher type and session key). */ |
| 1052 | packet_read_expect(&plen, SSH_CMSG_SESSION_KEY); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1053 | |
Damien Miller | 50945fa | 1999-12-09 10:31:37 +1100 | [diff] [blame] | 1054 | /* Get cipher type and check whether we accept this. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1055 | cipher_type = packet_get_char(); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1056 | |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1057 | if (!(cipher_mask() & (1 << cipher_type))) |
Damien Miller | 50945fa | 1999-12-09 10:31:37 +1100 | [diff] [blame] | 1058 | packet_disconnect("Warning: client selects unsupported cipher."); |
| 1059 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1060 | /* Get check bytes from the packet. These must match those we |
| 1061 | sent earlier with the public key packet. */ |
| 1062 | for (i = 0; i < 8; i++) |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 1063 | if (cookie[i] != packet_get_char()) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1064 | packet_disconnect("IP Spoofing check bytes do not match."); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1065 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1066 | debug("Encryption type: %.200s", cipher_name(cipher_type)); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1067 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1068 | /* Get the encrypted integer. */ |
| 1069 | session_key_int = BN_new(); |
| 1070 | packet_get_bignum(session_key_int, &slen); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1071 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1072 | protocol_flags = packet_get_int(); |
| 1073 | packet_set_protocol_flags(protocol_flags); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1074 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1075 | packet_integrity_check(plen, 1 + 8 + slen + 4, SSH_CMSG_SESSION_KEY); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1076 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1077 | /* |
| 1078 | * Decrypt it using our private server key and private host key (key |
| 1079 | * with larger modulus first). |
| 1080 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1081 | if (BN_cmp(sensitive_data.private_key->n, sensitive_data.host_key->n) > 0) { |
| 1082 | /* Private key has bigger modulus. */ |
| 1083 | if (BN_num_bits(sensitive_data.private_key->n) < |
| 1084 | BN_num_bits(sensitive_data.host_key->n) + SSH_KEY_BITS_RESERVED) { |
| 1085 | fatal("do_connection: %s: private_key %d < host_key %d + SSH_KEY_BITS_RESERVED %d", |
| 1086 | get_remote_ipaddr(), |
| 1087 | BN_num_bits(sensitive_data.private_key->n), |
| 1088 | BN_num_bits(sensitive_data.host_key->n), |
| 1089 | SSH_KEY_BITS_RESERVED); |
| 1090 | } |
| 1091 | rsa_private_decrypt(session_key_int, session_key_int, |
| 1092 | sensitive_data.private_key); |
| 1093 | rsa_private_decrypt(session_key_int, session_key_int, |
| 1094 | sensitive_data.host_key); |
| 1095 | } else { |
| 1096 | /* Host key has bigger modulus (or they are equal). */ |
| 1097 | if (BN_num_bits(sensitive_data.host_key->n) < |
| 1098 | BN_num_bits(sensitive_data.private_key->n) + SSH_KEY_BITS_RESERVED) { |
| 1099 | fatal("do_connection: %s: host_key %d < private_key %d + SSH_KEY_BITS_RESERVED %d", |
| 1100 | get_remote_ipaddr(), |
| 1101 | BN_num_bits(sensitive_data.host_key->n), |
| 1102 | BN_num_bits(sensitive_data.private_key->n), |
| 1103 | SSH_KEY_BITS_RESERVED); |
| 1104 | } |
| 1105 | rsa_private_decrypt(session_key_int, session_key_int, |
| 1106 | sensitive_data.host_key); |
| 1107 | rsa_private_decrypt(session_key_int, session_key_int, |
| 1108 | sensitive_data.private_key); |
| 1109 | } |
Damien Miller | 356a0b0 | 1999-11-08 15:30:59 +1100 | [diff] [blame] | 1110 | |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 1111 | compute_session_id(session_id, cookie, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1112 | sensitive_data.host_key->n, |
| 1113 | sensitive_data.private_key->n); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1114 | |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 1115 | /* Destroy the private and public keys. They will no longer be needed. */ |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1116 | destroy_sensitive_data(); |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 1117 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 1118 | /* |
| 1119 | * Extract session key from the decrypted integer. The key is in the |
| 1120 | * least significant 256 bits of the integer; the first byte of the |
| 1121 | * key is in the highest bits. |
| 1122 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1123 | BN_mask_bits(session_key_int, sizeof(session_key) * 8); |
| 1124 | len = BN_num_bytes(session_key_int); |
| 1125 | if (len < 0 || len > sizeof(session_key)) |
| 1126 | fatal("do_connection: bad len from %s: session_key_int %d > sizeof(session_key) %d", |
| 1127 | get_remote_ipaddr(), |
| 1128 | len, sizeof(session_key)); |
| 1129 | memset(session_key, 0, sizeof(session_key)); |
| 1130 | BN_bn2bin(session_key_int, session_key + sizeof(session_key) - len); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1131 | |
Damien Miller | 396691a | 2000-01-20 22:44:08 +1100 | [diff] [blame] | 1132 | /* Destroy the decrypted integer. It is no longer needed. */ |
| 1133 | BN_clear_free(session_key_int); |
| 1134 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1135 | /* Xor the first 16 bytes of the session key with the session id. */ |
| 1136 | for (i = 0; i < 16; i++) |
| 1137 | session_key[i] ^= session_id[i]; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1138 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1139 | /* Set the session key. From this on all communications will be encrypted. */ |
| 1140 | packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1141 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1142 | /* Destroy our copy of the session key. It is no longer needed. */ |
| 1143 | memset(session_key, 0, sizeof(session_key)); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1144 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1145 | debug("Received session key; encryption turned on."); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1146 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 1147 | /* Send an acknowledgement packet. Note that this packet is sent encrypted. */ |
| 1148 | packet_start(SSH_SMSG_SUCCESS); |
| 1149 | packet_send(); |
| 1150 | packet_write_wait(); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1151 | } |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1152 | |
| 1153 | /* |
| 1154 | * SSH2 key exchange: diffie-hellman-group1-sha1 |
| 1155 | */ |
| 1156 | void |
| 1157 | do_ssh2_kex() |
| 1158 | { |
| 1159 | Buffer *server_kexinit; |
| 1160 | Buffer *client_kexinit; |
| 1161 | int payload_len, dlen; |
| 1162 | int slen; |
| 1163 | unsigned int klen, kout; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1164 | unsigned char *signature = NULL; |
| 1165 | unsigned char *server_host_key_blob = NULL; |
| 1166 | unsigned int sbloblen; |
| 1167 | DH *dh; |
| 1168 | BIGNUM *dh_client_pub = 0; |
| 1169 | BIGNUM *shared_secret = 0; |
| 1170 | int i; |
| 1171 | unsigned char *kbuf; |
| 1172 | unsigned char *hash; |
| 1173 | Kex *kex; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1174 | char *cprop[PROPOSAL_MAX]; |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1175 | |
| 1176 | /* KEXINIT */ |
| 1177 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1178 | if (options.ciphers != NULL) { |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1179 | myproposal[PROPOSAL_ENC_ALGS_CTOS] = |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1180 | myproposal[PROPOSAL_ENC_ALGS_STOC] = options.ciphers; |
| 1181 | } |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1182 | server_kexinit = kex_init(myproposal); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1183 | client_kexinit = xmalloc(sizeof(*client_kexinit)); |
| 1184 | buffer_init(client_kexinit); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1185 | |
Damien Miller | b1715dc | 2000-05-30 13:44:51 +1000 | [diff] [blame] | 1186 | /* algorithm negotiation */ |
| 1187 | kex_exchange_kexinit(server_kexinit, client_kexinit, cprop); |
| 1188 | kex = kex_choose_conf(cprop, myproposal, 1); |
| 1189 | for (i = 0; i < PROPOSAL_MAX; i++) |
| 1190 | xfree(cprop[i]); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1191 | |
| 1192 | /* KEXDH */ |
| 1193 | |
| 1194 | debug("Wait SSH2_MSG_KEXDH_INIT."); |
| 1195 | packet_read_expect(&payload_len, SSH2_MSG_KEXDH_INIT); |
| 1196 | |
| 1197 | /* key, cert */ |
| 1198 | dh_client_pub = BN_new(); |
| 1199 | if (dh_client_pub == NULL) |
| 1200 | fatal("dh_client_pub == NULL"); |
| 1201 | packet_get_bignum2(dh_client_pub, &dlen); |
| 1202 | |
| 1203 | #ifdef DEBUG_KEXDH |
| 1204 | fprintf(stderr, "\ndh_client_pub= "); |
| 1205 | bignum_print(dh_client_pub); |
| 1206 | fprintf(stderr, "\n"); |
| 1207 | debug("bits %d", BN_num_bits(dh_client_pub)); |
| 1208 | #endif |
| 1209 | |
| 1210 | /* generate DH key */ |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1211 | dh = dh_new_group1(); /* XXX depends on 'kex' */ |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1212 | |
| 1213 | #ifdef DEBUG_KEXDH |
| 1214 | fprintf(stderr, "\np= "); |
| 1215 | bignum_print(dh->p); |
| 1216 | fprintf(stderr, "\ng= "); |
| 1217 | bignum_print(dh->g); |
| 1218 | fprintf(stderr, "\npub= "); |
| 1219 | bignum_print(dh->pub_key); |
| 1220 | fprintf(stderr, "\n"); |
| 1221 | #endif |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1222 | if (!dh_pub_is_valid(dh, dh_client_pub)) |
| 1223 | packet_disconnect("bad client public DH value"); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1224 | |
| 1225 | klen = DH_size(dh); |
| 1226 | kbuf = xmalloc(klen); |
| 1227 | kout = DH_compute_key(kbuf, dh_client_pub, dh); |
| 1228 | |
| 1229 | #ifdef DEBUG_KEXDH |
| 1230 | debug("shared secret: len %d/%d", klen, kout); |
| 1231 | fprintf(stderr, "shared secret == "); |
| 1232 | for (i = 0; i< kout; i++) |
| 1233 | fprintf(stderr, "%02x", (kbuf[i])&0xff); |
| 1234 | fprintf(stderr, "\n"); |
| 1235 | #endif |
| 1236 | shared_secret = BN_new(); |
| 1237 | |
| 1238 | BN_bin2bn(kbuf, kout, shared_secret); |
| 1239 | memset(kbuf, 0, klen); |
| 1240 | xfree(kbuf); |
| 1241 | |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1242 | /* XXX precompute? */ |
| 1243 | dsa_make_key_blob(sensitive_data.dsa_host_key, &server_host_key_blob, &sbloblen); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1244 | |
| 1245 | /* calc H */ /* XXX depends on 'kex' */ |
| 1246 | hash = kex_hash( |
| 1247 | client_version_string, |
| 1248 | server_version_string, |
| 1249 | buffer_ptr(client_kexinit), buffer_len(client_kexinit), |
| 1250 | buffer_ptr(server_kexinit), buffer_len(server_kexinit), |
| 1251 | (char *)server_host_key_blob, sbloblen, |
| 1252 | dh_client_pub, |
| 1253 | dh->pub_key, |
| 1254 | shared_secret |
| 1255 | ); |
| 1256 | buffer_free(client_kexinit); |
| 1257 | buffer_free(server_kexinit); |
| 1258 | xfree(client_kexinit); |
| 1259 | xfree(server_kexinit); |
| 1260 | #ifdef DEBUG_KEXDH |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 1261 | fprintf(stderr, "hash == "); |
| 1262 | for (i = 0; i< 20; i++) |
| 1263 | fprintf(stderr, "%02x", (hash[i])&0xff); |
| 1264 | fprintf(stderr, "\n"); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1265 | #endif |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1266 | /* save session id := H */ |
| 1267 | /* XXX hashlen depends on KEX */ |
| 1268 | session_id2_len = 20; |
| 1269 | session_id2 = xmalloc(session_id2_len); |
| 1270 | memcpy(session_id2, hash, session_id2_len); |
| 1271 | |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1272 | /* sign H */ |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1273 | /* XXX hashlen depends on KEX */ |
| 1274 | dsa_sign(sensitive_data.dsa_host_key, &signature, &slen, hash, 20); |
| 1275 | |
| 1276 | destroy_sensitive_data(); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1277 | |
| 1278 | /* send server hostkey, DH pubkey 'f' and singed H */ |
| 1279 | packet_start(SSH2_MSG_KEXDH_REPLY); |
| 1280 | packet_put_string((char *)server_host_key_blob, sbloblen); |
Damien Miller | e247cc4 | 2000-05-07 12:03:14 +1000 | [diff] [blame] | 1281 | packet_put_bignum2(dh->pub_key); /* f */ |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1282 | packet_put_string((char *)signature, slen); |
| 1283 | packet_send(); |
Damien Miller | 8bb73be | 2000-04-19 16:26:12 +1000 | [diff] [blame] | 1284 | xfree(signature); |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 1285 | xfree(server_host_key_blob); |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1286 | packet_write_wait(); |
| 1287 | |
| 1288 | kex_derive_keys(kex, hash, shared_secret); |
| 1289 | packet_set_kex(kex); |
| 1290 | |
| 1291 | /* have keys, free DH */ |
| 1292 | DH_free(dh); |
| 1293 | |
| 1294 | debug("send SSH2_MSG_NEWKEYS."); |
| 1295 | packet_start(SSH2_MSG_NEWKEYS); |
| 1296 | packet_send(); |
| 1297 | packet_write_wait(); |
| 1298 | debug("done: send SSH2_MSG_NEWKEYS."); |
| 1299 | |
| 1300 | debug("Wait SSH2_MSG_NEWKEYS."); |
| 1301 | packet_read_expect(&payload_len, SSH2_MSG_NEWKEYS); |
| 1302 | debug("GOT SSH2_MSG_NEWKEYS."); |
| 1303 | |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1304 | #ifdef DEBUG_KEXDH |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1305 | /* send 1st encrypted/maced/compressed message */ |
| 1306 | packet_start(SSH2_MSG_IGNORE); |
| 1307 | packet_put_cstring("markus"); |
| 1308 | packet_send(); |
| 1309 | packet_write_wait(); |
Damien Miller | 7892879 | 2000-04-12 20:17:38 +1000 | [diff] [blame] | 1310 | #endif |
Damien Miller | efb4afe | 2000-04-12 18:45:05 +1000 | [diff] [blame] | 1311 | debug("done: KEX2."); |
| 1312 | } |