summaryrefslogtreecommitdiff
path: root/sshd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshd.c')
-rw-r--r--sshd.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/sshd.c b/sshd.c
index 23e8c2de0..ffe360c62 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.414 2014/01/09 23:26:48 djm Exp $ */ 1/* $OpenBSD: sshd.c,v 1.420 2014/02/26 21:53:37 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
@@ -74,7 +74,6 @@
74 74
75#include <openssl/dh.h> 75#include <openssl/dh.h>
76#include <openssl/bn.h> 76#include <openssl/bn.h>
77#include <openssl/md5.h>
78#include <openssl/rand.h> 77#include <openssl/rand.h>
79#include "openbsd-compat/openssl-compat.h" 78#include "openbsd-compat/openssl-compat.h"
80 79
@@ -96,6 +95,7 @@
96#include "uidswap.h" 95#include "uidswap.h"
97#include "compat.h" 96#include "compat.h"
98#include "cipher.h" 97#include "cipher.h"
98#include "digest.h"
99#include "key.h" 99#include "key.h"
100#include "kex.h" 100#include "kex.h"
101#include "dh.h" 101#include "dh.h"
@@ -584,7 +584,7 @@ destroy_sensitive_data(void)
584 } 584 }
585 } 585 }
586 sensitive_data.ssh1_host_key = NULL; 586 sensitive_data.ssh1_host_key = NULL;
587 memset(sensitive_data.ssh1_cookie, 0, SSH_SESSION_KEY_LENGTH); 587 explicit_bzero(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH);
588} 588}
589 589
590/* Demote private to public keys for network child */ 590/* Demote private to public keys for network child */
@@ -623,10 +623,16 @@ privsep_preauth_child(void)
623 /* Enable challenge-response authentication for privilege separation */ 623 /* Enable challenge-response authentication for privilege separation */
624 privsep_challenge_enable(); 624 privsep_challenge_enable();
625 625
626#ifdef GSSAPI
627 /* Cache supported mechanism OIDs for later use */
628 if (options.gss_authentication)
629 ssh_gssapi_prepare_supported_oids();
630#endif
631
626 arc4random_stir(); 632 arc4random_stir();
627 arc4random_buf(rnd, sizeof(rnd)); 633 arc4random_buf(rnd, sizeof(rnd));
628 RAND_seed(rnd, sizeof(rnd)); 634 RAND_seed(rnd, sizeof(rnd));
629 bzero(rnd, sizeof(rnd)); 635 explicit_bzero(rnd, sizeof(rnd));
630 636
631 /* Demote the private keys to public keys. */ 637 /* Demote the private keys to public keys. */
632 demote_sensitive_data(); 638 demote_sensitive_data();
@@ -761,7 +767,7 @@ privsep_postauth(Authctxt *authctxt)
761 arc4random_stir(); 767 arc4random_stir();
762 arc4random_buf(rnd, sizeof(rnd)); 768 arc4random_buf(rnd, sizeof(rnd));
763 RAND_seed(rnd, sizeof(rnd)); 769 RAND_seed(rnd, sizeof(rnd));
764 bzero(rnd, sizeof(rnd)); 770 explicit_bzero(rnd, sizeof(rnd));
765 771
766 /* Drop privileges */ 772 /* Drop privileges */
767 do_setusercontext(authctxt->pw, authctxt->role); 773 do_setusercontext(authctxt->pw, authctxt->role);
@@ -1360,7 +1366,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1360 arc4random_stir(); 1366 arc4random_stir();
1361 arc4random_buf(rnd, sizeof(rnd)); 1367 arc4random_buf(rnd, sizeof(rnd));
1362 RAND_seed(rnd, sizeof(rnd)); 1368 RAND_seed(rnd, sizeof(rnd));
1363 bzero(rnd, sizeof(rnd)); 1369 explicit_bzero(rnd, sizeof(rnd));
1364 } 1370 }
1365 1371
1366 /* child process check (or debug mode) */ 1372 /* child process check (or debug mode) */
@@ -1662,7 +1668,8 @@ main(int ac, char **av)
1662 fatal("Privilege separation user %s does not exist", 1668 fatal("Privilege separation user %s does not exist",
1663 SSH_PRIVSEP_USER); 1669 SSH_PRIVSEP_USER);
1664 } else { 1670 } else {
1665 memset(privsep_pw->pw_passwd, 0, strlen(privsep_pw->pw_passwd)); 1671 explicit_bzero(privsep_pw->pw_passwd,
1672 strlen(privsep_pw->pw_passwd));
1666 privsep_pw = pwcopy(privsep_pw); 1673 privsep_pw = pwcopy(privsep_pw);
1667 free(privsep_pw->pw_passwd); 1674 free(privsep_pw->pw_passwd);
1668 privsep_pw->pw_passwd = xstrdup("*"); 1675 privsep_pw->pw_passwd = xstrdup("*");
@@ -2407,7 +2414,7 @@ do_ssh1_kex(void)
2407 get_remote_ipaddr(), len, (u_long)sizeof(session_key)); 2414 get_remote_ipaddr(), len, (u_long)sizeof(session_key));
2408 rsafail++; 2415 rsafail++;
2409 } else { 2416 } else {
2410 memset(session_key, 0, sizeof(session_key)); 2417 explicit_bzero(session_key, sizeof(session_key));
2411 BN_bn2bin(session_key_int, 2418 BN_bn2bin(session_key_int,
2412 session_key + sizeof(session_key) - len); 2419 session_key + sizeof(session_key) - len);
2413 2420
@@ -2426,20 +2433,26 @@ do_ssh1_kex(void)
2426 if (rsafail) { 2433 if (rsafail) {
2427 int bytes = BN_num_bytes(session_key_int); 2434 int bytes = BN_num_bytes(session_key_int);
2428 u_char *buf = xmalloc(bytes); 2435 u_char *buf = xmalloc(bytes);
2429 MD5_CTX md; 2436 struct ssh_digest_ctx *md;
2430 2437
2431 logit("do_connection: generating a fake encryption key"); 2438 logit("do_connection: generating a fake encryption key");
2432 BN_bn2bin(session_key_int, buf); 2439 BN_bn2bin(session_key_int, buf);
2433 MD5_Init(&md); 2440 if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
2434 MD5_Update(&md, buf, bytes); 2441 ssh_digest_update(md, buf, bytes) < 0 ||
2435 MD5_Update(&md, sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); 2442 ssh_digest_update(md, sensitive_data.ssh1_cookie,
2436 MD5_Final(session_key, &md); 2443 SSH_SESSION_KEY_LENGTH) < 0 ||
2437 MD5_Init(&md); 2444 ssh_digest_final(md, session_key, sizeof(session_key)) < 0)
2438 MD5_Update(&md, session_key, 16); 2445 fatal("%s: md5 failed", __func__);
2439 MD5_Update(&md, buf, bytes); 2446 ssh_digest_free(md);
2440 MD5_Update(&md, sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); 2447 if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL ||
2441 MD5_Final(session_key + 16, &md); 2448 ssh_digest_update(md, session_key, 16) < 0 ||
2442 memset(buf, 0, bytes); 2449 ssh_digest_update(md, sensitive_data.ssh1_cookie,
2450 SSH_SESSION_KEY_LENGTH) < 0 ||
2451 ssh_digest_final(md, session_key + 16,
2452 sizeof(session_key) - 16) < 0)
2453 fatal("%s: md5 failed", __func__);
2454 ssh_digest_free(md);
2455 explicit_bzero(buf, bytes);
2443 free(buf); 2456 free(buf);
2444 for (i = 0; i < 16; i++) 2457 for (i = 0; i < 16; i++)
2445 session_id[i] = session_key[i] ^ session_key[i + 16]; 2458 session_id[i] = session_key[i] ^ session_key[i + 16];
@@ -2457,7 +2470,7 @@ do_ssh1_kex(void)
2457 packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type); 2470 packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type);
2458 2471
2459 /* Destroy our copy of the session key. It is no longer needed. */ 2472 /* Destroy our copy of the session key. It is no longer needed. */
2460 memset(session_key, 0, sizeof(session_key)); 2473 explicit_bzero(session_key, sizeof(session_key));
2461 2474
2462 debug("Received session key; encryption turned on."); 2475 debug("Received session key; encryption turned on.");
2463 2476