summaryrefslogtreecommitdiff
path: root/sshd.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2014-05-15 14:24:09 +1000
committerDamien Miller <djm@mindrot.org>2014-05-15 14:24:09 +1000
commit1f0311c7c7d10c94ff7f823de9c5b2ed79368b14 (patch)
treeae708c2a25f84a04bcb04f2dbf3e8039e0f692bc /sshd.c
parentc5893785564498cea73cb60d2cf199490483e080 (diff)
- markus@cvs.openbsd.org 2014/04/29 18:01:49
[auth.c authfd.c authfile.c bufaux.c cipher.c cipher.h hostfile.c] [kex.c key.c mac.c monitor.c monitor_wrap.c myproposal.h packet.c] [roaming_client.c ssh-agent.c ssh-keygen.c ssh-keyscan.c ssh-keysign.c] [ssh-pkcs11.h ssh.c sshconnect.c sshconnect2.c sshd.c] make compiling against OpenSSL optional (make OPENSSL=no); reduces algorithms to curve25519, aes-ctr, chacha, ed25519; allows us to explore further options; with and ok djm
Diffstat (limited to 'sshd.c')
-rw-r--r--sshd.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/sshd.c b/sshd.c
index b955f1921..6e7192cf5 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.425 2014/04/19 14:53:48 tedu Exp $ */ 1/* $OpenBSD: sshd.c,v 1.426 2014/04/29 18:01:49 markus 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>
@@ -98,7 +100,6 @@
98#include "digest.h" 100#include "digest.h"
99#include "key.h" 101#include "key.h"
100#include "kex.h" 102#include "kex.h"
101#include "dh.h"
102#include "myproposal.h" 103#include "myproposal.h"
103#include "authfile.h" 104#include "authfile.h"
104#include "pathnames.h" 105#include "pathnames.h"
@@ -256,7 +257,9 @@ struct passwd *privsep_pw = NULL;
256void destroy_sensitive_data(void); 257void destroy_sensitive_data(void);
257void demote_sensitive_data(void); 258void demote_sensitive_data(void);
258 259
260#ifdef WITH_SSH1
259static void do_ssh1_kex(void); 261static void do_ssh1_kex(void);
262#endif
260static void do_ssh2_kex(void); 263static void do_ssh2_kex(void);
261 264
262/* 265/*
@@ -931,7 +934,13 @@ static void
931usage(void) 934usage(void)
932{ 935{
933 fprintf(stderr, "%s, %s\n", 936 fprintf(stderr, "%s, %s\n",
934 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 );
935 fprintf(stderr, 944 fprintf(stderr,
936"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"
937" [-E log_file] [-f config_file] [-g login_grace_time]\n" 946" [-E log_file] [-f config_file] [-g login_grace_time]\n"
@@ -964,6 +973,7 @@ send_rexec_state(int fd, Buffer *conf)
964 buffer_init(&m); 973 buffer_init(&m);
965 buffer_put_cstring(&m, buffer_ptr(conf)); 974 buffer_put_cstring(&m, buffer_ptr(conf));
966 975
976#ifdef WITH_SSH1
967 if (sensitive_data.server_key != NULL && 977 if (sensitive_data.server_key != NULL &&
968 sensitive_data.server_key->type == KEY_RSA1) { 978 sensitive_data.server_key->type == KEY_RSA1) {
969 buffer_put_int(&m, 1); 979 buffer_put_int(&m, 1);
@@ -974,6 +984,7 @@ send_rexec_state(int fd, Buffer *conf)
974 buffer_put_bignum(&m, sensitive_data.server_key->rsa->p); 984 buffer_put_bignum(&m, sensitive_data.server_key->rsa->p);
975 buffer_put_bignum(&m, sensitive_data.server_key->rsa->q); 985 buffer_put_bignum(&m, sensitive_data.server_key->rsa->q);
976 } else 986 } else
987#endif
977 buffer_put_int(&m, 0); 988 buffer_put_int(&m, 0);
978 989
979#ifndef OPENSSL_PRNG_ONLY 990#ifndef OPENSSL_PRNG_ONLY
@@ -1010,6 +1021,7 @@ recv_rexec_state(int fd, Buffer *conf)
1010 free(cp); 1021 free(cp);
1011 1022
1012 if (buffer_get_int(&m)) { 1023 if (buffer_get_int(&m)) {
1024#ifdef WITH_SSH1
1013 if (sensitive_data.server_key != NULL) 1025 if (sensitive_data.server_key != NULL)
1014 key_free(sensitive_data.server_key); 1026 key_free(sensitive_data.server_key);
1015 sensitive_data.server_key = key_new_private(KEY_RSA1); 1027 sensitive_data.server_key = key_new_private(KEY_RSA1);
@@ -1021,6 +1033,9 @@ recv_rexec_state(int fd, Buffer *conf)
1021 buffer_get_bignum(&m, sensitive_data.server_key->rsa->q); 1033 buffer_get_bignum(&m, sensitive_data.server_key->rsa->q);
1022 rsa_generate_additional_parameters( 1034 rsa_generate_additional_parameters(
1023 sensitive_data.server_key->rsa); 1035 sensitive_data.server_key->rsa);
1036#else
1037 fatal("ssh1 not supported");
1038#endif
1024 } 1039 }
1025 1040
1026#ifndef OPENSSL_PRNG_ONLY 1041#ifndef OPENSSL_PRNG_ONLY
@@ -1543,7 +1558,9 @@ main(int ac, char **av)
1543 else 1558 else
1544 closefrom(REEXEC_DEVCRYPTO_RESERVED_FD); 1559 closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
1545 1560
1561#ifdef WITH_OPENSSL
1546 OpenSSL_add_all_algorithms(); 1562 OpenSSL_add_all_algorithms();
1563#endif
1547 1564
1548 /* If requested, redirect the logs to the specified logfile. */ 1565 /* If requested, redirect the logs to the specified logfile. */
1549 if (logfile != NULL) { 1566 if (logfile != NULL) {
@@ -1648,7 +1665,12 @@ main(int ac, char **av)
1648 } 1665 }
1649 1666
1650 debug("sshd version %s, %s", SSH_VERSION, 1667 debug("sshd version %s, %s", SSH_VERSION,
1651 SSLeay_version(SSLEAY_VERSION)); 1668#ifdef WITH_OPENSSL
1669 SSLeay_version(SSLEAY_VERSION)
1670#else
1671 "without OpenSSL"
1672#endif
1673 );
1652 1674
1653 /* Store privilege separation user for later use if required. */ 1675 /* Store privilege separation user for later use if required. */
1654 if ((privsep_pw = getpwnam(SSH_PRIVSEP_USER)) == NULL) { 1676 if ((privsep_pw = getpwnam(SSH_PRIVSEP_USER)) == NULL) {
@@ -1770,6 +1792,8 @@ main(int ac, char **av)
1770 debug("host certificate: #%d type %d %s", j, key->type, 1792 debug("host certificate: #%d type %d %s", j, key->type,
1771 key_type(key)); 1793 key_type(key));
1772 } 1794 }
1795
1796#ifdef WITH_SSH1
1773 /* Check certain values for sanity. */ 1797 /* Check certain values for sanity. */
1774 if (options.protocol & SSH_PROTO_1) { 1798 if (options.protocol & SSH_PROTO_1) {
1775 if (options.server_key_bits < 512 || 1799 if (options.server_key_bits < 512 ||
@@ -1794,6 +1818,7 @@ main(int ac, char **av)
1794 options.server_key_bits); 1818 options.server_key_bits);
1795 } 1819 }
1796 } 1820 }
1821#endif
1797 1822
1798 if (use_privsep) { 1823 if (use_privsep) {
1799 struct stat st; 1824 struct stat st;
@@ -2077,8 +2102,12 @@ main(int ac, char **av)
2077 do_ssh2_kex(); 2102 do_ssh2_kex();
2078 do_authentication2(authctxt); 2103 do_authentication2(authctxt);
2079 } else { 2104 } else {
2105#ifdef WITH_SSH1
2080 do_ssh1_kex(); 2106 do_ssh1_kex();
2081 do_authentication(authctxt); 2107 do_authentication(authctxt);
2108#else
2109 fatal("ssh1 not supported");
2110#endif
2082 } 2111 }
2083 /* 2112 /*
2084 * If we use privilege separation, the unprivileged child transfers 2113 * If we use privilege separation, the unprivileged child transfers
@@ -2162,6 +2191,7 @@ main(int ac, char **av)
2162 exit(0); 2191 exit(0);
2163} 2192}
2164 2193
2194#ifdef WITH_SSH1
2165/* 2195/*
2166 * Decrypt session_key_int using our private server key and private host key 2196 * Decrypt session_key_int using our private server key and private host key
2167 * (key with larger modulus first). 2197 * (key with larger modulus first).
@@ -2211,6 +2241,7 @@ ssh1_session_key(BIGNUM *session_key_int)
2211 } 2241 }
2212 return (rsafail); 2242 return (rsafail);
2213} 2243}
2244
2214/* 2245/*
2215 * SSH1 key exchange 2246 * SSH1 key exchange
2216 */ 2247 */
@@ -2388,6 +2419,7 @@ do_ssh1_kex(void)
2388 packet_send(); 2419 packet_send();
2389 packet_write_wait(); 2420 packet_write_wait();
2390} 2421}
2422#endif
2391 2423
2392void 2424void
2393sshd_hostkey_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen, 2425sshd_hostkey_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen,
@@ -2450,11 +2482,13 @@ do_ssh2_kex(void)
2450 2482
2451 /* start key exchange */ 2483 /* start key exchange */
2452 kex = kex_setup(myproposal); 2484 kex = kex_setup(myproposal);
2485#ifdef WITH_OPENSSL
2453 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; 2486 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
2454 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; 2487 kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
2455 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; 2488 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
2456 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; 2489 kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
2457 kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 2490 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2491#endif
2458 kex->kex[KEX_C25519_SHA256] = kexc25519_server; 2492 kex->kex[KEX_C25519_SHA256] = kexc25519_server;
2459 kex->server = 1; 2493 kex->server = 1;
2460 kex->client_version_string=client_version_string; 2494 kex->client_version_string=client_version_string;