*/
#include "includes.h"
-RCSID("$OpenBSD: sshd.c,v 1.135 2000/11/29 21:11:59 markus Exp $");
+RCSID("$OpenBSD: sshd.c,v 1.147 2001/01/10 19:43:20 deraadt Exp $");
#include "xmalloc.h"
#include "rsa.h"
/* debug goes to stderr unless inetd_flag is set */
int log_stderr = 0;
-/* argv[0] without path. */
-char *av0;
-
/* Saved arguments to main(). */
char **saved_argv;
int saved_argc;
int received_sighup = 0;
/* session identifier, used by RSA-auth */
-unsigned char session_id[16];
+u_char session_id[16];
/* same for ssh2 */
-unsigned char *session_id2 = NULL;
+u_char *session_id2 = NULL;
int session_id2_len = 0;
/* record remote hostname or ip */
-unsigned int utmp_len = MAXHOSTNAMELEN;
+u_int utmp_len = MAXHOSTNAMELEN;
/* Prototypes for various functions defined later in this file. */
-void do_ssh1_kex();
-void do_ssh2_kex();
+void do_ssh1_kex(void);
+void do_ssh2_kex(void);
void ssh_dh1_server(Kex *, Buffer *_kexinit, Buffer *);
void ssh_dhgex_server(Kex *, Buffer *_kexinit, Buffer *);
log("Received SIGHUP; restarting.");
close_listen_socks();
execv(saved_argv[0], saved_argv);
- log("RESTART FAILED: av0='%s', error: %s.", av0, strerror(errno));
+ log("RESTART FAILED: av[0]='%.100s', error: %.100s.", saved_argv[0], strerror(errno));
exit(1);
}
* do anything with the private key or random state before forking.
* Thus there should be no concurrency control/asynchronous execution
* problems.
+ * XXX calling log() is not safe from races.
*/
-/* XXX do we really want this work to be done in a signal handler ? -m */
void
generate_empheral_server_key(void)
{
arc4random_stir();
log("RSA key generation complete.");
}
+
void
key_regeneration_alarm(int sig)
{
__progname = get_progname(av[0]);
init_rng();
- /* Save argv[0]. */
+ /* Save argv. */
saved_argc = ac;
saved_argv = av;
- if (strchr(av[0], '/'))
- av0 = strrchr(av[0], '/') + 1;
- else
- av0 = av[0];
/* Initialize configuration options to their default values. */
initialize_server_options(&options);
case '?':
default:
fprintf(stderr, "sshd version %s\n", SSH_VERSION);
- fprintf(stderr, "Usage: %s [options]\n", av0);
+ fprintf(stderr, "Usage: %s [options]\n", __progname);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -f file Configuration file (default %s)\n", SERVER_CONFIG_FILE);
fprintf(stderr, " -d Debugging mode (multiple -d means more debugging)\n");
fprintf(stderr, " -i Started from inetd\n");
+ fprintf(stderr, " -D Do not fork into daemon mode\n");
fprintf(stderr, " -q Quiet (no logging)\n");
fprintf(stderr, " -p port Listen on the specified port (default: 22)\n");
fprintf(stderr, " -k seconds Regenerate server key every this many seconds (default: 3600)\n");
- fprintf(stderr, " -g seconds Grace period for authentication (default: 300)\n");
+ fprintf(stderr, " -g seconds Grace period for authentication (default: 600)\n");
fprintf(stderr, " -b bits Size of server RSA key (default: 768 bits)\n");
fprintf(stderr, " -h file File from which to read host key (default: %s)\n",
HOST_KEY_FILE);
* Force logging to stderr until we have loaded the private host
* key (unless started from inetd)
*/
- log_init(av0,
- options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
+ log_init(__progname,
+ options.log_level == -1 ? SYSLOG_LEVEL_NOTICE : options.log_level,
options.log_facility == -1 ? SYSLOG_FACILITY_AUTH : options.log_facility,
!silent && !inetd_flag);
/* load private host keys */
sensitive_data.host_keys = xmalloc(options.num_host_key_files*sizeof(Key*));
+ for(i = 0; i < options.num_host_key_files; i++)
+ sensitive_data.host_keys[i] = NULL;
sensitive_data.server_key = NULL;
sensitive_data.ssh1_host_key = NULL;
sensitive_data.have_ssh1_key = 0;
/* Initialize the log (it is reinitialized below in case we forked). */
if (debug_flag && !inetd_flag)
log_stderr = 1;
- log_init(av0, options.log_level, options.log_facility, log_stderr);
+ log_init(__progname, options.log_level, options.log_facility, log_stderr);
/*
* If not in debugging mode, and not started from inetd, disconnect
#endif /* TIOCNOTTY */
}
/* Reinitialize the log (because of the fork above). */
- log_init(av0, options.log_level, options.log_facility, log_stderr);
+ log_init(__progname, options.log_level, options.log_facility, log_stderr);
/* Initialize the random number generator. */
arc4random_stir();
if (!debug_flag) {
/*
- * Record our pid in /etc/sshd_pid to make it easier
- * to kill the correct sshd. We don\'t want to do
- * this before the bind above because the bind will
+ * Record our pid in /var/run/sshd.pid to make it
+ * easier to kill the correct sshd. We don't want to
+ * do this before the bind above because the bind will
* fail if there already is a daemon, and this will
* overwrite any old pid in the file.
*/
f = fopen(options.pid_file, "wb");
if (f) {
- fprintf(f, "%u\n", (unsigned int) getpid());
+ fprintf(f, "%u\n", (u_int) getpid());
fclose(f);
}
}
/*
* the read end of the pipe is ready
* if the child has closed the pipe
- * after successfull authentication
+ * after successful authentication
* or if the child has died
*/
close(startup_pipes[i]);
close_listen_socks();
sock_in = newsock;
sock_out = newsock;
- log_init(av0, options.log_level, options.log_facility, log_stderr);
+ log_init(__progname, options.log_level, options.log_facility, log_stderr);
break;
}
}
{
struct request_info req;
- request_init(&req, RQ_DAEMON, av0, RQ_FILE, sock_in, NULL);
+ request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, NULL);
fromhost(&req);
if (!hosts_access(&req)) {
sshd_exchange_identification(sock_in, sock_out);
/*
- * Check that the connection comes from a privileged port. Rhosts-
- * and Rhosts-RSA-Authentication only make sense from priviledged
+ * Check that the connection comes from a privileged port.
+ * Rhosts-Authentication only makes sense from priviledged
* programs. Of course, if the intruder has root access on his local
* machine, he can connect from any port. So do not use these
* authentication methods from machines that you do not trust.
*/
if (remote_port >= IPPORT_RESERVED ||
remote_port < IPPORT_RESERVED / 2) {
- debug("Rhosts Authentication methods disabled, "
+ debug("Rhosts Authentication disabled, "
"originating port not trusted.");
options.rhosts_authentication = 0;
- options.rhosts_rsa_authentication = 0;
}
#ifdef KRB4
if (!packet_connection_is_ipv4() &&
* SSH1 key exchange
*/
void
-do_ssh1_kex()
+do_ssh1_kex(void)
{
int i, len;
int plen, slen;
BIGNUM *session_key_int;
- unsigned char session_key[SSH_SESSION_KEY_LENGTH];
- unsigned char cookie[8];
- unsigned int cipher_type, auth_mask, protocol_flags;
+ u_char session_key[SSH_SESSION_KEY_LENGTH];
+ u_char cookie[8];
+ u_int cipher_type, auth_mask, protocol_flags;
u_int32_t rand = 0;
/*
* SSH2 key exchange: diffie-hellman-group1-sha1
*/
void
-do_ssh2_kex()
+do_ssh2_kex(void)
{
Buffer *server_kexinit;
Buffer *client_kexinit;
#endif
int payload_len, dlen;
int slen;
- unsigned char *signature = NULL;
- unsigned char *server_host_key_blob = NULL;
- unsigned int sbloblen;
- unsigned int klen, kout;
- unsigned char *kbuf;
- unsigned char *hash;
+ u_char *signature = NULL;
+ u_char *server_host_key_blob = NULL;
+ u_int sbloblen;
+ u_int klen, kout;
+ u_char *kbuf;
+ u_char *hash;
BIGNUM *shared_secret = 0;
DH *dh;
BIGNUM *dh_client_pub = 0;
fatal("Unsupported hostkey type %d", kex->hostkey_type);
/* KEXDH */
+ /* generate DH key */
+ dh = dh_new_group1(); /* XXX depends on 'kex' */
+ dh_gen_key(dh);
+
debug("Wait SSH2_MSG_KEXDH_INIT.");
packet_read_expect(&payload_len, SSH2_MSG_KEXDH_INIT);
debug("bits %d", BN_num_bits(dh_client_pub));
#endif
- /* generate DH key */
- dh = dh_new_group1(); /* XXX depends on 'kex' */
-
#ifdef DEBUG_KEXDH
fprintf(stderr, "\np= ");
BN_print_fp(stderr, dh->p);
#endif
int payload_len, dlen;
int slen, nbits;
- unsigned char *signature = NULL;
- unsigned char *server_host_key_blob = NULL;
- unsigned int sbloblen;
- unsigned int klen, kout;
- unsigned char *kbuf;
- unsigned char *hash;
+ u_char *signature = NULL;
+ u_char *server_host_key_blob = NULL;
+ u_int sbloblen;
+ u_int klen, kout;
+ u_char *kbuf;
+ u_char *hash;
BIGNUM *shared_secret = 0;
DH *dh;
BIGNUM *dh_client_pub = 0;
packet_send();
packet_write_wait();
+ /* Compute our exchange value in parallel with the client */
+
+ dh_gen_key(dh);
+
debug("Wait SSH2_MSG_KEX_DH_GEX_INIT.");
packet_read_expect(&payload_len, SSH2_MSG_KEX_DH_GEX_INIT);