View | Details | Raw Unified | Return to bug 1974 | Differences between
and this patch

Collapse All | Expand All

(-)a/auth.h (+1 lines)
Lines 197-202 check_key_in_hostfiles(struct passwd *, Key *, const char *, Link Here
197
197
198
/* hostkey handling */
198
/* hostkey handling */
199
Key	*get_hostkey_by_index(int);
199
Key	*get_hostkey_by_index(int);
200
Key	*get_hostkey_public_by_index(int);
200
Key	*get_hostkey_public_by_type(int);
201
Key	*get_hostkey_public_by_type(int);
201
Key	*get_hostkey_private_by_type(int);
202
Key	*get_hostkey_private_by_type(int);
202
int	 get_hostkey_index(Key *);
203
int	 get_hostkey_index(Key *);
(-)a/kex.h (+1 lines)
Lines 139-144 struct Kex { Link Here
139
	Key	*(*load_host_public_key)(int);
139
	Key	*(*load_host_public_key)(int);
140
	Key	*(*load_host_private_key)(int);
140
	Key	*(*load_host_private_key)(int);
141
	int	(*host_key_index)(Key *);
141
	int	(*host_key_index)(Key *);
142
	void    (*sign)(Key *, Key *, u_char **, u_int *, u_char *, u_int);
142
	void	(*kex[KEX_MAX])(Kex *);
143
	void	(*kex[KEX_MAX])(Kex *);
143
};
144
};
144
145
(-)a/kexdhs.c (-6 / +2 lines)
Lines 80-88 kexdh_server(Kex *kex) Link Here
80
	if (server_host_public == NULL)
80
	if (server_host_public == NULL)
81
		fatal("Unsupported hostkey type %d", kex->hostkey_type);
81
		fatal("Unsupported hostkey type %d", kex->hostkey_type);
82
	server_host_private = kex->load_host_private_key(kex->hostkey_type);
82
	server_host_private = kex->load_host_private_key(kex->hostkey_type);
83
	if (server_host_private == NULL)
84
		fatal("Missing private key for hostkey type %d",
85
		    kex->hostkey_type);
86
83
87
	/* key, cert */
84
	/* key, cert */
88
	if ((dh_client_pub = BN_new()) == NULL)
85
	if ((dh_client_pub = BN_new()) == NULL)
Lines 144-152 kexdh_server(Kex *kex) Link Here
144
	}
141
	}
145
142
146
	/* sign H */
143
	/* sign H */
147
	if (PRIVSEP(key_sign(server_host_private, &signature, &slen, hash,
144
	kex->sign(server_host_private, server_host_public, &signature, &slen,
148
	    hashlen)) < 0)
145
	    hash, hashlen);
149
		fatal("kexdh_server: key_sign failed");
150
146
151
	/* destroy_sensitive_data(); */
147
	/* destroy_sensitive_data(); */
152
148
(-)a/kexecdhs.c (-6 / +2 lines)
Lines 78-86 kexecdh_server(Kex *kex) Link Here
78
	if (server_host_public == NULL)
78
	if (server_host_public == NULL)
79
		fatal("Unsupported hostkey type %d", kex->hostkey_type);
79
		fatal("Unsupported hostkey type %d", kex->hostkey_type);
80
	server_host_private = kex->load_host_private_key(kex->hostkey_type);
80
	server_host_private = kex->load_host_private_key(kex->hostkey_type);
81
	if (server_host_private == NULL)
82
		fatal("Missing private key for hostkey type %d",
83
		    kex->hostkey_type);
84
81
85
	debug("expecting SSH2_MSG_KEX_ECDH_INIT");
82
	debug("expecting SSH2_MSG_KEX_ECDH_INIT");
86
	packet_read_expect(SSH2_MSG_KEX_ECDH_INIT);
83
	packet_read_expect(SSH2_MSG_KEX_ECDH_INIT);
Lines 139-147 kexecdh_server(Kex *kex) Link Here
139
	}
136
	}
140
137
141
	/* sign H */
138
	/* sign H */
