summaryrefslogtreecommitdiff
path: root/sshd.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2014-10-07 12:13:50 +0100
committerColin Watson <cjwatson@debian.org>2014-10-07 12:13:50 +0100
commit487bdb3a5ef6075887b830ccb8a0b14f6da78e93 (patch)
treea2cff6fec1e6c4b4153a170a3e172cfe6bfdec46 /sshd.c
parent796ba4fd011b5d0d9d78d592ba2f30fc9d5ed2e7 (diff)
parent28453d58058a4d60c3ebe7d7f0c31a510cbf6158 (diff)
Import openssh_6.7p1.orig.tar.gz
Diffstat (limited to 'sshd.c')
-rw-r--r--sshd.c90
1 files changed, 53 insertions, 37 deletions
diff --git a/sshd.c b/sshd.c
index 7523de977..481d00155 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.420 2014/02/26 21:53:37 markus Exp $ */ 1/* $OpenBSD: sshd.c,v 1.428 2014/07/15 15:54:14 millert Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -72,10 +72,12 @@
72#include <string.h> 72#include <string.h>
73#include <unistd.h> 73#include <unistd.h>
74 74
75#ifdef WITH_OPENSSL
75#include <openssl/dh.h> 76#include <openssl/dh.h>
76#include <openssl/bn.h> 77#include <openssl/bn.h>
77#include <openssl/rand.h> 78#include <openssl/rand.h>
78#include "openbsd-compat/openssl-compat.h" 79#include "openbsd-compat/openssl-compat.h"
80#endif
79 81
80#ifdef HAVE_SECUREWARE 82#ifdef HAVE_SECUREWARE
81#include <sys/security.h> 83#include <sys/security.h>
@@ -91,6 +93,7 @@
91#include "packet.h" 93#include "packet.h"
92#include "log.h" 94#include "log.h"
93#include "buffer.h" 95#include "buffer.h"
96#include "misc.h"
94#include "servconf.h" 97#include "servconf.h"
95#include "uidswap.h" 98#include "uidswap.h"
96#include "compat.h" 99#include "compat.h"
@@ -98,7 +101,6 @@
98#include "digest.h" 101#include "digest.h"
99#include "key.h" 102#include "key.h"
100#include "kex.h" 103#include "kex.h"
101#include "dh.h"
102#include "myproposal.h" 104#include "myproposal.h"
103#include "authfile.h" 105#include "authfile.h"
104#include "pathnames.h" 106#include "pathnames.h"
@@ -107,7 +109,6 @@
107#include "hostfile.h" 109#include "hostfile.h"
108#include "auth.h" 110#include "auth.h"
109#include "authfd.h" 111#include "authfd.h"
110#include "misc.h"
111#include "msg.h" 112#include "msg.h"
112#include "dispatch.h" 113#include "dispatch.h"
113#include "channels.h" 114#include "channels.h"
@@ -122,13 +123,6 @@
122#include "ssh-sandbox.h" 123#include "ssh-sandbox.h"
123#include "version.h" 124#include "version.h"
124 125
125#ifdef LIBWRAP
126#include <tcpd.h>
127#include <syslog.h>
128int allow_severity;
129int deny_severity;
130#endif /* LIBWRAP */
131
132#ifndef O_NOCTTY 126#ifndef O_NOCTTY
133#define O_NOCTTY 0 127#define O_NOCTTY 0
134#endif 128#endif
@@ -263,7 +257,9 @@ struct passwd *privsep_pw = NULL;
263void destroy_sensitive_data(void); 257void destroy_sensitive_data(void);
264void demote_sensitive_data(void); 258void demote_sensitive_data(void);
265 259
260#ifdef WITH_SSH1
266static void do_ssh1_kex(void); 261static void do_ssh1_kex(void);
262#endif
267static void do_ssh2_kex(void); 263static void do_ssh2_kex(void);
268 264
269/* 265/*
@@ -938,7 +934,13 @@ static void
938usage(void) 934usage(void)
939{ 935{
940 fprintf(stderr, "%s, %s\n", 936 fprintf(stderr, "%s, %s\n",
941 SSH_RELEASE, SSLeay_version(SSLEAY_VERSION)); 937 SSH_RELEASE,
938#ifdef WITH_OPENSSL
939 SSLeay_version(SSLEAY_VERSION)
940#else
941 "without OpenSSL"
942#endif
943 );
942 fprintf(stderr, 944 fprintf(stderr,
943"usage: sshd [-46DdeiqTt] [-b bits] [-C connection_spec] [-c host_cert_file]\n" 945"usage: sshd [-46DdeiqTt] [-b bits] [-C connection_spec] [-c host_cert_file]\n"
944" [-E log_file] [-f config_file] [-g login_grace_time]\n" 946" [-E log_file] [-f config_file] [-g login_grace_time]\n"
@@ -971,6 +973,7 @@ send_rexec_state(int fd, Buffer *conf)
971 buffer_init(&m); 973 buffer_init(&m);
972 buffer_put_cstring(&m, buffer_ptr(conf)); 974 buffer_put_cstring(&m, buffer_ptr(conf));
973 975
976#ifdef WITH_SSH1
974 if (sensitive_data.server_key != NULL && 977 if (sensitive_data.server_key != NULL &&
975 sensitive_data.server_key->type == KEY_RSA1) { 978 sensitive_data.server_key->type == KEY_RSA1) {
976 buffer_put_int(&m, 1); 979 buffer_put_int(&m, 1);
@@ -981,6 +984,7 @@ send_rexec_state(int fd, Buffer *conf)
981 buffer_put_bignum(&m, sensitive_data.server_key->rsa->p); 984 buffer_put_bignum(&m, sensitive_data.server_key->rsa->p);
982 buffer_put_bignum(&m, sensitive_data.server_key->rsa->q); 985 buffer_put_bignum(&m, sensitive_data.server_key->rsa->q);
983 } else 986 } else
987#endif
984 buffer_put_int(&m, 0); 988 buffer_put_int(&m, 0);
985 989
986#ifndef OPENSSL_PRNG_ONLY 990#ifndef OPENSSL_PRNG_ONLY
@@ -1017,6 +1021,7 @@ recv_rexec_state(int fd, Buffer *conf)
1017 free(cp); 1021 free(cp);
1018 1022
1019 if (buffer_get_int(&m)) { 1023 if (buffer_get_int(&m)) {
1024#ifdef WITH_SSH1
1020 if (sensitive_data.server_key != NULL) 1025 if (sensitive_data.server_key != NULL)
1021 key_free(sensitive_data.server_key); 1026 key_free(sensitive_data.server_key);
1022 sensitive_data.server_key = key_new_private(KEY_RSA1); 1027 sensitive_data.server_key = key_new_private(KEY_RSA1);
@@ -1026,8 +1031,13 @@ recv_rexec_state(int fd, Buffer *conf)
1026 buffer_get_bignum(&m, sensitive_data.server_key->rsa->iqmp); 1031 buffer_get_bignum(&m, sensitive_data.server_key->rsa->iqmp);
1027 buffer_get_bignum(&m, sensitive_data.server_key->rsa->p); 1032 buffer_get_bignum(&m, sensitive_data.server_key->rsa->p);
1028 buffer_get_bignum(&m, sensitive_data.server_key->rsa->q); 1033 buffer_get_bignum(&m, sensitive_data.server_key->rsa->q);
1029 rsa_generate_additional_parameters( 1034 if (rsa_generate_additional_parameters(
1030 sensitive_data.server_key->rsa); 1035 sensitive_data.server_key->rsa) != 0)
1036 fatal("%s: rsa_generate_additional_parameters "
1037 "error", __func__);
1038#else
1039 fatal("ssh1 not supported");
1040#endif
1031 } 1041 }
1032 1042
1033#ifndef OPENSSL_PRNG_ONLY 1043#ifndef OPENSSL_PRNG_ONLY
@@ -1550,7 +1560,9 @@ main(int ac, char **av)
1550 else 1560 else
1551 closefrom(REEXEC_DEVCRYPTO_RESERVED_FD); 1561 closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
1552 1562
1563#ifdef WITH_OPENSSL
1553 OpenSSL_add_all_algorithms(); 1564 OpenSSL_add_all_algorithms();
1565#endif
1554 1566
1555 /* If requested, redirect the logs to the specified logfile. */ 1567 /* If requested, redirect the logs to the specified logfile. */
1556 if (logfile != NULL) { 1568 if (logfile != NULL) {
@@ -1655,7 +1667,12 @@ main(int ac, char **av)
1655 } 1667 }
1656 1668
1657 debug("sshd version %s, %s", SSH_VERSION, 1669 debug("sshd version %s, %s", SSH_VERSION,
1658 SSLeay_version(SSLEAY_VERSION)); 1670#ifdef WITH_OPENSSL
1671 SSLeay_version(SSLEAY_VERSION)
1672#else
1673 "without OpenSSL"
1674#endif
1675 );
1659 1676
1660 /* Store privilege separation user for later use if required. */ 1677 /* Store privilege separation user for later use if required. */
1661 if ((privsep_pw = getpwnam(SSH_PRIVSEP_USER)) == NULL) { 1678 if ((privsep_pw = getpwnam(SSH_PRIVSEP_USER)) == NULL) {
@@ -1777,6 +1794,8 @@ main(int ac, char **av)
1777 debug("host certificate: #%d type %d %s", j, key->type, 1794 debug("host certificate: #%d type %d %s", j, key->type,
1778 key_type(key)); 1795 key_type(key));
1779 } 1796 }
1797
1798#ifdef WITH_SSH1
1780 /* Check certain values for sanity. */ 1799 /* Check certain values for sanity. */
1781 if (options.protocol & SSH_PROTO_1) { 1800 if (options.protocol & SSH_PROTO_1) {
1782 if (options.server_key_bits < 512 || 1801 if (options.server_key_bits < 512 ||
@@ -1801,6 +1820,7 @@ main(int ac, char **av)
1801 options.server_key_bits); 1820 options.server_key_bits);
1802 } 1821 }
1803 } 1822 }
1823#endif
1804 1824
1805 if (use_privsep) { 1825 if (use_privsep) {
1806 struct stat st; 1826 struct stat st;
@@ -2034,24 +2054,6 @@ main(int ac, char **av)
2034#ifdef SSH_AUDIT_EVENTS 2054#ifdef SSH_AUDIT_EVENTS
2035 audit_connection_from(remote_ip, remote_port); 2055 audit_connection_from(remote_ip, remote_port);
2036#endif 2056#endif
2037#ifdef LIBWRAP
2038 allow_severity = options.log_facility|LOG_INFO;
2039 deny_severity = options.log_facility|LOG_WARNING;
2040 /* Check whether logins are denied from this host. */
2041 if (packet_connection_is_on_socket()) {
2042 struct request_info req;
2043
2044 request_init(&req, RQ_DAEMON, __progname, RQ_FILE, sock_in, 0);
2045 fromhost(&req);
2046
2047 if (!hosts_access(&req)) {
2048 debug("Connection refused by tcp wrapper");
2049 refuse(&req);
2050 /* NOTREACHED */
2051 fatal("libwrap refuse returns");
2052 }
2053 }
2054#endif /* LIBWRAP */
2055 2057
2056 /* Log the connection. */ 2058 /* Log the connection. */
2057 verbose("Connection from %s port %d on %s port %d", 2059 verbose("Connection from %s port %d on %s port %d",
@@ -2102,8 +2104,12 @@ main(int ac, char **av)
2102 do_ssh2_kex(); 2104 do_ssh2_kex();
2103 do_authentication2(authctxt); 2105 do_authentication2(authctxt);
2104 } else { 2106 } else {
2107#ifdef WITH_SSH1
2105 do_ssh1_kex(); 2108 do_ssh1_kex();
2106 do_authentication(authctxt); 2109 do_authentication(authctxt);
2110#else
2111 fatal("ssh1 not supported");
2112#endif
2107 } 2113 }
2108 /* 2114 /*
2109 * If we use privilege separation, the unprivileged child transfers 2115 * If we use privilege separation, the unprivileged child transfers
@@ -2187,6 +2193,7 @@ main(int ac, char **av)
2187 exit(0); 2193 exit(0);
2188} 2194}
2189 2195
2196#ifdef WITH_SSH1
2190/* 2197/*
2191 * Decrypt session_key_int using our private server key and private host key 2198 * Decrypt session_key_int using our private server key and private host key
2192 * (key with larger modulus first). 2199 * (key with larger modulus first).
@@ -2210,10 +2217,10 @@ ssh1_session_key(BIGNUM *session_key_int)
2210 SSH_KEY_BITS_RESERVED); 2217 SSH_KEY_BITS_RESERVED);
2211 } 2218 }
2212 if (rsa_private_decrypt(session_key_int, session_key_int, 2219 if (rsa_private_decrypt(session_key_int, session_key_int,
2213 sensitive_data.server_key->rsa) <= 0) 2220 sensitive_data.server_key->rsa) != 0)
2214 rsafail++; 2221 rsafail++;
2215 if (rsa_private_decrypt(session_key_int, session_key_int, 2222 if (rsa_private_decrypt(session_key_int, session_key_int,
2216 sensitive_data.ssh1_host_key->rsa) <= 0) 2223 sensitive_data.ssh1_host_key->rsa) != 0)
2217 rsafail++; 2224 rsafail++;
2218 } else { 2225 } else {
2219 /* Host key has bigger modulus (or they are equal). */ 2226 /* Host key has bigger modulus (or they are equal). */
@@ -2228,14 +2235,15 @@ ssh1_session_key(BIGNUM *session_key_int)
2228 SSH_KEY_BITS_RESERVED); 2235 SSH_KEY_BITS_RESERVED);
2229 } 2236 }
2230 if (rsa_private_decrypt(session_key_int, session_key_int, 2237 if (rsa_private_decrypt(session_key_int, session_key_int,
2231 sensitive_data.ssh1_host_key->rsa) < 0) 2238 sensitive_data.ssh1_host_key->rsa) != 0)
2232 rsafail++; 2239 rsafail++;
2233 if (rsa_private_decrypt(session_key_int, session_key_int, 2240 if (rsa_private_decrypt(session_key_int, session_key_int,
2234 sensitive_data.server_key->rsa) < 0) 2241 sensitive_data.server_key->rsa) != 0)
2235 rsafail++; 2242 rsafail++;
2236 } 2243 }
2237 return (rsafail); 2244 return (rsafail);
2238} 2245}
2246
2239/* 2247/*
2240 * SSH1 key exchange 2248 * SSH1 key exchange
2241 */ 2249 */
@@ -2413,6 +2421,7 @@ do_ssh1_kex(void)
2413 packet_send(); 2421 packet_send();
2414 packet_write_wait(); 2422 packet_write_wait();
2415} 2423}
2424#endif
2416 2425
2417void 2426void
2418sshd_hostkey_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen, 2427sshd_hostkey_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen,
@@ -2437,6 +2446,7 @@ sshd_hostkey_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen,
2437static void 2446static void
2438do_ssh2_kex(void) 2447do_ssh2_kex(void)
2439{ 2448{
2449 char *myproposal[PROPOSAL_MAX] = { KEX_SERVER };
2440 Kex *kex; 2450 Kex *kex;
2441 2451
2442 if (options.ciphers != NULL) { 2452 if (options.ciphers != NULL) {
@@ -2462,6 +2472,9 @@ do_ssh2_kex(void)
2462 if (options.kex_algorithms != NULL) 2472 if (options.kex_algorithms != NULL)
2463 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms; 2473 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
2464 2474
2475 myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
2476 myproposal[PROPOSAL_KEX_ALGS]);
2477
2465 if (options.rekey_limit || options.rekey_interval) 2478 if (options.rekey_limit || options.rekey_interval)
2466 packet_set_rekey_limits((u_int32_t)options.rekey_limit, 2479 packet_set_rekey_limits((u_int32_t)options.rekey_limit,
2467 (time_t)options.rekey_interval); 2480 (time_t)options.rekey_interval);
@@ -2471,11 +2484,13 @@ do_ssh2_kex(void)
2471 2484
2472 /* start key exchange */ 2485 /* start key exchange */
2473 kex = kex_setup(myproposal); 2486 kex = kex_setup(myproposal);
2487#ifdef WITH_OPENSSL
2474 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; 2488 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
2475 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; 2489 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
2476 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; 2490 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2477 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; 2491 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2478 kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 2492 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2493#endif
2479 kex->kex[KEX_C25519_SHA256] = kexc25519_server; 2494 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
2480 kex->server = 1; 2495 kex->server = 1;
2481 kex->client_version_string=client_version_string; 2496 kex->client_version_string=client_version_string;
@@ -2508,7 +2523,8 @@ cleanup_exit(int i)
2508{ 2523{
2509 if (the_authctxt) { 2524 if (the_authctxt) {
2510 do_cleanup(the_authctxt); 2525 do_cleanup(the_authctxt);
2511 if (use_privsep && privsep_is_preauth && pmonitor->m_pid > 1) { 2526 if (use_privsep && privsep_is_preauth &&
2527 pmonitor != NULL && pmonitor->m_pid > 1) {
2512 debug("Killing privsep child %d", pmonitor->m_pid); 2528 debug("Killing privsep child %d", pmonitor->m_pid);
2513 if (kill(pmonitor->m_pid, SIGKILL) != 0 && 2529 if (kill(pmonitor->m_pid, SIGKILL) != 0 &&
2514 errno != ESRCH) 2530 errno != ESRCH)