summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auth.h10
-rw-r--r--auth2-hostbased.c12
-rw-r--r--kex.h6
-rw-r--r--kexc25519s.c6
-rw-r--r--kexdhs.c6
-rw-r--r--kexecdhs.c6
-rw-r--r--kexgexs.c6
-rw-r--r--monitor.c8
-rw-r--r--monitor.h3
-rw-r--r--monitor_wrap.c15
-rw-r--r--monitor_wrap.h11
-rw-r--r--serverloop.c6
-rw-r--r--ssh.c5
-rw-r--r--ssh_api.c15
-rw-r--r--sshd.c63
15 files changed, 90 insertions, 88 deletions
diff --git a/auth.h b/auth.h
index 71c372e97..bf393e755 100644
--- a/auth.h
+++ b/auth.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth.h,v 1.98 2019/01/19 21:41:18 djm Exp $ */ 1/* $OpenBSD: auth.h,v 1.99 2019/01/19 21:43:56 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -132,8 +132,8 @@ auth_rhosts2(struct passwd *, const char *, const char *, const char *);
132 132
133int auth_password(struct ssh *, const char *); 133int auth_password(struct ssh *, const char *);
134 134
135int hostbased_key_allowed(struct passwd *, const char *, char *, 135int hostbased_key_allowed(struct ssh *, struct passwd *,
136 struct sshkey *); 136 const char *, char *, struct sshkey *);
137int user_key_allowed(struct ssh *, struct passwd *, struct sshkey *, int, 137int user_key_allowed(struct ssh *, struct passwd *, struct sshkey *, int,
138 struct sshauthopt **); 138 struct sshauthopt **);
139int auth2_key_already_used(Authctxt *, const struct sshkey *); 139int auth2_key_already_used(Authctxt *, const struct sshkey *);
@@ -208,8 +208,8 @@ struct sshkey *get_hostkey_public_by_index(int, struct ssh *);
208struct sshkey *get_hostkey_public_by_type(int, int, struct ssh *); 208struct sshkey *get_hostkey_public_by_type(int, int, struct ssh *);
209struct sshkey *get_hostkey_private_by_type(int, int, struct ssh *); 209struct sshkey *get_hostkey_private_by_type(int, int, struct ssh *);
210int get_hostkey_index(struct sshkey *, int, struct ssh *); 210int get_hostkey_index(struct sshkey *, int, struct ssh *);
211int sshd_hostkey_sign(struct sshkey *, struct sshkey *, u_char **, 211int sshd_hostkey_sign(struct ssh *, struct sshkey *, struct sshkey *,
212 size_t *, const u_char *, size_t, const char *, u_int); 212 u_char **, size_t *, const u_char *, size_t, const char *);
213 213
214/* Key / cert options linkage to auth layer */ 214/* Key / cert options linkage to auth layer */
215const struct sshauthopt *auth_options(struct ssh *); 215const struct sshauthopt *auth_options(struct ssh *);
diff --git a/auth2-hostbased.c b/auth2-hostbased.c
index e28a48fb3..0c40fad4e 100644
--- a/auth2-hostbased.c
+++ b/auth2-hostbased.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth2-hostbased.c,v 1.39 2019/01/19 21:31:32 djm Exp $ */ 1/* $OpenBSD: auth2-hostbased.c,v 1.40 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * 4 *
@@ -51,8 +51,6 @@
51#include "ssherr.h" 51#include "ssherr.h"
52#include "match.h" 52#include "match.h"
53 53
54extern struct ssh *active_state; /* XXX */
55
56/* import */ 54/* import */
57extern ServerOptions options; 55extern ServerOptions options;
58extern u_char *session_id2; 56extern u_char *session_id2;
@@ -149,7 +147,8 @@ userauth_hostbased(struct ssh *ssh)
149 147
150 /* test for allowed key and correct signature */ 148 /* test for allowed key and correct signature */
151 authenticated = 0; 149 authenticated = 0;
152 if (PRIVSEP(hostbased_key_allowed(authctxt->pw, cuser, chost, key)) && 150 if (PRIVSEP(hostbased_key_allowed(ssh, authctxt->pw, cuser,
151 chost, key)) &&
153 PRIVSEP(sshkey_verify(key, sig, slen, 152 PRIVSEP(sshkey_verify(key, sig, slen,
154 sshbuf_ptr(b), sshbuf_len(b), pkalg, ssh->compat)) == 0) 153 sshbuf_ptr(b), sshbuf_len(b), pkalg, ssh->compat)) == 0)
155 authenticated = 1; 154 authenticated = 1;
@@ -169,10 +168,9 @@ done:
169 168
170/* return 1 if given hostkey is allowed */ 169/* return 1 if given hostkey is allowed */
171int 170int
172hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost, 171hostbased_key_allowed(struct ssh *ssh, struct passwd *pw,
173 struct sshkey *key) 172 const char *cuser, char *chost, struct sshkey *key)
174{ 173{
175 struct ssh *ssh = active_state; /* XXX */
176 const char *resolvedname, *ipaddr, *lookup, *reason; 174 const char *resolvedname, *ipaddr, *lookup, *reason;
177 HostStatus host_status; 175 HostStatus host_status;
178 int len; 176 int len;
diff --git a/kex.h b/kex.h
index 9ba860954..085e60b52 100644
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.h,v 1.93 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: kex.h,v 1.94 2019/01/19 21:43:56 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -156,8 +156,8 @@ struct kex {
156 struct sshkey *(*load_host_public_key)(int, int, struct ssh *); 156 struct sshkey *(*load_host_public_key)(int, int, struct ssh *);
157 struct sshkey *(*load_host_private_key)(int, int, struct ssh *); 157 struct sshkey *(*load_host_private_key)(int, int, struct ssh *);
158 int (*host_key_index)(struct sshkey *, int, struct ssh *); 158 int (*host_key_index)(struct sshkey *, int, struct ssh *);
159 int (*sign)(struct sshkey *, struct sshkey *, u_char **, size_t *, 159 int (*sign)(struct ssh *, struct sshkey *, struct sshkey *,
160 const u_char *, size_t, const char *, u_int); 160 u_char **, size_t *, const u_char *, size_t, const char *);
161 int (*kex[KEX_MAX])(struct ssh *); 161 int (*kex[KEX_MAX])(struct ssh *);
162 /* kex specific state */ 162 /* kex specific state */
163 DH *dh; /* DH */ 163 DH *dh; /* DH */
diff --git a/kexc25519s.c b/kexc25519s.c
index 81f816e56..9ff74d912 100644
--- a/kexc25519s.c
+++ b/kexc25519s.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexc25519s.c,v 1.12 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: kexc25519s.c,v 1.13 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved. 4 * Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -133,8 +133,8 @@ input_kex_c25519_init(int type, u_int32_t seq, struct ssh *ssh)
133 } 133 }
134 134
135 /* sign H */ 135 /* sign H */
136 if ((r = kex->sign(server_host_private, server_host_public, &signature, 136 if ((r = kex->sign(ssh, server_host_private, server_host_public,
137 &slen, hash, hashlen, kex->hostkey_alg, ssh->compat)) < 0) 137 &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
138 goto out; 138 goto out;
139 139
140 /* send server hostkey, ECDH pubkey 'Q_S' and signed H */ 140 /* send server hostkey, ECDH pubkey 'Q_S' and signed H */
diff --git a/kexdhs.c b/kexdhs.c
index adf70babd..c8be1b2f7 100644
--- a/kexdhs.c
+++ b/kexdhs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexdhs.c,v 1.29 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: kexdhs.c,v 1.30 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -189,8 +189,8 @@ input_kex_dh_init(int type, u_int32_t seq, struct ssh *ssh)
189 } 189 }
190 190
191 /* sign H */ 191 /* sign H */
192 if ((r = kex->sign(server_host_private, server_host_public, &signature, 192 if ((r = kex->sign(ssh, server_host_private, server_host_public,
193 &slen, hash, hashlen, kex->hostkey_alg, ssh->compat)) < 0) 193 &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
194 goto out; 194 goto out;
195 195
196 /* destroy_sensitive_data(); */ 196 /* destroy_sensitive_data(); */
diff --git a/kexecdhs.c b/kexecdhs.c
index c690feffe..45ac3f794 100644
--- a/kexecdhs.c
+++ b/kexecdhs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexecdhs.c,v 1.18 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: kexecdhs.c,v 1.19 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved. 4 * Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -168,8 +168,8 @@ input_kex_ecdh_init(int type, u_int32_t seq, struct ssh *ssh)
168 } 168 }
169 169
170 /* sign H */ 170 /* sign H */
171 if ((r = kex->sign(server_host_private, server_host_public, &signature, 171 if ((r = kex->sign(ssh, server_host_private, server_host_public,
172 &slen, hash, hashlen, kex->hostkey_alg, ssh->compat)) < 0) 172 &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
173 goto out; 173 goto out;
174 174
175 /* destroy_sensitive_data(); */ 175 /* destroy_sensitive_data(); */
diff --git a/kexgexs.c b/kexgexs.c
index cd0e758c4..3b2ad37e4 100644
--- a/kexgexs.c
+++ b/kexgexs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexgexs.c,v 1.36 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: kexgexs.c,v 1.37 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -223,8 +223,8 @@ input_kex_dh_gex_init(int type, u_int32_t seq, struct ssh *ssh)
223 } 223 }
224 224
225 /* sign H */ 225 /* sign H */
226 if ((r = kex->sign(server_host_private, server_host_public, &signature, 226 if ((r = kex->sign(ssh, server_host_private, server_host_public,
227 &slen, hash, hashlen, kex->hostkey_alg, ssh->compat)) < 0) 227 &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
228 goto out; 228 goto out;
229 229
230 /* destroy_sensitive_data(); */ 230 /* destroy_sensitive_data(); */
diff --git a/monitor.c b/monitor.c
index 387b50026..1dcf930d4 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor.c,v 1.191 2019/01/19 21:43:07 djm Exp $ */ 1/* $OpenBSD: monitor.c,v 1.192 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2002 Markus Friedl <markus@openbsd.org> 4 * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -360,7 +360,7 @@ monitor_child_preauth(struct ssh *ssh, struct monitor *pmonitor)
360 ssh->authctxt = NULL; 360 ssh->authctxt = NULL;
361 ssh_packet_set_log_preamble(ssh, "user %s", authctxt->user); 361 ssh_packet_set_log_preamble(ssh, "user %s", authctxt->user);
362 362
363 mm_get_keystate(pmonitor); 363 mm_get_keystate(ssh, pmonitor);
364 364
365 /* Drain any buffered messages from the child */ 365 /* Drain any buffered messages from the child */
366 while (pmonitor->m_log_recvfd != -1 && monitor_read_log(pmonitor) == 0) 366 while (pmonitor->m_log_recvfd != -1 && monitor_read_log(pmonitor) == 0)
@@ -1195,7 +1195,7 @@ mm_answer_keyallowed(struct ssh *ssh, int sock, struct sshbuf *m)
1195 if (!key_base_type_match(auth_method, key, 1195 if (!key_base_type_match(auth_method, key,
1196 options.hostbased_key_types)) 1196 options.hostbased_key_types))
1197 break; 1197 break;
1198 allowed = hostbased_key_allowed(authctxt->pw, 1198 allowed = hostbased_key_allowed(ssh, authctxt->pw,
1199 cuser, chost, key); 1199 cuser, chost, key);
1200 auth2_record_info(authctxt, 1200 auth2_record_info(authctxt,
1201 "client user \"%.100s\", client host \"%.100s\"", 1201 "client user \"%.100s\", client host \"%.100s\"",
@@ -1699,7 +1699,7 @@ monitor_apply_keystate(struct ssh *ssh, struct monitor *pmonitor)
1699/* This function requries careful sanity checking */ 1699/* This function requries careful sanity checking */
1700 1700
1701void 1701void
1702mm_get_keystate(struct monitor *pmonitor) 1702mm_get_keystate(struct ssh *ssh, struct monitor *pmonitor)
1703{ 1703{
1704 debug3("%s: Waiting for new keys", __func__); 1704 debug3("%s: Waiting for new keys", __func__);
1705 1705
diff --git a/monitor.h b/monitor.h
index a4b68fbe2..683e5e071 100644
--- a/monitor.h
+++ b/monitor.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor.h,v 1.22 2019/01/19 21:43:07 djm Exp $ */ 1/* $OpenBSD: monitor.h,v 1.23 2019/01/19 21:43:56 djm Exp $ */
2 2
3/* 3/*
4 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 4 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
@@ -90,5 +90,6 @@ void monitor_apply_keystate(struct ssh *, struct monitor *);
90void mm_request_send(int, enum monitor_reqtype, struct sshbuf *); 90void mm_request_send(int, enum monitor_reqtype, struct sshbuf *);
91void mm_request_receive(int, struct sshbuf *); 91void mm_request_receive(int, struct sshbuf *);
92void mm_request_receive_expect(int, enum monitor_reqtype, struct sshbuf *); 92void mm_request_receive_expect(int, enum monitor_reqtype, struct sshbuf *);
93void mm_get_keystate(struct ssh *, struct monitor *);
93 94
94#endif /* _MONITOR_H_ */ 95#endif /* _MONITOR_H_ */
diff --git a/monitor_wrap.c b/monitor_wrap.c
index 4bdfd518e..5a0964b69 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor_wrap.c,v 1.110 2019/01/19 21:43:07 djm Exp $ */ 1/* $OpenBSD: monitor_wrap.c,v 1.111 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2002 Markus Friedl <markus@openbsd.org> 4 * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -76,8 +76,6 @@
76 76
77#include "ssherr.h" 77#include "ssherr.h"
78 78
79extern struct ssh *active_state; /* XXX */
80
81/* Imports */ 79/* Imports */
82extern struct monitor *pmonitor; 80extern struct monitor *pmonitor;
83extern struct sshbuf *loginmsg; 81extern struct sshbuf *loginmsg;
@@ -220,12 +218,12 @@ mm_choose_dh(int min, int nbits, int max)
220#endif 218#endif
221 219
222int 220int
223mm_sshkey_sign(struct sshkey *key, u_char **sigp, size_t *lenp, 221mm_sshkey_sign(struct ssh *ssh, struct sshkey *key, u_char **sigp, size_t *lenp,
224 const u_char *data, size_t datalen, const char *hostkey_alg, u_int compat) 222 const u_char *data, size_t datalen, const char *hostkey_alg, u_int compat)
225{ 223{
226 struct kex *kex = *pmonitor->m_pkex; 224 struct kex *kex = *pmonitor->m_pkex;
227 struct sshbuf *m; 225 struct sshbuf *m;
228 u_int ndx = kex->host_key_index(key, 0, active_state); 226 u_int ndx = kex->host_key_index(key, 0, ssh);
229 int r; 227 int r;
230 228
231 debug3("%s entering", __func__); 229 debug3("%s entering", __func__);
@@ -439,8 +437,8 @@ mm_user_key_allowed(struct ssh *ssh, struct passwd *pw, struct sshkey *key,
439} 437}
440 438
441int 439int
442mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host, 440mm_hostbased_key_allowed(struct ssh *ssh, struct passwd *pw,
443 struct sshkey *key) 441 const char *user, const char *host, struct sshkey *key)
444{ 442{
445 return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0, NULL)); 443 return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0, NULL));
446} 444}
@@ -533,9 +531,8 @@ mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
533} 531}
534 532
535void 533void
536mm_send_keystate(struct monitor *monitor) 534mm_send_keystate(struct ssh *ssh, struct monitor *monitor)
537{ 535{
538 struct ssh *ssh = active_state; /* XXX */
539 struct sshbuf *m; 536 struct sshbuf *m;
540 int r; 537 int r;
541 538
diff --git a/monitor_wrap.h b/monitor_wrap.h
index 8277cbf45..2b7052202 100644
--- a/monitor_wrap.h
+++ b/monitor_wrap.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor_wrap.h,v 1.40 2019/01/19 21:43:07 djm Exp $ */ 1/* $OpenBSD: monitor_wrap.h,v 1.41 2019/01/19 21:43:56 djm Exp $ */
2 2
3/* 3/*
4 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 4 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
@@ -42,8 +42,8 @@ struct sshauthopt;
42void mm_log_handler(LogLevel, const char *, void *); 42void mm_log_handler(LogLevel, const char *, void *);
43int mm_is_monitor(void); 43int mm_is_monitor(void);
44DH *mm_choose_dh(int, int, int); 44DH *mm_choose_dh(int, int, int);
45int mm_sshkey_sign(struct sshkey *, u_char **, size_t *, const u_char *, size_t, 45int mm_sshkey_sign(struct ssh *, struct sshkey *, u_char **, size_t *,
46 const char *, u_int compat); 46 const u_char *, size_t, const char *, u_int compat);
47void mm_inform_authserv(char *, char *); 47void mm_inform_authserv(char *, char *);
48struct passwd *mm_getpwnamallow(struct ssh *, const char *); 48struct passwd *mm_getpwnamallow(struct ssh *, const char *);
49char *mm_auth2_read_banner(void); 49char *mm_auth2_read_banner(void);
@@ -52,7 +52,7 @@ int mm_key_allowed(enum mm_keytype, const char *, const char *, struct sshkey *,
52 int, struct sshauthopt **); 52 int, struct sshauthopt **);
53int mm_user_key_allowed(struct ssh *, struct passwd *, struct sshkey *, int, 53int mm_user_key_allowed(struct ssh *, struct passwd *, struct sshkey *, int,
54 struct sshauthopt **); 54 struct sshauthopt **);
55int mm_hostbased_key_allowed(struct passwd *, const char *, 55int mm_hostbased_key_allowed(struct ssh *, struct passwd *, const char *,
56 const char *, struct sshkey *); 56 const char *, struct sshkey *);
57int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t, 57int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t,
58 const u_char *, size_t, const char *, u_int); 58 const u_char *, size_t, const char *, u_int);
@@ -89,8 +89,7 @@ void mm_session_pty_cleanup2(struct Session *);
89struct newkeys *mm_newkeys_from_blob(u_char *, int); 89struct newkeys *mm_newkeys_from_blob(u_char *, int);
90int mm_newkeys_to_blob(int, u_char **, u_int *); 90int mm_newkeys_to_blob(int, u_char **, u_int *);
91 91
92void mm_get_keystate(struct monitor *); 92void mm_send_keystate(struct ssh *, struct monitor*);
93void mm_send_keystate(struct monitor*);
94 93
95/* bsdauth */ 94/* bsdauth */
96int mm_bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); 95int mm_bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
diff --git a/serverloop.c b/serverloop.c
index c60758e88..afb32fd34 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: serverloop.c,v 1.211 2019/01/19 21:40:48 djm Exp $ */ 1/* $OpenBSD: serverloop.c,v 1.212 2019/01/19 21:43:56 djm 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
@@ -782,9 +782,9 @@ server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
782 (r = sshbuf_put_string(sigbuf, 782 (r = sshbuf_put_string(sigbuf,
783 ssh->kex->session_id, ssh->kex->session_id_len)) != 0 || 783 ssh->kex->session_id, ssh->kex->session_id_len)) != 0 ||
784 (r = sshkey_puts(key, sigbuf)) != 0 || 784 (r = sshkey_puts(key, sigbuf)) != 0 ||
785 (r = ssh->kex->sign(key_prv, key_pub, &sig, &slen, 785 (r = ssh->kex->sign(ssh, key_prv, key_pub, &sig, &slen,
786 sshbuf_ptr(sigbuf), sshbuf_len(sigbuf), 786 sshbuf_ptr(sigbuf), sshbuf_len(sigbuf),
787 use_kexsigtype ? ssh->kex->hostkey_alg : NULL, 0)) != 0 || 787 use_kexsigtype ? ssh->kex->hostkey_alg : NULL)) != 0 ||
788 (r = sshbuf_put_string(resp, sig, slen)) != 0) { 788 (r = sshbuf_put_string(resp, sig, slen)) != 0) {
789 error("%s: couldn't prepare signature: %s", 789 error("%s: couldn't prepare signature: %s",
790 __func__, ssh_err(r)); 790 __func__, ssh_err(r));
diff --git a/ssh.c b/ssh.c
index 160bf6b54..91e7c3511 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.499 2019/01/19 21:36:06 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.500 2019/01/19 21:43:56 djm 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
@@ -113,8 +113,6 @@
113#include "ssh-pkcs11.h" 113#include "ssh-pkcs11.h"
114#endif 114#endif
115 115
116extern struct ssh *active_state; /* XXX remove after sshconnect2.c updated */
117
118extern char *__progname; 116extern char *__progname;
119 117
120/* Saves a copy of argv for setproctitle emulation */ 118/* Saves a copy of argv for setproctitle emulation */
@@ -652,7 +650,6 @@ main(int ac, char **av)
652 */ 650 */
653 if ((ssh = ssh_alloc_session_state()) == NULL) 651 if ((ssh = ssh_alloc_session_state()) == NULL)
654 fatal("Couldn't allocate session state"); 652 fatal("Couldn't allocate session state");
655 active_state = ssh; /* XXX */
656 channel_init_channels(ssh); 653 channel_init_channels(ssh);
657 654
658 /* Parse command-line arguments. */ 655 /* Parse command-line arguments. */
diff --git a/ssh_api.c b/ssh_api.c
index ab209c4ca..182c0d7e4 100644
--- a/ssh_api.c
+++ b/ssh_api.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh_api.c,v 1.9 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: ssh_api.c,v 1.10 2019/01/19 21:43:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2012 Markus Friedl. All rights reserved. 3 * Copyright (c) 2012 Markus Friedl. All rights reserved.
4 * 4 *
@@ -40,8 +40,8 @@ int _ssh_order_hostkeyalgs(struct ssh *);
40int _ssh_verify_host_key(struct sshkey *, struct ssh *); 40int _ssh_verify_host_key(struct sshkey *, struct ssh *);
41struct sshkey *_ssh_host_public_key(int, int, struct ssh *); 41struct sshkey *_ssh_host_public_key(int, int, struct ssh *);
42struct sshkey *_ssh_host_private_key(int, int, struct ssh *); 42struct sshkey *_ssh_host_private_key(int, int, struct ssh *);
43int _ssh_host_key_sign(struct sshkey *, struct sshkey *, 43int _ssh_host_key_sign(struct ssh *, struct sshkey *, struct sshkey *,
44 u_char **, size_t *, const u_char *, size_t, const char *, u_int); 44 u_char **, size_t *, const u_char *, size_t, const char *);
45 45
46/* 46/*
47 * stubs for the server side implementation of kex. 47 * stubs for the server side implementation of kex.
@@ -547,9 +547,10 @@ _ssh_order_hostkeyalgs(struct ssh *ssh)
547} 547}
548 548
549int 549int
550_ssh_host_key_sign(struct sshkey *privkey, struct sshkey *pubkey, 550_ssh_host_key_sign(struct ssh *ssh, struct sshkey *privkey,
551 u_char **signature, size_t *slen, const u_char *data, size_t dlen, 551 struct sshkey *pubkey, u_char **signature, size_t *slen,
552 const char *alg, u_int compat) 552 const u_char *data, size_t dlen, const char *alg)
553{ 553{
554 return sshkey_sign(privkey, signature, slen, data, dlen, alg, compat); 554 return sshkey_sign(privkey, signature, slen, data, dlen,
555 alg, ssh->compat);
555} 556}
diff --git a/sshd.c b/sshd.c
index 0c93f7f31..58d17e546 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.526 2019/01/19 21:43:07 djm Exp $ */ 1/* $OpenBSD: sshd.c,v 1.527 2019/01/19 21:43:56 djm 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
@@ -123,8 +123,6 @@
123#include "version.h" 123#include "version.h"
124#include "ssherr.h" 124#include "ssherr.h"
125 125
126extern struct ssh *active_state; /* XXX move decl to this file */
127
128/* Re-exec fds */ 126/* Re-exec fds */
129#define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1) 127#define REEXEC_DEVCRYPTO_RESERVED_FD (STDERR_FILENO + 1)
130#define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2) 128#define REEXEC_STARTUP_PIPE_FD (STDERR_FILENO + 2)
@@ -225,8 +223,9 @@ struct monitor *pmonitor = NULL;
225int privsep_is_preauth = 1; 223int privsep_is_preauth = 1;
226static int privsep_chroot = 1; 224static int privsep_chroot = 1;
227 225
228/* global authentication context */ 226/* global connection state and authentication contexts */
229Authctxt *the_authctxt = NULL; 227Authctxt *the_authctxt = NULL;
228struct ssh *the_active_state;
230 229
231/* global key/cert auth options. XXX move to permanent ssh->authctxt? */ 230/* global key/cert auth options. XXX move to permanent ssh->authctxt? */
232struct sshauthopt *auth_opts = NULL; 231struct sshauthopt *auth_opts = NULL;
@@ -353,9 +352,11 @@ grace_alarm_handler(int sig)
353 kill(0, SIGTERM); 352 kill(0, SIGTERM);
354 } 353 }
355 354
355 /* XXX pre-format ipaddr/port so we don't need to access active_state */
356 /* Log error and exit. */ 356 /* Log error and exit. */
357 sigdie("Timeout before authentication for %s port %d", 357 sigdie("Timeout before authentication for %s port %d",
358 ssh_remote_ipaddr(active_state), ssh_remote_port(active_state)); 358 ssh_remote_ipaddr(the_active_state),
359 ssh_remote_port(the_active_state));
359} 360}
360 361
361/* Destroy the host and server keys. They will no longer be needed. */ 362/* Destroy the host and server keys. They will no longer be needed. */
@@ -742,7 +743,7 @@ notify_hostkeys(struct ssh *ssh)
742 char *fp; 743 char *fp;
743 744
744 /* Some clients cannot cope with the hostkeys message, skip those. */ 745 /* Some clients cannot cope with the hostkeys message, skip those. */
745 if (datafellows & SSH_BUG_HOSTKEYS) 746 if (ssh->compat & SSH_BUG_HOSTKEYS)
746 return; 747 return;
747 748
748 if ((buf = sshbuf_new()) == NULL) 749 if ((buf = sshbuf_new()) == NULL)
@@ -1960,8 +1961,8 @@ main(int ac, char **av)
1960 */ 1961 */
1961 if ((ssh = ssh_packet_set_connection(NULL, sock_in, sock_out)) == NULL) 1962 if ((ssh = ssh_packet_set_connection(NULL, sock_in, sock_out)) == NULL)
1962 fatal("Unable to create connection"); 1963 fatal("Unable to create connection");
1964 the_active_state = ssh;
1963 ssh_packet_set_server(ssh); 1965 ssh_packet_set_server(ssh);
1964 active_state = ssh; /* XXX needed elsewhere */
1965 1966
1966 check_ip_options(ssh); 1967 check_ip_options(ssh);
1967 1968
@@ -2060,7 +2061,7 @@ main(int ac, char **av)
2060 * the current keystate and exits 2061 * the current keystate and exits
2061 */ 2062 */
2062 if (use_privsep) { 2063 if (use_privsep) {
2063 mm_send_keystate(pmonitor); 2064 mm_send_keystate(ssh, pmonitor);
2064 ssh_packet_clear_keys(ssh); 2065 ssh_packet_clear_keys(ssh);
2065 exit(0); 2066 exit(0);
2066 } 2067 }
@@ -2139,25 +2140,35 @@ main(int ac, char **av)
2139} 2140}
2140 2141
2141int 2142int
2142sshd_hostkey_sign(struct sshkey *privkey, struct sshkey *pubkey, 2143sshd_hostkey_sign(struct ssh *ssh, struct sshkey *privkey,
2143 u_char **signature, size_t *slenp, const u_char *data, size_t dlen, 2144 struct sshkey *pubkey, u_char **signature, size_t *slenp,
2144 const char *alg, u_int flag) 2145 const u_char *data, size_t dlen, const char *alg)
2145{ 2146{
2146 int r; 2147 int r;
2147 2148
2148 if (privkey) { 2149 if (use_privsep) {
2149 if (PRIVSEP(sshkey_sign(privkey, signature, slenp, data, dlen, 2150 if (privkey) {
2150 alg, datafellows)) < 0) 2151 if (mm_sshkey_sign(ssh, privkey, signature, slenp,
2151 fatal("%s: key_sign failed", __func__); 2152 data, dlen, alg, ssh->compat) < 0)
2152 } else if (use_privsep) { 2153 fatal("%s: privkey sign failed", __func__);
2153 if (mm_sshkey_sign(pubkey, signature, slenp, data, dlen, 2154 } else {
2154 alg, datafellows) < 0) 2155 if (mm_sshkey_sign(ssh, pubkey, signature, slenp,
2155 fatal("%s: pubkey_sign failed", __func__); 2156 data, dlen, alg, ssh->compat) < 0)
2157 fatal("%s: pubkey sign failed", __func__);
2158 }
2156 } else { 2159 } else {
2157 if ((r = ssh_agent_sign(auth_sock, pubkey, signature, slenp, 2160 if (privkey) {
2158 data, dlen, alg, datafellows)) != 0) 2161 if (sshkey_sign(privkey, signature, slenp, data, dlen,
2159 fatal("%s: ssh_agent_sign failed: %s", 2162 alg, ssh->compat) < 0)
2160 __func__, ssh_err(r)); 2163 fatal("%s: privkey sign failed", __func__);
2164 } else {
2165 if ((r = ssh_agent_sign(auth_sock, pubkey,
2166 signature, slenp, data, dlen, alg,
2167 ssh->compat)) != 0) {
2168 fatal("%s: agent sign failed: %s",
2169 __func__, ssh_err(r));
2170 }
2171 }
2161 } 2172 }
2162 return 0; 2173 return 0;
2163} 2174}
@@ -2232,10 +2243,8 @@ do_ssh2_kex(struct ssh *ssh)
2232void 2243void
2233cleanup_exit(int i) 2244cleanup_exit(int i)
2234{ 2245{
2235 struct ssh *ssh = active_state; /* XXX */ 2246 if (the_active_state != NULL && the_authctxt != NULL) {
2236 2247 do_cleanup(the_active_state, the_authctxt);
2237 if (the_authctxt) {
2238 do_cleanup(ssh, the_authctxt);
2239 if (use_privsep && privsep_is_preauth && 2248 if (use_privsep && privsep_is_preauth &&
2240 pmonitor != NULL && pmonitor->m_pid > 1) { 2249 pmonitor != NULL && pmonitor->m_pid > 1) {
2241 debug("Killing privsep child %d", pmonitor->m_pid); 2250 debug("Killing privsep child %d", pmonitor->m_pid);