|
Lines 106-111
Link Here
|
| 106 |
#include "canohost.h" |
106 |
#include "canohost.h" |
| 107 |
#include "hostfile.h" |
107 |
#include "hostfile.h" |
| 108 |
#include "auth.h" |
108 |
#include "auth.h" |
|
|
109 |
#include "authfd.h" |
| 109 |
#include "misc.h" |
110 |
#include "misc.h" |
| 110 |
#include "msg.h" |
111 |
#include "msg.h" |
| 111 |
#include "dispatch.h" |
112 |
#include "dispatch.h" |
|
Lines 194-199
char *server_version_string = NULL;
Link Here
|
| 194 |
/* for rekeying XXX fixme */ |
195 |
/* for rekeying XXX fixme */ |
| 195 |
Kex *xxx_kex; |
196 |
Kex *xxx_kex; |
| 196 |
|
197 |
|
|
|
198 |
/* Daemon's agent connection */ |
| 199 |
AuthenticationConnection *auth_conn = NULL; |
| 200 |
|
| 197 |
/* |
201 |
/* |
| 198 |
* Any really sensitive data in the application is contained in this |
202 |
* Any really sensitive data in the application is contained in this |
| 199 |
* structure. The idea is that this structure could be locked into memory so |
203 |
* structure. The idea is that this structure could be locked into memory so |
|
Lines 206-211
struct {
Link Here
|
| 206 |
Key *server_key; /* ephemeral server key */ |
210 |
Key *server_key; /* ephemeral server key */ |
| 207 |
Key *ssh1_host_key; /* ssh1 host key */ |
211 |
Key *ssh1_host_key; /* ssh1 host key */ |
| 208 |
Key **host_keys; /* all private host keys */ |
212 |
Key **host_keys; /* all private host keys */ |
|
|
213 |
Key **host_pubkeys; /* all public host keys */ |
| 209 |
Key **host_certificates; /* all public host certificates */ |
214 |
Key **host_certificates; /* all public host certificates */ |
| 210 |
int have_ssh1_key; |
215 |
int have_ssh1_key; |
| 211 |
int have_ssh2_key; |
216 |
int have_ssh2_key; |
|
Lines 652-662
privsep_preauth(Authctxt *authctxt)
Link Here
|
| 652 |
} else if (pid != 0) { |
657 |
} else if (pid != 0) { |
| 653 |
debug2("Network child is on pid %ld", (long)pid); |
658 |
debug2("Network child is on pid %ld", (long)pid); |
| 654 |
|
659 |
|
|
|
660 |
auth_conn = ssh_get_authentication_connection(); |
| 661 |
|
| 655 |
pmonitor->m_pid = pid; |
662 |
pmonitor->m_pid = pid; |
| 656 |
if (box != NULL) |
663 |
if (box != NULL) |
| 657 |
ssh_sandbox_parent_preauth(box, pid); |
664 |
ssh_sandbox_parent_preauth(box, pid); |
| 658 |
monitor_child_preauth(authctxt, pmonitor); |
665 |
monitor_child_preauth(authctxt, pmonitor); |
| 659 |
|
666 |
|
|
|
667 |
if (auth_conn) { |
| 668 |
ssh_close_authentication_connection(auth_conn); |
| 669 |
auth_conn = NULL; |
| 670 |
} |
| 671 |
|
| 660 |
/* Sync memory */ |
672 |
/* Sync memory */ |
| 661 |
monitor_sync(pmonitor); |
673 |
monitor_sync(pmonitor); |
| 662 |
|
674 |
|
|
Lines 704-713
privsep_postauth(Authctxt *authctxt)
Link Here
|
| 704 |
u_int32_t rnd[256]; |
716 |
u_int32_t rnd[256]; |
| 705 |
|
717 |
|
| 706 |
#ifdef DISABLE_FD_PASSING |
718 |
#ifdef DISABLE_FD_PASSING |
| 707 |
if (1) { |
719 |
if (1) |
| 708 |
#else |
720 |
#else |
| 709 |
if (authctxt->pw->pw_uid == 0 || options.use_login) { |
721 |
if (authctxt->pw->pw_uid == 0 || options.use_login) |
| 710 |
#endif |
722 |
#endif |
|
|
723 |
{ |
| 711 |
/* File descriptor passing is broken or root login */ |
724 |
/* File descriptor passing is broken or root login */ |
| 712 |
use_privsep = 0; |
725 |
use_privsep = 0; |
| 713 |
goto skip; |
726 |
goto skip; |
|
Lines 767-772
list_hostkey_types(void)
Link Here
|
| 767 |
for (i = 0; i < options.num_host_key_files; i++) { |
780 |
for (i = 0; i < options.num_host_key_files; i++) { |
| 768 |
key = sensitive_data.host_keys[i]; |
781 |
key = sensitive_data.host_keys[i]; |
| 769 |
if (key == NULL) |
782 |
if (key == NULL) |
|
|
783 |
key = sensitive_data.host_pubkeys[i]; |
| 784 |
if (key == NULL) |
| 770 |
continue; |
785 |
continue; |
| 771 |
switch (key->type) { |
786 |
switch (key->type) { |
| 772 |
case KEY_RSA: |
787 |
case KEY_RSA: |
|
Lines 819-824
get_hostkey_by_type(int type, int need_private)
Link Here
|
| 819 |
break; |
834 |
break; |
| 820 |
default: |
835 |
default: |
| 821 |
key = sensitive_data.host_keys[i]; |
836 |
key = sensitive_data.host_keys[i]; |
|
|
837 |
if (key == NULL && !need_private) |
| 838 |
key = sensitive_data.host_pubkeys[i]; |
| 822 |
break; |
839 |
break; |
| 823 |
} |
840 |
} |
| 824 |
if (key != NULL && key->type == type) |
841 |
if (key != NULL && key->type == type) |
|
Lines 848-853
get_hostkey_by_index(int ind)
Link Here
|
| 848 |
return (sensitive_data.host_keys[ind]); |
865 |
return (sensitive_data.host_keys[ind]); |
| 849 |
} |
866 |
} |
| 850 |
|
867 |
|
|
|
868 |
Key * |
| 869 |
get_hostkey_public_by_index(int ind) |
| 870 |
{ |
| 871 |
if (ind < 0 || ind >= options.num_host_key_files) |
| 872 |
return (NULL); |
| 873 |
return (sensitive_data.host_pubkeys[ind]); |
| 874 |
} |
| 875 |
|
| 851 |
int |
876 |
int |
| 852 |
get_hostkey_index(Key *key) |
877 |
get_hostkey_index(Key *key) |
| 853 |
{ |
878 |
{ |
|
Lines 860-865
get_hostkey_index(Key *key)
Link Here
|
| 860 |
} else { |
885 |
} else { |
| 861 |
if (key == sensitive_data.host_keys[i]) |
886 |
if (key == sensitive_data.host_keys[i]) |
| 862 |
return (i); |
887 |
return (i); |
|
|
888 |
if (key == sensitive_data.host_pubkeys[i]) |
| 889 |
return (i); |
| 863 |
} |
890 |
} |
| 864 |
} |
891 |
} |
| 865 |
return (-1); |
892 |
return (-1); |
|
Lines 1344-1349
main(int ac, char **av)
Link Here
|
| 1344 |
u_int64_t ibytes, obytes; |
1371 |
u_int64_t ibytes, obytes; |
| 1345 |
mode_t new_umask; |
1372 |
mode_t new_umask; |
| 1346 |
Key *key; |
1373 |
Key *key; |
|
|
1374 |
Key *pubkey; |
| 1375 |
char *pubkey_comment; |
| 1376 |
int have_agent, keytype; |
| 1347 |
Authctxt *authctxt; |
1377 |
Authctxt *authctxt; |
| 1348 |
struct connection_info *connection_info = get_connection_info(0, 0); |
1378 |
struct connection_info *connection_info = get_connection_info(0, 0); |
| 1349 |
|
1379 |
|
|
Lines 1623-1644
main(int ac, char **av)
Link Here
|
| 1623 |
} |
1653 |
} |
| 1624 |
endpwent(); |
1654 |
endpwent(); |
| 1625 |
|
1655 |
|
| 1626 |
/* load private host keys */ |
1656 |
/* load host keys */ |
| 1627 |
sensitive_data.host_keys = xcalloc(options.num_host_key_files, |
1657 |
sensitive_data.host_keys = xcalloc(options.num_host_key_files, |
| 1628 |
sizeof(Key *)); |
1658 |
sizeof(Key *)); |
| 1629 |
for (i = 0; i < options.num_host_key_files; i++) |
1659 |
sensitive_data.host_pubkeys = xcalloc(options.num_host_key_files, |
|
|
1660 |
sizeof(Key *)); |
| 1661 |
for (i = 0; i < options.num_host_key_files; i++) { |
| 1630 |
sensitive_data.host_keys[i] = NULL; |
1662 |
sensitive_data.host_keys[i] = NULL; |
|
|
1663 |
sensitive_data.host_pubkeys[i] = NULL; |
| 1664 |
} |
| 1665 |
|
| 1666 |
have_agent = ssh_agent_present(); |
| 1631 |
|
1667 |
|
| 1632 |
for (i = 0; i < options.num_host_key_files; i++) { |
1668 |
for (i = 0; i < options.num_host_key_files; i++) { |
| 1633 |
key = key_load_private(options.host_key_files[i], "", NULL); |
1669 |
key = key_load_private(options.host_key_files[i], "", NULL); |
|
|
1670 |
pubkey = key_load_public(options.host_key_files[i], |
| 1671 |
&pubkey_comment); |
| 1634 |
sensitive_data.host_keys[i] = key; |
1672 |
sensitive_data.host_keys[i] = key; |
| 1635 |
if (key == NULL) { |
1673 |
sensitive_data.host_pubkeys[i] = pubkey; |
|
|
1674 |
|
| 1675 |
if (key == NULL && pubkey != NULL && pubkey->type != KEY_RSA1 && |
| 1676 |
have_agent) { |
| 1677 |
debug("will rely on agent for hostkey %s", |
| 1678 |
options.host_key_files[i]); |
| 1679 |
keytype = pubkey->type; |
| 1680 |
} else if (key == NULL) { |
| 1636 |
error("Could not load host key: %s", |
1681 |
error("Could not load host key: %s", |
| 1637 |
options.host_key_files[i]); |
1682 |
options.host_key_files[i]); |
| 1638 |
sensitive_data.host_keys[i] = NULL; |
1683 |
sensitive_data.host_keys[i] = NULL; |
|
|
1684 |
sensitive_data.host_pubkeys[i] = NULL; |
| 1639 |
continue; |
1685 |
continue; |
| 1640 |
} |
1686 |
} else |
| 1641 |
switch (key->type) { |
1687 |
keytype = key->type; |
|
|
1688 |
|
| 1689 |
switch (keytype) { |
| 1642 |
case KEY_RSA1: |
1690 |
case KEY_RSA1: |
| 1643 |
sensitive_data.ssh1_host_key = key; |
1691 |
sensitive_data.ssh1_host_key = key; |
| 1644 |
sensitive_data.have_ssh1_key = 1; |
1692 |
sensitive_data.have_ssh1_key = 1; |
|
Lines 1649-1656
main(int ac, char **av)
Link Here
|
| 1649 |
sensitive_data.have_ssh2_key = 1; |
1697 |
sensitive_data.have_ssh2_key = 1; |
| 1650 |
break; |
1698 |
break; |
| 1651 |
} |
1699 |
} |
| 1652 |
debug("private host key: #%d type %d %s", i, key->type, |
1700 |
debug("private host key: #%d type %d %s", i, keytype, |
| 1653 |
key_type(key)); |
1701 |
key_type(key ? key : pubkey)); |
| 1654 |
} |
1702 |
} |
| 1655 |
if ((options.protocol & SSH_PROTO_1) && !sensitive_data.have_ssh1_key) { |
1703 |
if ((options.protocol & SSH_PROTO_1) && !sensitive_data.have_ssh1_key) { |
| 1656 |
logit("Disabling protocol version 1. Could not load host key"); |
1704 |
logit("Disabling protocol version 1. Could not load host key"); |
|
Lines 2020-2034
main(int ac, char **av)
Link Here
|
| 2020 |
buffer_init(&loginmsg); |
2068 |
buffer_init(&loginmsg); |
| 2021 |
auth_debug_reset(); |
2069 |
auth_debug_reset(); |
| 2022 |
|
2070 |
|
| 2023 |
if (use_privsep) |
2071 |
if (use_privsep) { |
| 2024 |
if (privsep_preauth(authctxt) == 1) |
2072 |
if (privsep_preauth(authctxt) == 1) |
| 2025 |
goto authenticated; |
2073 |
goto authenticated; |
|
|
2074 |
} else if (compat20) |
| 2075 |
auth_conn = ssh_get_authentication_connection(); |
| 2026 |
|
2076 |
|
| 2027 |
/* perform the key exchange */ |
2077 |
/* perform the key exchange */ |
| 2028 |
/* authenticate user and start session */ |
2078 |
/* authenticate user and start session */ |
| 2029 |
if (compat20) { |
2079 |
if (compat20) { |
| 2030 |
do_ssh2_kex(); |
2080 |
do_ssh2_kex(); |
| 2031 |
do_authentication2(authctxt); |
2081 |
do_authentication2(authctxt); |
|
|
2082 |
if (!use_privsep && auth_conn) { |
| 2083 |
ssh_close_authentication_connection(auth_conn); |
| 2084 |
auth_conn = NULL; |
| 2085 |
} |
| 2032 |
} else { |
2086 |
} else { |
| 2033 |
do_ssh1_kex(); |
2087 |
do_ssh1_kex(); |
| 2034 |
do_authentication(authctxt); |
2088 |
do_authentication(authctxt); |
|
Lines 2336-2341
do_ssh1_kex(void)
Link Here
|
| 2336 |
packet_write_wait(); |
2390 |
packet_write_wait(); |
| 2337 |
} |
2391 |
} |
| 2338 |
|
2392 |
|
|
|
2393 |
static void |
| 2394 |
kex_server_sign(Key *privkey, Key *pubkey, u_char **signature, u_int *slen, |
| 2395 |
u_char *data, u_int dlen) |
| 2396 |
{ |
| 2397 |
if (privkey) { |
| 2398 |
if (PRIVSEP(key_sign(privkey, signature, slen, data, dlen) < 0)) |
| 2399 |
fatal("%s: key_sign failed", __func__); |
| 2400 |
} else if (use_privsep) { |
| 2401 |
if (mm_key_sign(pubkey, signature, slen, data, dlen) < 0) |
| 2402 |
fatal("%s: pubkey_sign failed", __func__); |
| 2403 |
} else { |
| 2404 |
if (ssh_agent_sign(auth_conn, pubkey, signature, slen, data, |
| 2405 |
dlen)) |
| 2406 |
fatal("%s: ssh_agent_sign failed", __func__); |
| 2407 |
} |
| 2408 |
} |
| 2409 |
|
| 2339 |
/* |
2410 |
/* |
| 2340 |
* SSH2 key exchange: diffie-hellman-group1-sha1 |
2411 |
* SSH2 key exchange: diffie-hellman-group1-sha1 |
| 2341 |
*/ |
2412 |
*/ |
|
Lines 2386-2391
do_ssh2_kex(void)
Link Here
|
| 2386 |
kex->load_host_public_key=&get_hostkey_public_by_type; |
2457 |
kex->load_host_public_key=&get_hostkey_public_by_type; |
| 2387 |
kex->load_host_private_key=&get_hostkey_private_by_type; |
2458 |
kex->load_host_private_key=&get_hostkey_private_by_type; |
| 2388 |
kex->host_key_index=&get_hostkey_index; |
2459 |
kex->host_key_index=&get_hostkey_index; |
|
|
2460 |
kex->sign = kex_server_sign; |
| 2389 |
|
2461 |
|
| 2390 |
xxx_kex = kex; |
2462 |
xxx_kex = kex; |
| 2391 |
|
2463 |
|