142
	if (PRIVSEP(key_sign(server_host_private, &signature, &slen,
139
	kex->sign(server_host_private, server_host_public, &signature, &slen,
143
	    hash, hashlen)) < 0)
140
	    hash, hashlen);
144
		fatal("kexdh_server: key_sign failed");
145
141
146
	/* destroy_sensitive_data(); */
142
	/* destroy_sensitive_data(); */
147
143
(-)a/kexgexs.c (-7 / +2 lines)
Lines 68-77 kexgex_server(Kex *kex) Link Here
68
	if (server_host_public == NULL)
68
	if (server_host_public == NULL)
69
		fatal("Unsupported hostkey type %d", kex->hostkey_type);
69
		fatal("Unsupported hostkey type %d", kex->hostkey_type);
70
	server_host_private = kex->load_host_private_key(kex->hostkey_type);
70
	server_host_private = kex->load_host_private_key(kex->hostkey_type);
71
	if (server_host_private == NULL)
72
		fatal("Missing private key for hostkey type %d",
73
		    kex->hostkey_type);
74
75
71
76
	type = packet_read();
72
	type = packet_read();
77
	switch (type) {
73
	switch (type) {
Lines 187-195 kexgex_server(Kex *kex) Link Here
187
	}
183
	}
188
184
189
	/* sign H */
185
	/* sign H */
190
	if (PRIVSEP(key_sign(server_host_private, &signature, &slen, hash,
186
	kex->sign(server_host_private, server_host_public, &signature, &slen,
191
	    hashlen)) < 0)
187
	    hash, hashlen);
192
		fatal("kexgex_server: key_sign failed");
193
188
194
	/* destroy_sensitive_data(); */
189
	/* destroy_sensitive_data(); */
195
190
(-)a/monitor.c (-3 / +12 lines)
Lines 97-102 Link Here
97
#include "ssh2.h"
97
#include "ssh2.h"
98
#include "jpake.h"
98
#include "jpake.h"
99
#include "roaming.h"
99
#include "roaming.h"
100
#include "authfd.h"
100
101
101
#ifdef GSSAPI
102
#ifdef GSSAPI
102
static Gssctxt *gsscontext = NULL;
103
static Gssctxt *gsscontext = NULL;
Lines 686-691 mm_answer_moduli(int sock, Buffer *m) Link Here
686
	return (0);
687
	return (0);
687
}
688
}
688
689
690
extern AuthenticationConnection *auth_conn;
691
689
int
692
int
690
mm_answer_sign(int sock, Buffer *m)
693
mm_answer_sign(int sock, Buffer *m)
691
{
694
{
Lines 714-723 mm_answer_sign(int sock, Buffer *m) Link Here
714
		memcpy(session_id2, p, session_id2_len);
717
		memcpy(session_id2, p, session_id2_len);
715
	}
718
	}
716
719
717
	if ((key = get_hostkey_by_index(keyid)) == NULL)
720
	if ((key = get_hostkey_by_index(keyid)) != NULL) {
721
		if (key_sign(key, &signature, &siglen, p, datlen) < 0)
722
			fatal("%s: key_sign failed", __func__);
723
	} else if ((key = get_hostkey_public_by_index(keyid)) != NULL &&
724
	    auth_conn != NULL) {
725
		if (ssh_agent_sign(auth_conn, key, &signature, &siglen, p,
726
		    datlen) < 0)
727
			fatal("%s: ssh_agent_sign failed", __func__);
728
	} else
718
		fatal("%s: no hostkey from index %d", __func__, keyid);
729
		fatal("%s: no hostkey from index %d", __func__, keyid);
719
	if (key_sign(key, &signature, &siglen, p, datlen) < 0)
720
		fatal("%s: key_sign failed", __func__);
721
730
722
	debug3("%s: signature %p(%u)", __func__, signature, siglen);
731
	debug3("%s: signature %p(%u)", __func__, signature, siglen);
723
732
(-)a/sshd.c (-10 / +82 lines)
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

Return to bug 1974