diff options
Diffstat (limited to 'sshd.c')
-rw-r--r-- | sshd.c | 53 |
1 files changed, 33 insertions, 20 deletions
@@ -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" |
@@ -579,7 +579,7 @@ destroy_sensitive_data(void) | |||
579 | } | 579 | } |
580 | } | 580 | } |
581 | sensitive_data.ssh1_host_key = NULL; | 581 | sensitive_data.ssh1_host_key = NULL; |
582 | memset(sensitive_data.ssh1_cookie, 0, SSH_SESSION_KEY_LENGTH); | 582 | explicit_bzero(sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); |
583 | } | 583 | } |
584 | 584 | ||
585 | /* Demote private to public keys for network child */ | 585 | /* Demote private to public keys for network child */ |
@@ -618,10 +618,16 @@ privsep_preauth_child(void) | |||
618 | /* Enable challenge-response authentication for privilege separation */ | 618 | /* Enable challenge-response authentication for privilege separation */ |
619 | privsep_challenge_enable(); | 619 | privsep_challenge_enable(); |
620 | 620 | ||
621 | #ifdef GSSAPI | ||
622 | /* Cache supported mechanism OIDs for later use */ | ||
623 | if (options.gss_authentication) | ||
624 | ssh_gssapi_prepare_supported_oids(); | ||
625 | #endif | ||
626 | |||
621 | arc4random_stir(); | 627 | arc4random_stir(); |
622 | arc4random_buf(rnd, sizeof(rnd)); | 628 | arc4random_buf(rnd, sizeof(rnd)); |
623 | RAND_seed(rnd, sizeof(rnd)); | 629 | RAND_seed(rnd, sizeof(rnd)); |
624 | bzero(rnd, sizeof(rnd)); | 630 | explicit_bzero(rnd, sizeof(rnd)); |
625 | 631 | ||
626 | /* Demote the private keys to public keys. */ | 632 | /* Demote the private keys to public keys. */ |
627 | demote_sensitive_data(); | 633 | demote_sensitive_data(); |
@@ -756,7 +762,7 @@ privsep_postauth(Authctxt *authctxt) | |||
756 | arc4random_stir(); | 762 | arc4random_stir(); |
757 | arc4random_buf(rnd, sizeof(rnd)); | 763 | arc4random_buf(rnd, sizeof(rnd)); |
758 | RAND_seed(rnd, sizeof(rnd)); | 764 | RAND_seed(rnd, sizeof(rnd)); |
759 | bzero(rnd, sizeof(rnd)); | 765 | explicit_bzero(rnd, sizeof(rnd)); |
760 | 766 | ||
761 | /* Drop privileges */ | 767 | /* Drop privileges */ |
762 | do_setusercontext(authctxt->pw); | 768 | do_setusercontext(authctxt->pw); |
@@ -1355,7 +1361,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s) | |||
1355 | arc4random_stir(); | 1361 | arc4random_stir(); |
1356 | arc4random_buf(rnd, sizeof(rnd)); | 1362 | arc4random_buf(rnd, sizeof(rnd)); |
1357 | RAND_seed(rnd, sizeof(rnd)); | 1363 | RAND_seed(rnd, sizeof(rnd)); |
1358 | bzero(rnd, sizeof(rnd)); | 1364 | explicit_bzero(rnd, sizeof(rnd)); |
1359 | } | 1365 | } |
1360 | 1366 | ||
1361 | /* child process check (or debug mode) */ | 1367 | /* child process check (or debug mode) */ |
@@ -1657,7 +1663,8 @@ main(int ac, char **av) | |||
1657 | fatal("Privilege separation user %s does not exist", | 1663 | fatal("Privilege separation user %s does not exist", |
1658 | SSH_PRIVSEP_USER); | 1664 | SSH_PRIVSEP_USER); |
1659 | } else { | 1665 | } else { |
1660 | memset(privsep_pw->pw_passwd, 0, strlen(privsep_pw->pw_passwd)); | 1666 | explicit_bzero(privsep_pw->pw_passwd, |
1667 | strlen(privsep_pw->pw_passwd)); | ||
1661 | privsep_pw = pwcopy(privsep_pw); | 1668 | privsep_pw = pwcopy(privsep_pw); |
1662 | free(privsep_pw->pw_passwd); | 1669 | free(privsep_pw->pw_passwd); |
1663 | privsep_pw->pw_passwd = xstrdup("*"); | 1670 | privsep_pw->pw_passwd = xstrdup("*"); |
@@ -2341,7 +2348,7 @@ do_ssh1_kex(void) | |||
2341 | get_remote_ipaddr(), len, (u_long)sizeof(session_key)); | 2348 | get_remote_ipaddr(), len, (u_long)sizeof(session_key)); |
2342 | rsafail++; | 2349 | rsafail++; |
2343 | } else { | 2350 | } else { |
2344 | memset(session_key, 0, sizeof(session_key)); | 2351 | explicit_bzero(session_key, sizeof(session_key)); |
2345 | BN_bn2bin(session_key_int, | 2352 | BN_bn2bin(session_key_int, |
2346 | session_key + sizeof(session_key) - len); | 2353 | session_key + sizeof(session_key) - len); |
2347 | 2354 | ||
@@ -2360,20 +2367,26 @@ do_ssh1_kex(void) | |||
2360 | if (rsafail) { | 2367 | if (rsafail) { |
2361 | int bytes = BN_num_bytes(session_key_int); | 2368 | int bytes = BN_num_bytes(session_key_int); |
2362 | u_char *buf = xmalloc(bytes); | 2369 | u_char *buf = xmalloc(bytes); |
2363 | MD5_CTX md; | 2370 | struct ssh_digest_ctx *md; |
2364 | 2371 | ||
2365 | logit("do_connection: generating a fake encryption key"); | 2372 | logit("do_connection: generating a fake encryption key"); |
2366 | BN_bn2bin(session_key_int, buf); | 2373 | BN_bn2bin(session_key_int, buf); |
2367 | MD5_Init(&md); | 2374 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
2368 | MD5_Update(&md, buf, bytes); | 2375 | ssh_digest_update(md, buf, bytes) < 0 || |
2369 | MD5_Update(&md, sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); | 2376 | ssh_digest_update(md, sensitive_data.ssh1_cookie, |
2370 | MD5_Final(session_key, &md); | 2377 | SSH_SESSION_KEY_LENGTH) < 0 || |
2371 | MD5_Init(&md); | 2378 | ssh_digest_final(md, session_key, sizeof(session_key)) < 0) |
2372 | MD5_Update(&md, session_key, 16); | 2379 | fatal("%s: md5 failed", __func__); |
2373 | MD5_Update(&md, buf, bytes); | 2380 | ssh_digest_free(md); |
2374 | MD5_Update(&md, sensitive_data.ssh1_cookie, SSH_SESSION_KEY_LENGTH); | 2381 | if ((md = ssh_digest_start(SSH_DIGEST_MD5)) == NULL || |
2375 | MD5_Final(session_key + 16, &md); | 2382 | ssh_digest_update(md, session_key, 16) < 0 || |
2376 | memset(buf, 0, bytes); | 2383 | ssh_digest_update(md, sensitive_data.ssh1_cookie, |
2384 | SSH_SESSION_KEY_LENGTH) < 0 || | ||
2385 | ssh_digest_final(md, session_key + 16, | ||
2386 | sizeof(session_key) - 16) < 0) | ||
2387 | fatal("%s: md5 failed", __func__); | ||
2388 | ssh_digest_free(md); | ||
2389 | explicit_bzero(buf, bytes); | ||
2377 | free(buf); | 2390 | free(buf); |
2378 | for (i = 0; i < 16; i++) | 2391 | for (i = 0; i < 16; i++) |
2379 | session_id[i] = session_key[i] ^ session_key[i + 16]; | 2392 | session_id[i] = session_key[i] ^ session_key[i + 16]; |
@@ -2391,7 +2404,7 @@ do_ssh1_kex(void) | |||
2391 | packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type); | 2404 | packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, cipher_type); |
2392 | 2405 | ||
2393 | /* Destroy our copy of the session key. It is no longer needed. */ | 2406 | /* Destroy our copy of the session key. It is no longer needed. */ |
2394 | memset(session_key, 0, sizeof(session_key)); | 2407 | explicit_bzero(session_key, sizeof(session_key)); |
2395 | 2408 | ||
2396 | debug("Received session key; encryption turned on."); | 2409 | debug("Received session key; encryption turned on."); |
2397 | 2410 | ||