Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1 | /* $OpenBSD: monitor.c,v 1.100 2008/11/04 08:22:13 djm Exp $ */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
| 4 | * Copyright 2002 Markus Friedl <markus@openbsd.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "includes.h" |
Damien Miller | 9cf6d07 | 2006-03-15 11:29:24 +1100 | [diff] [blame] | 29 | |
| 30 | #include <sys/types.h> |
Damien Miller | 8dbffe7 | 2006-08-05 11:02:17 +1000 | [diff] [blame] | 31 | #include <sys/param.h> |
Damien Miller | e3b60b5 | 2006-07-10 21:08:03 +1000 | [diff] [blame] | 32 | #include <sys/socket.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 33 | #include "openbsd-compat/sys-tree.h" |
Damien Miller | 9cf6d07 | 2006-03-15 11:29:24 +1100 | [diff] [blame] | 34 | #include <sys/wait.h> |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 35 | |
Darren Tucker | 3997249 | 2006-07-12 22:22:46 +1000 | [diff] [blame] | 36 | #include <errno.h> |
Damien Miller | 57cf638 | 2006-07-10 21:13:46 +1000 | [diff] [blame] | 37 | #include <fcntl.h> |
Damien Miller | 6645e7a | 2006-03-15 14:42:54 +1100 | [diff] [blame] | 38 | #ifdef HAVE_PATHS_H |
Damien Miller | 03e2003 | 2006-03-15 11:16:59 +1100 | [diff] [blame] | 39 | #include <paths.h> |
Damien Miller | 6645e7a | 2006-03-15 14:42:54 +1100 | [diff] [blame] | 40 | #endif |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 41 | #include <pwd.h> |
Damien Miller | 6ff3cad | 2006-03-15 11:52:09 +1100 | [diff] [blame] | 42 | #include <signal.h> |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 43 | #include <stdarg.h> |
Damien Miller | e7a1e5c | 2006-08-05 11:34:19 +1000 | [diff] [blame] | 44 | #include <stdlib.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 45 | #include <string.h> |
Damien Miller | 607aede | 2006-09-01 15:48:19 +1000 | [diff] [blame] | 46 | #include <unistd.h> |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 47 | |
| 48 | #ifdef SKEY |
| 49 | #include <skey.h> |
| 50 | #endif |
| 51 | |
Damien Miller | 03e2003 | 2006-03-15 11:16:59 +1100 | [diff] [blame] | 52 | #include <openssl/dh.h> |
| 53 | |
Damien Miller | b84886b | 2008-05-19 15:05:07 +1000 | [diff] [blame] | 54 | #include "openbsd-compat/sys-queue.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 55 | #include "xmalloc.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 56 | #include "ssh.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 57 | #include "key.h" |
| 58 | #include "buffer.h" |
| 59 | #include "hostfile.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 60 | #include "auth.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 61 | #include "cipher.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 62 | #include "kex.h" |
| 63 | #include "dh.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 64 | #ifdef TARGET_OS_MAC /* XXX Broken krb5 headers on Mac */ |
| 65 | #undef TARGET_OS_MAC |
Ben Lindstrom | 1b9f2a6 | 2004-04-08 05:11:03 +0000 | [diff] [blame] | 66 | #include "zlib.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 67 | #define TARGET_OS_MAC 1 |
| 68 | #else |
| 69 | #include "zlib.h" |
| 70 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 71 | #include "packet.h" |
| 72 | #include "auth-options.h" |
| 73 | #include "sshpty.h" |
| 74 | #include "channels.h" |
| 75 | #include "session.h" |
| 76 | #include "sshlogin.h" |
| 77 | #include "canohost.h" |
| 78 | #include "log.h" |
| 79 | #include "servconf.h" |
| 80 | #include "monitor.h" |
| 81 | #include "monitor_mm.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 82 | #ifdef GSSAPI |
| 83 | #include "ssh-gss.h" |
| 84 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 85 | #include "monitor_wrap.h" |
| 86 | #include "monitor_fdpass.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 87 | #include "misc.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 88 | #include "compat.h" |
| 89 | #include "ssh2.h" |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 90 | #include "jpake.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 91 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 92 | #ifdef GSSAPI |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 93 | static Gssctxt *gsscontext = NULL; |
| 94 | #endif |
| 95 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 96 | /* Imports */ |
| 97 | extern ServerOptions options; |
| 98 | extern u_int utmp_len; |
| 99 | extern Newkeys *current_keys[]; |
| 100 | extern z_stream incoming_stream; |
| 101 | extern z_stream outgoing_stream; |
| 102 | extern u_char session_id[]; |
| 103 | extern Buffer input, output; |
| 104 | extern Buffer auth_debug; |
| 105 | extern int auth_debug_init; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 106 | extern Buffer loginmsg; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 107 | |
| 108 | /* State exported from the child */ |
| 109 | |
| 110 | struct { |
| 111 | z_stream incoming; |
| 112 | z_stream outgoing; |
| 113 | u_char *keyin; |
| 114 | u_int keyinlen; |
| 115 | u_char *keyout; |
| 116 | u_int keyoutlen; |
| 117 | u_char *ivin; |
| 118 | u_int ivinlen; |
| 119 | u_char *ivout; |
| 120 | u_int ivoutlen; |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 121 | u_char *ssh1key; |
| 122 | u_int ssh1keylen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 123 | int ssh1cipher; |
| 124 | int ssh1protoflags; |
| 125 | u_char *input; |
| 126 | u_int ilen; |
| 127 | u_char *output; |
| 128 | u_int olen; |
| 129 | } child_state; |
| 130 | |
Damien Miller | 469954d | 2003-06-18 20:25:33 +1000 | [diff] [blame] | 131 | /* Functions on the monitor that answer unprivileged requests */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 132 | |
| 133 | int mm_answer_moduli(int, Buffer *); |
| 134 | int mm_answer_sign(int, Buffer *); |
| 135 | int mm_answer_pwnamallow(int, Buffer *); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 136 | int mm_answer_auth2_read_banner(int, Buffer *); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 137 | int mm_answer_authserv(int, Buffer *); |
| 138 | int mm_answer_authpassword(int, Buffer *); |
| 139 | int mm_answer_bsdauthquery(int, Buffer *); |
| 140 | int mm_answer_bsdauthrespond(int, Buffer *); |
| 141 | int mm_answer_skeyquery(int, Buffer *); |
| 142 | int mm_answer_skeyrespond(int, Buffer *); |
| 143 | int mm_answer_keyallowed(int, Buffer *); |
| 144 | int mm_answer_keyverify(int, Buffer *); |
| 145 | int mm_answer_pty(int, Buffer *); |
| 146 | int mm_answer_pty_cleanup(int, Buffer *); |
| 147 | int mm_answer_term(int, Buffer *); |
| 148 | int mm_answer_rsa_keyallowed(int, Buffer *); |
| 149 | int mm_answer_rsa_challenge(int, Buffer *); |
| 150 | int mm_answer_rsa_response(int, Buffer *); |
| 151 | int mm_answer_sesskey(int, Buffer *); |
| 152 | int mm_answer_sessid(int, Buffer *); |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 153 | int mm_answer_jpake_get_pwdata(int, Buffer *); |
| 154 | int mm_answer_jpake_step1(int, Buffer *); |
| 155 | int mm_answer_jpake_step2(int, Buffer *); |
| 156 | int mm_answer_jpake_key_confirm(int, Buffer *); |
| 157 | int mm_answer_jpake_check_confirm(int, Buffer *); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 158 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 159 | #ifdef USE_PAM |
| 160 | int mm_answer_pam_start(int, Buffer *); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 161 | int mm_answer_pam_account(int, Buffer *); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 162 | int mm_answer_pam_init_ctx(int, Buffer *); |
| 163 | int mm_answer_pam_query(int, Buffer *); |
| 164 | int mm_answer_pam_respond(int, Buffer *); |
| 165 | int mm_answer_pam_free_ctx(int, Buffer *); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 166 | #endif |
| 167 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 168 | #ifdef GSSAPI |
| 169 | int mm_answer_gss_setup_ctx(int, Buffer *); |
| 170 | int mm_answer_gss_accept_ctx(int, Buffer *); |
| 171 | int mm_answer_gss_userok(int, Buffer *); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 172 | int mm_answer_gss_checkmic(int, Buffer *); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 173 | #endif |
Damien Miller | 25162f2 | 2002-09-12 09:47:29 +1000 | [diff] [blame] | 174 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 175 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 176 | int mm_answer_audit_event(int, Buffer *); |
| 177 | int mm_answer_audit_command(int, Buffer *); |
| 178 | #endif |
| 179 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 180 | static Authctxt *authctxt; |
| 181 | static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */ |
| 182 | |
| 183 | /* local state for key verify */ |
| 184 | static u_char *key_blob = NULL; |
| 185 | static u_int key_bloblen = 0; |
| 186 | static int key_blobtype = MM_NOKEY; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 187 | static char *hostbased_cuser = NULL; |
| 188 | static char *hostbased_chost = NULL; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 189 | static char *auth_method = "unknown"; |
Darren Tucker | 502d384 | 2003-06-28 12:38:01 +1000 | [diff] [blame] | 190 | static u_int session_id2_len = 0; |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 191 | static u_char *session_id2 = NULL; |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 192 | static pid_t monitor_child_pid; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 193 | |
| 194 | struct mon_table { |
| 195 | enum monitor_reqtype type; |
| 196 | int flags; |
| 197 | int (*f)(int, Buffer *); |
| 198 | }; |
| 199 | |
| 200 | #define MON_ISAUTH 0x0004 /* Required for Authentication */ |
| 201 | #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */ |
| 202 | #define MON_ONCE 0x0010 /* Disable after calling */ |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 203 | #define MON_ALOG 0x0020 /* Log auth attempt without authenticating */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 204 | |
| 205 | #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE) |
| 206 | |
| 207 | #define MON_PERMIT 0x1000 /* Request is permitted */ |
| 208 | |
| 209 | struct mon_table mon_dispatch_proto20[] = { |
| 210 | {MONITOR_REQ_MODULI, MON_ONCE, mm_answer_moduli}, |
| 211 | {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign}, |
| 212 | {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow}, |
| 213 | {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv}, |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 214 | {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner}, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 215 | {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword}, |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 216 | #ifdef USE_PAM |
| 217 | {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start}, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 218 | {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account}, |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 219 | {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx}, |
| 220 | {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query}, |
| 221 | {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond}, |
| 222 | {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx}, |
Kevin Steves | bd1901b | 2002-04-01 18:04:35 +0000 | [diff] [blame] | 223 | #endif |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 224 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 3745e2b | 2005-03-06 22:31:35 +1100 | [diff] [blame] | 225 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 226 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 227 | #ifdef BSD_AUTH |
| 228 | {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery}, |
Damien Miller | 0b70b54 | 2006-03-15 11:20:03 +1100 | [diff] [blame] | 229 | {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH, mm_answer_bsdauthrespond}, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 230 | #endif |
| 231 | #ifdef SKEY |
| 232 | {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery}, |
| 233 | {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond}, |
| 234 | #endif |
| 235 | {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed}, |
| 236 | {MONITOR_REQ_KEYVERIFY, MON_AUTH, mm_answer_keyverify}, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 237 | #ifdef GSSAPI |
| 238 | {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx}, |
| 239 | {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx}, |
| 240 | {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok}, |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 241 | {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic}, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 242 | #endif |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 243 | #ifdef JPAKE |
| 244 | {MONITOR_REQ_JPAKE_GET_PWDATA, MON_ONCE, mm_answer_jpake_get_pwdata}, |
| 245 | {MONITOR_REQ_JPAKE_STEP1, MON_ISAUTH, mm_answer_jpake_step1}, |
| 246 | {MONITOR_REQ_JPAKE_STEP2, MON_ONCE, mm_answer_jpake_step2}, |
| 247 | {MONITOR_REQ_JPAKE_KEY_CONFIRM, MON_ONCE, mm_answer_jpake_key_confirm}, |
| 248 | {MONITOR_REQ_JPAKE_CHECK_CONFIRM, MON_AUTH, mm_answer_jpake_check_confirm}, |
| 249 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 250 | {0, 0, NULL} |
| 251 | }; |
| 252 | |
| 253 | struct mon_table mon_dispatch_postauth20[] = { |
| 254 | {MONITOR_REQ_MODULI, 0, mm_answer_moduli}, |
| 255 | {MONITOR_REQ_SIGN, 0, mm_answer_sign}, |
| 256 | {MONITOR_REQ_PTY, 0, mm_answer_pty}, |
| 257 | {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup}, |
| 258 | {MONITOR_REQ_TERM, 0, mm_answer_term}, |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 259 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 260 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
| 261 | {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command}, |
| 262 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 263 | {0, 0, NULL} |
| 264 | }; |
| 265 | |
| 266 | struct mon_table mon_dispatch_proto15[] = { |
| 267 | {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow}, |
| 268 | {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey}, |
| 269 | {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid}, |
| 270 | {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword}, |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 271 | {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH|MON_ALOG, mm_answer_rsa_keyallowed}, |
| 272 | {MONITOR_REQ_KEYALLOWED, MON_ISAUTH|MON_ALOG, mm_answer_keyallowed}, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 273 | {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge}, |
| 274 | {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response}, |
| 275 | #ifdef BSD_AUTH |
| 276 | {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery}, |
Damien Miller | 0b70b54 | 2006-03-15 11:20:03 +1100 | [diff] [blame] | 277 | {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH, mm_answer_bsdauthrespond}, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 278 | #endif |
| 279 | #ifdef SKEY |
| 280 | {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery}, |
| 281 | {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond}, |
| 282 | #endif |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 283 | #ifdef USE_PAM |
| 284 | {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start}, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 285 | {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account}, |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 286 | {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx}, |
| 287 | {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query}, |
| 288 | {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond}, |
| 289 | {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx}, |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 290 | #endif |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 291 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 3745e2b | 2005-03-06 22:31:35 +1100 | [diff] [blame] | 292 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 293 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 294 | {0, 0, NULL} |
| 295 | }; |
| 296 | |
| 297 | struct mon_table mon_dispatch_postauth15[] = { |
| 298 | {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty}, |
| 299 | {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup}, |
| 300 | {MONITOR_REQ_TERM, 0, mm_answer_term}, |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 301 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 302 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
Darren Tucker | 5965ae1 | 2006-09-17 12:00:13 +1000 | [diff] [blame] | 303 | {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT|MON_ONCE, mm_answer_audit_command}, |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 304 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 305 | {0, 0, NULL} |
| 306 | }; |
| 307 | |
| 308 | struct mon_table *mon_dispatch; |
| 309 | |
| 310 | /* Specifies if a certain message is allowed at the moment */ |
| 311 | |
| 312 | static void |
| 313 | monitor_permit(struct mon_table *ent, enum monitor_reqtype type, int permit) |
| 314 | { |
| 315 | while (ent->f != NULL) { |
| 316 | if (ent->type == type) { |
| 317 | ent->flags &= ~MON_PERMIT; |
| 318 | ent->flags |= permit ? MON_PERMIT : 0; |
| 319 | return; |
| 320 | } |
| 321 | ent++; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | static void |
| 326 | monitor_permit_authentications(int permit) |
| 327 | { |
| 328 | struct mon_table *ent = mon_dispatch; |
| 329 | |
| 330 | while (ent->f != NULL) { |
| 331 | if (ent->flags & MON_AUTH) { |
| 332 | ent->flags &= ~MON_PERMIT; |
| 333 | ent->flags |= permit ? MON_PERMIT : 0; |
| 334 | } |
| 335 | ent++; |
| 336 | } |
| 337 | } |
| 338 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 339 | void |
| 340 | monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 341 | { |
| 342 | struct mon_table *ent; |
| 343 | int authenticated = 0; |
| 344 | |
| 345 | debug3("preauth child monitor started"); |
| 346 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 347 | authctxt = _authctxt; |
| 348 | memset(authctxt, 0, sizeof(*authctxt)); |
| 349 | |
Darren Tucker | de0de39 | 2005-03-31 23:52:04 +1000 | [diff] [blame] | 350 | authctxt->loginmsg = &loginmsg; |
| 351 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 352 | if (compat20) { |
| 353 | mon_dispatch = mon_dispatch_proto20; |
| 354 | |
| 355 | /* Permit requests for moduli and signatures */ |
| 356 | monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); |
| 357 | monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); |
| 358 | } else { |
| 359 | mon_dispatch = mon_dispatch_proto15; |
| 360 | |
| 361 | monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1); |
| 362 | } |
| 363 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 364 | /* The first few requests do not require asynchronous access */ |
| 365 | while (!authenticated) { |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 366 | auth_method = "unknown"; |
Darren Tucker | fbba735 | 2006-11-07 23:16:08 +1100 | [diff] [blame] | 367 | authenticated = (monitor_read(pmonitor, mon_dispatch, &ent) == 1); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 368 | if (authenticated) { |
| 369 | if (!(ent->flags & MON_AUTHDECIDE)) |
| 370 | fatal("%s: unexpected authentication from %d", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 371 | __func__, ent->type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 372 | if (authctxt->pw->pw_uid == 0 && |
| 373 | !auth_root_allowed(auth_method)) |
| 374 | authenticated = 0; |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 375 | #ifdef USE_PAM |
| 376 | /* PAM needs to perform account checks after auth */ |
Damien Miller | 6aef38f | 2003-11-18 10:45:20 +1100 | [diff] [blame] | 377 | if (options.use_pam && authenticated) { |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 378 | Buffer m; |
| 379 | |
| 380 | buffer_init(&m); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 381 | mm_request_receive_expect(pmonitor->m_sendfd, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 382 | MONITOR_REQ_PAM_ACCOUNT, &m); |
| 383 | authenticated = mm_answer_pam_account(pmonitor->m_sendfd, &m); |
| 384 | buffer_free(&m); |
| 385 | } |
| 386 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 389 | if (ent->flags & (MON_AUTHDECIDE|MON_ALOG)) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 390 | auth_log(authctxt, authenticated, auth_method, |
| 391 | compat20 ? " ssh2" : ""); |
| 392 | if (!authenticated) |
| 393 | authctxt->failures++; |
| 394 | } |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 395 | #ifdef JPAKE |
| 396 | /* Cleanup JPAKE context after authentication */ |
| 397 | if (ent->flags & MON_AUTHDECIDE) { |
| 398 | if (authctxt->jpake_ctx != NULL) { |
| 399 | jpake_free(authctxt->jpake_ctx); |
| 400 | authctxt->jpake_ctx = NULL; |
| 401 | } |
| 402 | } |
| 403 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | if (!authctxt->valid) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 407 | fatal("%s: authenticated invalid user", __func__); |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 408 | if (strcmp(auth_method, "unknown") == 0) |
| 409 | fatal("%s: authentication method name unknown", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 410 | |
| 411 | debug("%s: %s has been authenticated by privileged process", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 412 | __func__, authctxt->user); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 413 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 414 | mm_get_keystate(pmonitor); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 417 | static void |
| 418 | monitor_set_child_handler(pid_t pid) |
| 419 | { |
| 420 | monitor_child_pid = pid; |
| 421 | } |
| 422 | |
| 423 | static void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 424 | monitor_child_handler(int sig) |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 425 | { |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 426 | kill(monitor_child_pid, sig); |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 427 | } |
| 428 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 429 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 430 | monitor_child_postauth(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 431 | { |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 432 | monitor_set_child_handler(pmonitor->m_pid); |
| 433 | signal(SIGHUP, &monitor_child_handler); |
| 434 | signal(SIGTERM, &monitor_child_handler); |
Darren Tucker | 7fa339b | 2007-05-20 15:10:16 +1000 | [diff] [blame] | 435 | signal(SIGINT, &monitor_child_handler); |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 436 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 437 | if (compat20) { |
| 438 | mon_dispatch = mon_dispatch_postauth20; |
| 439 | |
| 440 | /* Permit requests for moduli and signatures */ |
| 441 | monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); |
| 442 | monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); |
| 443 | monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 444 | } else { |
| 445 | mon_dispatch = mon_dispatch_postauth15; |
| 446 | monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); |
| 447 | } |
| 448 | if (!no_pty_flag) { |
| 449 | monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); |
| 450 | monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1); |
| 451 | } |
| 452 | |
| 453 | for (;;) |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 454 | monitor_read(pmonitor, mon_dispatch, NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 458 | monitor_sync(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 459 | { |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 460 | if (options.compression) { |
| 461 | /* The member allocation is not visible, so sync it */ |
| 462 | mm_share_sync(&pmonitor->m_zlib, &pmonitor->m_zback); |
| 463 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | int |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 467 | monitor_read(struct monitor *pmonitor, struct mon_table *ent, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 468 | struct mon_table **pent) |
| 469 | { |
| 470 | Buffer m; |
| 471 | int ret; |
| 472 | u_char type; |
| 473 | |
| 474 | buffer_init(&m); |
| 475 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 476 | mm_request_receive(pmonitor->m_sendfd, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 477 | type = buffer_get_char(&m); |
| 478 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 479 | debug3("%s: checking request %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 480 | |
| 481 | while (ent->f != NULL) { |
| 482 | if (ent->type == type) |
| 483 | break; |
| 484 | ent++; |
| 485 | } |
| 486 | |
| 487 | if (ent->f != NULL) { |
| 488 | if (!(ent->flags & MON_PERMIT)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 489 | fatal("%s: unpermitted request %d", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 490 | type); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 491 | ret = (*ent->f)(pmonitor->m_sendfd, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 492 | buffer_free(&m); |
| 493 | |
| 494 | /* The child may use this request only once, disable it */ |
| 495 | if (ent->flags & MON_ONCE) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 496 | debug2("%s: %d used once, disabling now", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 497 | type); |
| 498 | ent->flags &= ~MON_PERMIT; |
| 499 | } |
| 500 | |
| 501 | if (pent != NULL) |
| 502 | *pent = ent; |
| 503 | |
| 504 | return ret; |
| 505 | } |
| 506 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 507 | fatal("%s: unsupported request: %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 508 | |
| 509 | /* NOTREACHED */ |
| 510 | return (-1); |
| 511 | } |
| 512 | |
| 513 | /* allowed key state */ |
| 514 | static int |
| 515 | monitor_allowed_key(u_char *blob, u_int bloblen) |
| 516 | { |
| 517 | /* make sure key is allowed */ |
| 518 | if (key_blob == NULL || key_bloblen != bloblen || |
| 519 | memcmp(key_blob, blob, key_bloblen)) |
| 520 | return (0); |
| 521 | return (1); |
| 522 | } |
| 523 | |
| 524 | static void |
| 525 | monitor_reset_key_state(void) |
| 526 | { |
| 527 | /* reset state */ |
| 528 | if (key_blob != NULL) |
| 529 | xfree(key_blob); |
| 530 | if (hostbased_cuser != NULL) |
| 531 | xfree(hostbased_cuser); |
| 532 | if (hostbased_chost != NULL) |
| 533 | xfree(hostbased_chost); |
| 534 | key_blob = NULL; |
| 535 | key_bloblen = 0; |
| 536 | key_blobtype = MM_NOKEY; |
| 537 | hostbased_cuser = NULL; |
| 538 | hostbased_chost = NULL; |
| 539 | } |
| 540 | |
| 541 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 542 | mm_answer_moduli(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 543 | { |
| 544 | DH *dh; |
| 545 | int min, want, max; |
| 546 | |
| 547 | min = buffer_get_int(m); |
| 548 | want = buffer_get_int(m); |
| 549 | max = buffer_get_int(m); |
| 550 | |
| 551 | debug3("%s: got parameters: %d %d %d", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 552 | __func__, min, want, max); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 553 | /* We need to check here, too, in case the child got corrupted */ |
| 554 | if (max < min || want < min || max < want) |
| 555 | fatal("%s: bad parameters: %d %d %d", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 556 | __func__, min, want, max); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 557 | |
| 558 | buffer_clear(m); |
| 559 | |
| 560 | dh = choose_dh(min, want, max); |
| 561 | if (dh == NULL) { |
| 562 | buffer_put_char(m, 0); |
| 563 | return (0); |
| 564 | } else { |
| 565 | /* Send first bignum */ |
| 566 | buffer_put_char(m, 1); |
| 567 | buffer_put_bignum2(m, dh->p); |
| 568 | buffer_put_bignum2(m, dh->g); |
| 569 | |
| 570 | DH_free(dh); |
| 571 | } |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 572 | mm_request_send(sock, MONITOR_ANS_MODULI, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 573 | return (0); |
| 574 | } |
| 575 | |
| 576 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 577 | mm_answer_sign(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 578 | { |
| 579 | Key *key; |
| 580 | u_char *p; |
| 581 | u_char *signature; |
| 582 | u_int siglen, datlen; |
| 583 | int keyid; |
| 584 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 585 | debug3("%s", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 586 | |
| 587 | keyid = buffer_get_int(m); |
| 588 | p = buffer_get_string(m, &datlen); |
| 589 | |
Damien Miller | a63128d | 2006-03-15 12:08:28 +1100 | [diff] [blame] | 590 | /* |
Damien Miller | c91e556 | 2006-03-26 13:58:55 +1100 | [diff] [blame] | 591 | * Supported KEX types will only return SHA1 (20 byte) or |
Damien Miller | a63128d | 2006-03-15 12:08:28 +1100 | [diff] [blame] | 592 | * SHA256 (32 byte) hashes |
| 593 | */ |
| 594 | if (datlen != 20 && datlen != 32) |
Ben Lindstrom | d550218 | 2002-06-27 00:12:57 +0000 | [diff] [blame] | 595 | fatal("%s: data length incorrect: %u", __func__, datlen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 596 | |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 597 | /* save session id, it will be passed on the first call */ |
| 598 | if (session_id2_len == 0) { |
| 599 | session_id2_len = datlen; |
| 600 | session_id2 = xmalloc(session_id2_len); |
| 601 | memcpy(session_id2, p, session_id2_len); |
| 602 | } |
| 603 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 604 | if ((key = get_hostkey_by_index(keyid)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 605 | fatal("%s: no hostkey from index %d", __func__, keyid); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 606 | if (key_sign(key, &signature, &siglen, p, datlen) < 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 607 | fatal("%s: key_sign failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 608 | |
Ben Lindstrom | d550218 | 2002-06-27 00:12:57 +0000 | [diff] [blame] | 609 | debug3("%s: signature %p(%u)", __func__, signature, siglen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 610 | |
| 611 | buffer_clear(m); |
| 612 | buffer_put_string(m, signature, siglen); |
| 613 | |
| 614 | xfree(p); |
| 615 | xfree(signature); |
| 616 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 617 | mm_request_send(sock, MONITOR_ANS_SIGN, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 618 | |
| 619 | /* Turn on permissions for getpwnam */ |
| 620 | monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1); |
| 621 | |
| 622 | return (0); |
| 623 | } |
| 624 | |
| 625 | /* Retrieves the password entry and also checks if the user is permitted */ |
| 626 | |
| 627 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 628 | mm_answer_pwnamallow(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 629 | { |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 630 | char *username; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 631 | struct passwd *pwent; |
| 632 | int allowed = 0; |
| 633 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 634 | debug3("%s", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 635 | |
| 636 | if (authctxt->attempt++ != 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 637 | fatal("%s: multiple attempts for getpwnam", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 638 | |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 639 | username = buffer_get_string(m, NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 640 | |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 641 | pwent = getpwnamallow(username); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 642 | |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 643 | authctxt->user = xstrdup(username); |
| 644 | setproctitle("%s [priv]", pwent ? username : "unknown"); |
| 645 | xfree(username); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 646 | |
| 647 | buffer_clear(m); |
| 648 | |
| 649 | if (pwent == NULL) { |
| 650 | buffer_put_char(m, 0); |
Damien Miller | f96d183 | 2003-11-18 22:01:48 +1100 | [diff] [blame] | 651 | authctxt->pw = fakepw(); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 652 | goto out; |
| 653 | } |
| 654 | |
| 655 | allowed = 1; |
| 656 | authctxt->pw = pwent; |
| 657 | authctxt->valid = 1; |
| 658 | |
| 659 | buffer_put_char(m, 1); |
| 660 | buffer_put_string(m, pwent, sizeof(struct passwd)); |
| 661 | buffer_put_cstring(m, pwent->pw_name); |
| 662 | buffer_put_cstring(m, "*"); |
| 663 | buffer_put_cstring(m, pwent->pw_gecos); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 664 | #ifdef HAVE_PW_CLASS_IN_PASSWD |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 665 | buffer_put_cstring(m, pwent->pw_class); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 666 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 667 | buffer_put_cstring(m, pwent->pw_dir); |
| 668 | buffer_put_cstring(m, pwent->pw_shell); |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 669 | |
| 670 | out: |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 671 | buffer_put_string(m, &options, sizeof(options)); |
| 672 | if (options.banner != NULL) |
| 673 | buffer_put_cstring(m, options.banner); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 674 | debug3("%s: sending MONITOR_ANS_PWNAM: %d", __func__, allowed); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 675 | mm_request_send(sock, MONITOR_ANS_PWNAM, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 676 | |
| 677 | /* For SSHv1 allow authentication now */ |
| 678 | if (!compat20) |
| 679 | monitor_permit_authentications(1); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 680 | else { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 681 | /* Allow service/style information on the auth context */ |
| 682 | monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 683 | monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1); |
| 684 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 685 | |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 686 | #ifdef USE_PAM |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 687 | if (options.use_pam) |
| 688 | monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1); |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 689 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 690 | |
| 691 | return (0); |
| 692 | } |
| 693 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 694 | int mm_answer_auth2_read_banner(int sock, Buffer *m) |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 695 | { |
| 696 | char *banner; |
| 697 | |
| 698 | buffer_clear(m); |
| 699 | banner = auth2_read_banner(); |
| 700 | buffer_put_cstring(m, banner != NULL ? banner : ""); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 701 | mm_request_send(sock, MONITOR_ANS_AUTH2_READ_BANNER, m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 702 | |
| 703 | if (banner != NULL) |
Ben Lindstrom | eec16fc | 2002-07-04 00:06:15 +0000 | [diff] [blame] | 704 | xfree(banner); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 705 | |
| 706 | return (0); |
| 707 | } |
| 708 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 709 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 710 | mm_answer_authserv(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 711 | { |
| 712 | monitor_permit_authentications(1); |
| 713 | |
| 714 | authctxt->service = buffer_get_string(m, NULL); |
| 715 | authctxt->style = buffer_get_string(m, NULL); |
| 716 | debug3("%s: service=%s, style=%s", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 717 | __func__, authctxt->service, authctxt->style); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 718 | |
| 719 | if (strlen(authctxt->style) == 0) { |
| 720 | xfree(authctxt->style); |
| 721 | authctxt->style = NULL; |
| 722 | } |
| 723 | |
| 724 | return (0); |
| 725 | } |
| 726 | |
| 727 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 728 | mm_answer_authpassword(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 729 | { |
| 730 | static int call_count; |
| 731 | char *passwd; |
Ben Lindstrom | 7cea16b | 2002-07-23 21:13:40 +0000 | [diff] [blame] | 732 | int authenticated; |
| 733 | u_int plen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 734 | |
| 735 | passwd = buffer_get_string(m, &plen); |
| 736 | /* Only authenticate if the context is valid */ |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 737 | authenticated = options.password_authentication && |
Damien Miller | 856f0be | 2003-09-03 07:32:45 +1000 | [diff] [blame] | 738 | auth_password(authctxt, passwd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 739 | memset(passwd, 0, strlen(passwd)); |
| 740 | xfree(passwd); |
| 741 | |
| 742 | buffer_clear(m); |
| 743 | buffer_put_int(m, authenticated); |
| 744 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 745 | debug3("%s: sending result %d", __func__, authenticated); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 746 | mm_request_send(sock, MONITOR_ANS_AUTHPASSWORD, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 747 | |
| 748 | call_count++; |
| 749 | if (plen == 0 && call_count == 1) |
| 750 | auth_method = "none"; |
| 751 | else |
| 752 | auth_method = "password"; |
| 753 | |
| 754 | /* Causes monitor loop to terminate if authenticated */ |
| 755 | return (authenticated); |
| 756 | } |
| 757 | |
| 758 | #ifdef BSD_AUTH |
| 759 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 760 | mm_answer_bsdauthquery(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 761 | { |
| 762 | char *name, *infotxt; |
| 763 | u_int numprompts; |
| 764 | u_int *echo_on; |
| 765 | char **prompts; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 766 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 767 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 768 | success = bsdauth_query(authctxt, &name, &infotxt, &numprompts, |
| 769 | &prompts, &echo_on) < 0 ? 0 : 1; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 770 | |
| 771 | buffer_clear(m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 772 | buffer_put_int(m, success); |
| 773 | if (success) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 774 | buffer_put_cstring(m, prompts[0]); |
| 775 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 776 | debug3("%s: sending challenge success: %u", __func__, success); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 777 | mm_request_send(sock, MONITOR_ANS_BSDAUTHQUERY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 778 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 779 | if (success) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 780 | xfree(name); |
| 781 | xfree(infotxt); |
| 782 | xfree(prompts); |
| 783 | xfree(echo_on); |
| 784 | } |
| 785 | |
| 786 | return (0); |
| 787 | } |
| 788 | |
| 789 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 790 | mm_answer_bsdauthrespond(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 791 | { |
| 792 | char *response; |
| 793 | int authok; |
| 794 | |
| 795 | if (authctxt->as == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 796 | fatal("%s: no bsd auth session", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 797 | |
| 798 | response = buffer_get_string(m, NULL); |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 799 | authok = options.challenge_response_authentication && |
| 800 | auth_userresponse(authctxt->as, response, 0); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 801 | authctxt->as = NULL; |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 802 | debug3("%s: <%s> = <%d>", __func__, response, authok); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 803 | xfree(response); |
| 804 | |
| 805 | buffer_clear(m); |
| 806 | buffer_put_int(m, authok); |
| 807 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 808 | debug3("%s: sending authenticated: %d", __func__, authok); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 809 | mm_request_send(sock, MONITOR_ANS_BSDAUTHRESPOND, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 810 | |
| 811 | auth_method = "bsdauth"; |
| 812 | |
| 813 | return (authok != 0); |
| 814 | } |
| 815 | #endif |
| 816 | |
| 817 | #ifdef SKEY |
| 818 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 819 | mm_answer_skeyquery(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 820 | { |
| 821 | struct skey skey; |
| 822 | char challenge[1024]; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 823 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 824 | |
Darren Tucker | 06a8cfe | 2004-04-14 17:24:30 +1000 | [diff] [blame] | 825 | success = _compat_skeychallenge(&skey, authctxt->user, challenge, |
| 826 | sizeof(challenge)) < 0 ? 0 : 1; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 827 | |
| 828 | buffer_clear(m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 829 | buffer_put_int(m, success); |
| 830 | if (success) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 831 | buffer_put_cstring(m, challenge); |
| 832 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 833 | debug3("%s: sending challenge success: %u", __func__, success); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 834 | mm_request_send(sock, MONITOR_ANS_SKEYQUERY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 835 | |
| 836 | return (0); |
| 837 | } |
| 838 | |
| 839 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 840 | mm_answer_skeyrespond(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 841 | { |
| 842 | char *response; |
| 843 | int authok; |
| 844 | |
| 845 | response = buffer_get_string(m, NULL); |
| 846 | |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 847 | authok = (options.challenge_response_authentication && |
| 848 | authctxt->valid && |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 849 | skey_haskey(authctxt->pw->pw_name) == 0 && |
| 850 | skey_passcheck(authctxt->pw->pw_name, response) != -1); |
| 851 | |
| 852 | xfree(response); |
| 853 | |
| 854 | buffer_clear(m); |
| 855 | buffer_put_int(m, authok); |
| 856 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 857 | debug3("%s: sending authenticated: %d", __func__, authok); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 858 | mm_request_send(sock, MONITOR_ANS_SKEYRESPOND, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 859 | |
| 860 | auth_method = "skey"; |
| 861 | |
| 862 | return (authok != 0); |
| 863 | } |
| 864 | #endif |
| 865 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 866 | #ifdef USE_PAM |
| 867 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 868 | mm_answer_pam_start(int sock, Buffer *m) |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 869 | { |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 870 | if (!options.use_pam) |
| 871 | fatal("UsePAM not set, but ended up in %s anyway", __func__); |
| 872 | |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 873 | start_pam(authctxt); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 874 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 875 | monitor_permit(mon_dispatch, MONITOR_REQ_PAM_ACCOUNT, 1); |
| 876 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 877 | return (0); |
| 878 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 879 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 880 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 881 | mm_answer_pam_account(int sock, Buffer *m) |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 882 | { |
| 883 | u_int ret; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 884 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 885 | if (!options.use_pam) |
| 886 | fatal("UsePAM not set, but ended up in %s anyway", __func__); |
| 887 | |
| 888 | ret = do_pam_account(); |
| 889 | |
| 890 | buffer_put_int(m, ret); |
Darren Tucker | d4f04ae | 2005-09-30 10:23:21 +1000 | [diff] [blame] | 891 | buffer_put_string(m, buffer_ptr(&loginmsg), buffer_len(&loginmsg)); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 892 | |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 893 | mm_request_send(sock, MONITOR_ANS_PAM_ACCOUNT, m); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 894 | |
| 895 | return (ret); |
| 896 | } |
| 897 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 898 | static void *sshpam_ctxt, *sshpam_authok; |
| 899 | extern KbdintDevice sshpam_device; |
| 900 | |
| 901 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 902 | mm_answer_pam_init_ctx(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 903 | { |
| 904 | |
| 905 | debug3("%s", __func__); |
| 906 | authctxt->user = buffer_get_string(m, NULL); |
| 907 | sshpam_ctxt = (sshpam_device.init_ctx)(authctxt); |
| 908 | sshpam_authok = NULL; |
| 909 | buffer_clear(m); |
| 910 | if (sshpam_ctxt != NULL) { |
| 911 | monitor_permit(mon_dispatch, MONITOR_REQ_PAM_FREE_CTX, 1); |
| 912 | buffer_put_int(m, 1); |
| 913 | } else { |
| 914 | buffer_put_int(m, 0); |
| 915 | } |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 916 | mm_request_send(sock, MONITOR_ANS_PAM_INIT_CTX, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 917 | return (0); |
| 918 | } |
| 919 | |
| 920 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 921 | mm_answer_pam_query(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 922 | { |
| 923 | char *name, *info, **prompts; |
Damien Miller | 04b6533 | 2005-07-17 17:53:31 +1000 | [diff] [blame] | 924 | u_int i, num, *echo_on; |
| 925 | int ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 926 | |
| 927 | debug3("%s", __func__); |
| 928 | sshpam_authok = NULL; |
| 929 | ret = (sshpam_device.query)(sshpam_ctxt, &name, &info, &num, &prompts, &echo_on); |
| 930 | if (ret == 0 && num == 0) |
| 931 | sshpam_authok = sshpam_ctxt; |
| 932 | if (num > 1 || name == NULL || info == NULL) |
| 933 | ret = -1; |
| 934 | buffer_clear(m); |
| 935 | buffer_put_int(m, ret); |
| 936 | buffer_put_cstring(m, name); |
| 937 | xfree(name); |
| 938 | buffer_put_cstring(m, info); |
| 939 | xfree(info); |
| 940 | buffer_put_int(m, num); |
| 941 | for (i = 0; i < num; ++i) { |
| 942 | buffer_put_cstring(m, prompts[i]); |
| 943 | xfree(prompts[i]); |
| 944 | buffer_put_int(m, echo_on[i]); |
| 945 | } |
| 946 | if (prompts != NULL) |
| 947 | xfree(prompts); |
| 948 | if (echo_on != NULL) |
| 949 | xfree(echo_on); |
Darren Tucker | f14b2aa | 2006-05-21 18:26:40 +1000 | [diff] [blame] | 950 | auth_method = "keyboard-interactive/pam"; |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 951 | mm_request_send(sock, MONITOR_ANS_PAM_QUERY, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 952 | return (0); |
| 953 | } |
| 954 | |
| 955 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 956 | mm_answer_pam_respond(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 957 | { |
| 958 | char **resp; |
Damien Miller | 04b6533 | 2005-07-17 17:53:31 +1000 | [diff] [blame] | 959 | u_int i, num; |
| 960 | int ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 961 | |
| 962 | debug3("%s", __func__); |
| 963 | sshpam_authok = NULL; |
| 964 | num = buffer_get_int(m); |
| 965 | if (num > 0) { |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 966 | resp = xcalloc(num, sizeof(char *)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 967 | for (i = 0; i < num; ++i) |
| 968 | resp[i] = buffer_get_string(m, NULL); |
| 969 | ret = (sshpam_device.respond)(sshpam_ctxt, num, resp); |
| 970 | for (i = 0; i < num; ++i) |
| 971 | xfree(resp[i]); |
| 972 | xfree(resp); |
| 973 | } else { |
| 974 | ret = (sshpam_device.respond)(sshpam_ctxt, num, NULL); |
| 975 | } |
| 976 | buffer_clear(m); |
| 977 | buffer_put_int(m, ret); |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 978 | mm_request_send(sock, MONITOR_ANS_PAM_RESPOND, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 979 | auth_method = "keyboard-interactive/pam"; |
| 980 | if (ret == 0) |
| 981 | sshpam_authok = sshpam_ctxt; |
| 982 | return (0); |
| 983 | } |
| 984 | |
| 985 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 986 | mm_answer_pam_free_ctx(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 987 | { |
| 988 | |
| 989 | debug3("%s", __func__); |
| 990 | (sshpam_device.free_ctx)(sshpam_ctxt); |
| 991 | buffer_clear(m); |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 992 | mm_request_send(sock, MONITOR_ANS_PAM_FREE_CTX, m); |
Darren Tucker | f14b2aa | 2006-05-21 18:26:40 +1000 | [diff] [blame] | 993 | auth_method = "keyboard-interactive/pam"; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 994 | return (sshpam_authok == sshpam_ctxt); |
| 995 | } |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 996 | #endif |
| 997 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 998 | static void |
| 999 | mm_append_debug(Buffer *m) |
| 1000 | { |
| 1001 | if (auth_debug_init && buffer_len(&auth_debug)) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1002 | debug3("%s: Appending debug messages for child", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1003 | buffer_append(m, buffer_ptr(&auth_debug), |
| 1004 | buffer_len(&auth_debug)); |
| 1005 | buffer_clear(&auth_debug); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1010 | mm_answer_keyallowed(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1011 | { |
| 1012 | Key *key; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1013 | char *cuser, *chost; |
| 1014 | u_char *blob; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1015 | u_int bloblen; |
| 1016 | enum mm_keytype type = 0; |
| 1017 | int allowed = 0; |
| 1018 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1019 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1020 | |
| 1021 | type = buffer_get_int(m); |
| 1022 | cuser = buffer_get_string(m, NULL); |
| 1023 | chost = buffer_get_string(m, NULL); |
| 1024 | blob = buffer_get_string(m, &bloblen); |
| 1025 | |
| 1026 | key = key_from_blob(blob, bloblen); |
| 1027 | |
| 1028 | if ((compat20 && type == MM_RSAHOSTKEY) || |
| 1029 | (!compat20 && type != MM_RSAHOSTKEY)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1030 | fatal("%s: key type and protocol mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1031 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1032 | debug3("%s: key_from_blob: %p", __func__, key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1033 | |
Damien Miller | 3e3b514 | 2003-11-17 21:13:40 +1100 | [diff] [blame] | 1034 | if (key != NULL && authctxt->valid) { |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 1035 | switch (type) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1036 | case MM_USERKEY: |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 1037 | allowed = options.pubkey_authentication && |
| 1038 | user_key_allowed(authctxt->pw, key); |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 1039 | auth_method = "publickey"; |
Darren Tucker | f2c16d3 | 2008-06-14 08:59:49 +1000 | [diff] [blame] | 1040 | if (options.pubkey_authentication && allowed != 1) |
| 1041 | auth_clear_options(); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | case MM_HOSTKEY: |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 1044 | allowed = options.hostbased_authentication && |
| 1045 | hostbased_key_allowed(authctxt->pw, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1046 | cuser, chost, key); |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 1047 | auth_method = "hostbased"; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1048 | break; |
| 1049 | case MM_RSAHOSTKEY: |
| 1050 | key->type = KEY_RSA1; /* XXX */ |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 1051 | allowed = options.rhosts_rsa_authentication && |
| 1052 | auth_rhosts_rsa_key_allowed(authctxt->pw, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1053 | cuser, chost, key); |
Darren Tucker | f2c16d3 | 2008-06-14 08:59:49 +1000 | [diff] [blame] | 1054 | if (options.rhosts_rsa_authentication && allowed != 1) |
| 1055 | auth_clear_options(); |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 1056 | auth_method = "rsa"; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | default: |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1059 | fatal("%s: unknown key type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1060 | break; |
| 1061 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1062 | } |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1063 | if (key != NULL) |
| 1064 | key_free(key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1065 | |
| 1066 | /* clear temporarily storage (used by verify) */ |
| 1067 | monitor_reset_key_state(); |
| 1068 | |
| 1069 | if (allowed) { |
| 1070 | /* Save temporarily for comparison in verify */ |
| 1071 | key_blob = blob; |
| 1072 | key_bloblen = bloblen; |
| 1073 | key_blobtype = type; |
| 1074 | hostbased_cuser = cuser; |
| 1075 | hostbased_chost = chost; |
Damien Miller | 96937bd | 2006-03-26 14:01:54 +1100 | [diff] [blame] | 1076 | } else { |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 1077 | /* Log failed attempt */ |
| 1078 | auth_log(authctxt, 0, auth_method, compat20 ? " ssh2" : ""); |
Damien Miller | 96937bd | 2006-03-26 14:01:54 +1100 | [diff] [blame] | 1079 | xfree(blob); |
| 1080 | xfree(cuser); |
| 1081 | xfree(chost); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | debug3("%s: key %p is %s", |
Darren Tucker | 2784f1f | 2008-07-04 13:51:45 +1000 | [diff] [blame] | 1085 | __func__, key, allowed ? "allowed" : "not allowed"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1086 | |
| 1087 | buffer_clear(m); |
| 1088 | buffer_put_int(m, allowed); |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1089 | buffer_put_int(m, forced_command != NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1090 | |
| 1091 | mm_append_debug(m); |
| 1092 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1093 | mm_request_send(sock, MONITOR_ANS_KEYALLOWED, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1094 | |
| 1095 | if (type == MM_RSAHOSTKEY) |
| 1096 | monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed); |
| 1097 | |
| 1098 | return (0); |
| 1099 | } |
| 1100 | |
| 1101 | static int |
| 1102 | monitor_valid_userblob(u_char *data, u_int datalen) |
| 1103 | { |
| 1104 | Buffer b; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1105 | char *p; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1106 | u_int len; |
| 1107 | int fail = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1108 | |
| 1109 | buffer_init(&b); |
| 1110 | buffer_append(&b, data, datalen); |
| 1111 | |
| 1112 | if (datafellows & SSH_OLD_SESSIONID) { |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1113 | p = buffer_ptr(&b); |
| 1114 | len = buffer_len(&b); |
| 1115 | if ((session_id2 == NULL) || |
| 1116 | (len < session_id2_len) || |
| 1117 | (memcmp(p, session_id2, session_id2_len) != 0)) |
| 1118 | fail++; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1119 | buffer_consume(&b, session_id2_len); |
| 1120 | } else { |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1121 | p = buffer_get_string(&b, &len); |
| 1122 | if ((session_id2 == NULL) || |
| 1123 | (len != session_id2_len) || |
| 1124 | (memcmp(p, session_id2, session_id2_len) != 0)) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1125 | fail++; |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1126 | xfree(p); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1127 | } |
| 1128 | if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST) |
| 1129 | fail++; |
| 1130 | p = buffer_get_string(&b, NULL); |
| 1131 | if (strcmp(authctxt->user, p) != 0) { |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 1132 | logit("wrong user name passed to monitor: expected %s != %.100s", |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1133 | authctxt->user, p); |
| 1134 | fail++; |
| 1135 | } |
| 1136 | xfree(p); |
| 1137 | buffer_skip_string(&b); |
| 1138 | if (datafellows & SSH_BUG_PKAUTH) { |
| 1139 | if (!buffer_get_char(&b)) |
| 1140 | fail++; |
| 1141 | } else { |
| 1142 | p = buffer_get_string(&b, NULL); |
| 1143 | if (strcmp("publickey", p) != 0) |
| 1144 | fail++; |
| 1145 | xfree(p); |
| 1146 | if (!buffer_get_char(&b)) |
| 1147 | fail++; |
| 1148 | buffer_skip_string(&b); |
| 1149 | } |
| 1150 | buffer_skip_string(&b); |
| 1151 | if (buffer_len(&b) != 0) |
| 1152 | fail++; |
| 1153 | buffer_free(&b); |
| 1154 | return (fail == 0); |
| 1155 | } |
| 1156 | |
| 1157 | static int |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1158 | monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser, |
| 1159 | char *chost) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1160 | { |
| 1161 | Buffer b; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1162 | char *p; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1163 | u_int len; |
| 1164 | int fail = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1165 | |
| 1166 | buffer_init(&b); |
| 1167 | buffer_append(&b, data, datalen); |
| 1168 | |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1169 | p = buffer_get_string(&b, &len); |
| 1170 | if ((session_id2 == NULL) || |
| 1171 | (len != session_id2_len) || |
| 1172 | (memcmp(p, session_id2, session_id2_len) != 0)) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1173 | fail++; |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1174 | xfree(p); |
| 1175 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1176 | if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST) |
| 1177 | fail++; |
| 1178 | p = buffer_get_string(&b, NULL); |
| 1179 | if (strcmp(authctxt->user, p) != 0) { |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 1180 | logit("wrong user name passed to monitor: expected %s != %.100s", |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1181 | authctxt->user, p); |
| 1182 | fail++; |
| 1183 | } |
| 1184 | xfree(p); |
| 1185 | buffer_skip_string(&b); /* service */ |
| 1186 | p = buffer_get_string(&b, NULL); |
| 1187 | if (strcmp(p, "hostbased") != 0) |
| 1188 | fail++; |
| 1189 | xfree(p); |
| 1190 | buffer_skip_string(&b); /* pkalg */ |
| 1191 | buffer_skip_string(&b); /* pkblob */ |
| 1192 | |
| 1193 | /* verify client host, strip trailing dot if necessary */ |
| 1194 | p = buffer_get_string(&b, NULL); |
| 1195 | if (((len = strlen(p)) > 0) && p[len - 1] == '.') |
| 1196 | p[len - 1] = '\0'; |
| 1197 | if (strcmp(p, chost) != 0) |
| 1198 | fail++; |
| 1199 | xfree(p); |
| 1200 | |
| 1201 | /* verify client user */ |
| 1202 | p = buffer_get_string(&b, NULL); |
| 1203 | if (strcmp(p, cuser) != 0) |
| 1204 | fail++; |
| 1205 | xfree(p); |
| 1206 | |
| 1207 | if (buffer_len(&b) != 0) |
| 1208 | fail++; |
| 1209 | buffer_free(&b); |
| 1210 | return (fail == 0); |
| 1211 | } |
| 1212 | |
| 1213 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1214 | mm_answer_keyverify(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1215 | { |
| 1216 | Key *key; |
| 1217 | u_char *signature, *data, *blob; |
| 1218 | u_int signaturelen, datalen, bloblen; |
| 1219 | int verified = 0; |
| 1220 | int valid_data = 0; |
| 1221 | |
| 1222 | blob = buffer_get_string(m, &bloblen); |
| 1223 | signature = buffer_get_string(m, &signaturelen); |
| 1224 | data = buffer_get_string(m, &datalen); |
| 1225 | |
| 1226 | if (hostbased_cuser == NULL || hostbased_chost == NULL || |
Ben Lindstrom | b57a4bf | 2002-03-27 18:00:59 +0000 | [diff] [blame] | 1227 | !monitor_allowed_key(blob, bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1228 | fatal("%s: bad key, not previously allowed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1229 | |
| 1230 | key = key_from_blob(blob, bloblen); |
| 1231 | if (key == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1232 | fatal("%s: bad public key blob", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1233 | |
| 1234 | switch (key_blobtype) { |
| 1235 | case MM_USERKEY: |
| 1236 | valid_data = monitor_valid_userblob(data, datalen); |
| 1237 | break; |
| 1238 | case MM_HOSTKEY: |
| 1239 | valid_data = monitor_valid_hostbasedblob(data, datalen, |
| 1240 | hostbased_cuser, hostbased_chost); |
| 1241 | break; |
| 1242 | default: |
| 1243 | valid_data = 0; |
| 1244 | break; |
| 1245 | } |
| 1246 | if (!valid_data) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1247 | fatal("%s: bad signature data blob", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1248 | |
| 1249 | verified = key_verify(key, signature, signaturelen, data, datalen); |
| 1250 | debug3("%s: key %p signature %s", |
Darren Tucker | fbba735 | 2006-11-07 23:16:08 +1100 | [diff] [blame] | 1251 | __func__, key, (verified == 1) ? "verified" : "unverified"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1252 | |
| 1253 | key_free(key); |
| 1254 | xfree(blob); |
| 1255 | xfree(signature); |
| 1256 | xfree(data); |
| 1257 | |
Ben Lindstrom | e1c0912 | 2002-06-23 00:38:24 +0000 | [diff] [blame] | 1258 | auth_method = key_blobtype == MM_USERKEY ? "publickey" : "hostbased"; |
| 1259 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1260 | monitor_reset_key_state(); |
| 1261 | |
| 1262 | buffer_clear(m); |
| 1263 | buffer_put_int(m, verified); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1264 | mm_request_send(sock, MONITOR_ANS_KEYVERIFY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1265 | |
Darren Tucker | fbba735 | 2006-11-07 23:16:08 +1100 | [diff] [blame] | 1266 | return (verified == 1); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static void |
| 1270 | mm_record_login(Session *s, struct passwd *pw) |
| 1271 | { |
| 1272 | socklen_t fromlen; |
| 1273 | struct sockaddr_storage from; |
| 1274 | |
| 1275 | /* |
| 1276 | * Get IP address of client. If the connection is not a socket, let |
| 1277 | * the address be 0.0.0.0. |
| 1278 | */ |
| 1279 | memset(&from, 0, sizeof(from)); |
Damien Miller | ebc2306 | 2002-09-04 16:45:09 +1000 | [diff] [blame] | 1280 | fromlen = sizeof(from); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1281 | if (packet_connection_is_on_socket()) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1282 | if (getpeername(packet_get_connection_in(), |
Damien Miller | 9f3bd53 | 2006-03-26 14:07:52 +1100 | [diff] [blame] | 1283 | (struct sockaddr *)&from, &fromlen) < 0) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1284 | debug("getpeername: %.100s", strerror(errno)); |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 1285 | cleanup_exit(255); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | /* Record that there was a login on that tty from the remote host. */ |
| 1289 | record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid, |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 1290 | get_remote_name_or_ip(utmp_len, options.use_dns), |
Damien Miller | ebc2306 | 2002-09-04 16:45:09 +1000 | [diff] [blame] | 1291 | (struct sockaddr *)&from, fromlen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | static void |
| 1295 | mm_session_close(Session *s) |
| 1296 | { |
Damien Miller | 04bd8b0 | 2003-05-25 14:38:33 +1000 | [diff] [blame] | 1297 | debug3("%s: session %d pid %ld", __func__, s->self, (long)s->pid); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1298 | if (s->ttyfd != -1) { |
Damien Miller | 9ab00b4 | 2006-08-05 12:40:11 +1000 | [diff] [blame] | 1299 | debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1300 | session_pty_cleanup2(s); |
| 1301 | } |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 1302 | session_unused(s->self); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1306 | mm_answer_pty(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1307 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1308 | extern struct monitor *pmonitor; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1309 | Session *s; |
| 1310 | int res, fd0; |
| 1311 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1312 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1313 | |
| 1314 | buffer_clear(m); |
| 1315 | s = session_new(); |
| 1316 | if (s == NULL) |
| 1317 | goto error; |
| 1318 | s->authctxt = authctxt; |
| 1319 | s->pw = authctxt->pw; |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1320 | s->pid = pmonitor->m_pid; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1321 | res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty)); |
| 1322 | if (res == 0) |
| 1323 | goto error; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1324 | pty_setowner(authctxt->pw, s->tty); |
| 1325 | |
| 1326 | buffer_put_int(m, 1); |
| 1327 | buffer_put_cstring(m, s->tty); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1328 | |
| 1329 | /* We need to trick ttyslot */ |
| 1330 | if (dup2(s->ttyfd, 0) == -1) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1331 | fatal("%s: dup2", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1332 | |
| 1333 | mm_record_login(s, authctxt->pw); |
| 1334 | |
| 1335 | /* Now we can close the file descriptor again */ |
| 1336 | close(0); |
| 1337 | |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 1338 | /* send messages generated by record_login */ |
| 1339 | buffer_put_string(m, buffer_ptr(&loginmsg), buffer_len(&loginmsg)); |
| 1340 | buffer_clear(&loginmsg); |
| 1341 | |
| 1342 | mm_request_send(sock, MONITOR_ANS_PTY, m); |
| 1343 | |
Damien Miller | 54fd7cf | 2007-09-17 12:04:08 +1000 | [diff] [blame] | 1344 | if (mm_send_fd(sock, s->ptyfd) == -1 || |
| 1345 | mm_send_fd(sock, s->ttyfd) == -1) |
| 1346 | fatal("%s: send fds failed", __func__); |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 1347 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1348 | /* make sure nothing uses fd 0 */ |
| 1349 | if ((fd0 = open(_PATH_DEVNULL, O_RDONLY)) < 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1350 | fatal("%s: open(/dev/null): %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1351 | if (fd0 != 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1352 | error("%s: fd0 %d != 0", __func__, fd0); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1353 | |
| 1354 | /* slave is not needed */ |
| 1355 | close(s->ttyfd); |
| 1356 | s->ttyfd = s->ptyfd; |
| 1357 | /* no need to dup() because nobody closes ptyfd */ |
| 1358 | s->ptymaster = s->ptyfd; |
| 1359 | |
Damien Miller | 9ab00b4 | 2006-08-05 12:40:11 +1000 | [diff] [blame] | 1360 | debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1361 | |
| 1362 | return (0); |
| 1363 | |
| 1364 | error: |
| 1365 | if (s != NULL) |
| 1366 | mm_session_close(s); |
| 1367 | buffer_put_int(m, 0); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1368 | mm_request_send(sock, MONITOR_ANS_PTY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1369 | return (0); |
| 1370 | } |
| 1371 | |
| 1372 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1373 | mm_answer_pty_cleanup(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1374 | { |
| 1375 | Session *s; |
| 1376 | char *tty; |
| 1377 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1378 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1379 | |
| 1380 | tty = buffer_get_string(m, NULL); |
| 1381 | if ((s = session_by_tty(tty)) != NULL) |
| 1382 | mm_session_close(s); |
| 1383 | buffer_clear(m); |
| 1384 | xfree(tty); |
| 1385 | return (0); |
| 1386 | } |
| 1387 | |
| 1388 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1389 | mm_answer_sesskey(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1390 | { |
| 1391 | BIGNUM *p; |
| 1392 | int rsafail; |
| 1393 | |
| 1394 | /* Turn off permissions */ |
Darren Tucker | 5b53026 | 2005-02-09 09:52:17 +1100 | [diff] [blame] | 1395 | monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 0); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1396 | |
| 1397 | if ((p = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1398 | fatal("%s: BN_new", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1399 | |
| 1400 | buffer_get_bignum2(m, p); |
| 1401 | |
| 1402 | rsafail = ssh1_session_key(p); |
| 1403 | |
| 1404 | buffer_clear(m); |
| 1405 | buffer_put_int(m, rsafail); |
| 1406 | buffer_put_bignum2(m, p); |
| 1407 | |
| 1408 | BN_clear_free(p); |
| 1409 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1410 | mm_request_send(sock, MONITOR_ANS_SESSKEY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1411 | |
| 1412 | /* Turn on permissions for sessid passing */ |
| 1413 | monitor_permit(mon_dispatch, MONITOR_REQ_SESSID, 1); |
| 1414 | |
| 1415 | return (0); |
| 1416 | } |
| 1417 | |
| 1418 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1419 | mm_answer_sessid(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1420 | { |
| 1421 | int i; |
| 1422 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1423 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1424 | |
| 1425 | if (buffer_len(m) != 16) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1426 | fatal("%s: bad ssh1 session id", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1427 | for (i = 0; i < 16; i++) |
| 1428 | session_id[i] = buffer_get_char(m); |
| 1429 | |
| 1430 | /* Turn on permissions for getpwnam */ |
| 1431 | monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1); |
| 1432 | |
| 1433 | return (0); |
| 1434 | } |
| 1435 | |
| 1436 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1437 | mm_answer_rsa_keyallowed(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1438 | { |
| 1439 | BIGNUM *client_n; |
| 1440 | Key *key = NULL; |
| 1441 | u_char *blob = NULL; |
| 1442 | u_int blen = 0; |
| 1443 | int allowed = 0; |
| 1444 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1445 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1446 | |
Damien Miller | 7a8f5b3 | 2006-03-31 23:14:23 +1100 | [diff] [blame] | 1447 | auth_method = "rsa"; |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 1448 | if (options.rsa_authentication && authctxt->valid) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1449 | if ((client_n = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1450 | fatal("%s: BN_new", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1451 | buffer_get_bignum2(m, client_n); |
| 1452 | allowed = auth_rsa_key_allowed(authctxt->pw, client_n, &key); |
| 1453 | BN_clear_free(client_n); |
| 1454 | } |
| 1455 | buffer_clear(m); |
| 1456 | buffer_put_int(m, allowed); |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1457 | buffer_put_int(m, forced_command != NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1458 | |
| 1459 | /* clear temporarily storage (used by generate challenge) */ |
| 1460 | monitor_reset_key_state(); |
| 1461 | |
| 1462 | if (allowed && key != NULL) { |
| 1463 | key->type = KEY_RSA; /* cheat for key_to_blob */ |
| 1464 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1465 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1466 | buffer_put_string(m, blob, blen); |
| 1467 | |
| 1468 | /* Save temporarily for comparison in verify */ |
| 1469 | key_blob = blob; |
| 1470 | key_bloblen = blen; |
| 1471 | key_blobtype = MM_RSAUSERKEY; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1472 | } |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1473 | if (key != NULL) |
| 1474 | key_free(key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1475 | |
| 1476 | mm_append_debug(m); |
| 1477 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1478 | mm_request_send(sock, MONITOR_ANS_RSAKEYALLOWED, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1479 | |
| 1480 | monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed); |
| 1481 | monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 0); |
| 1482 | return (0); |
| 1483 | } |
| 1484 | |
| 1485 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1486 | mm_answer_rsa_challenge(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1487 | { |
| 1488 | Key *key = NULL; |
| 1489 | u_char *blob; |
| 1490 | u_int blen; |
| 1491 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1492 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1493 | |
| 1494 | if (!authctxt->valid) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1495 | fatal("%s: authctxt not valid", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1496 | blob = buffer_get_string(m, &blen); |
| 1497 | if (!monitor_allowed_key(blob, blen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1498 | fatal("%s: bad key, not previously allowed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1499 | if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1500 | fatal("%s: key type mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1501 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1502 | fatal("%s: received bad key", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1503 | |
| 1504 | if (ssh1_challenge) |
| 1505 | BN_clear_free(ssh1_challenge); |
| 1506 | ssh1_challenge = auth_rsa_generate_challenge(key); |
| 1507 | |
| 1508 | buffer_clear(m); |
| 1509 | buffer_put_bignum2(m, ssh1_challenge); |
| 1510 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1511 | debug3("%s sending reply", __func__); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1512 | mm_request_send(sock, MONITOR_ANS_RSACHALLENGE, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1513 | |
| 1514 | monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1); |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1515 | |
| 1516 | xfree(blob); |
| 1517 | key_free(key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1518 | return (0); |
| 1519 | } |
| 1520 | |
| 1521 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1522 | mm_answer_rsa_response(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1523 | { |
| 1524 | Key *key = NULL; |
| 1525 | u_char *blob, *response; |
| 1526 | u_int blen, len; |
| 1527 | int success; |
| 1528 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1529 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1530 | |
| 1531 | if (!authctxt->valid) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1532 | fatal("%s: authctxt not valid", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1533 | if (ssh1_challenge == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1534 | fatal("%s: no ssh1_challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1535 | |
| 1536 | blob = buffer_get_string(m, &blen); |
| 1537 | if (!monitor_allowed_key(blob, blen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1538 | fatal("%s: bad key, not previously allowed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1539 | if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1540 | fatal("%s: key type mismatch: %d", __func__, key_blobtype); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1541 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1542 | fatal("%s: received bad key", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1543 | response = buffer_get_string(m, &len); |
| 1544 | if (len != 16) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1545 | fatal("%s: received bad response to challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1546 | success = auth_rsa_verify_response(key, ssh1_challenge, response); |
| 1547 | |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1548 | xfree(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1549 | key_free(key); |
| 1550 | xfree(response); |
| 1551 | |
| 1552 | auth_method = key_blobtype == MM_RSAUSERKEY ? "rsa" : "rhosts-rsa"; |
| 1553 | |
| 1554 | /* reset state */ |
| 1555 | BN_clear_free(ssh1_challenge); |
| 1556 | ssh1_challenge = NULL; |
| 1557 | monitor_reset_key_state(); |
| 1558 | |
| 1559 | buffer_clear(m); |
| 1560 | buffer_put_int(m, success); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1561 | mm_request_send(sock, MONITOR_ANS_RSARESPONSE, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1562 | |
| 1563 | return (success); |
| 1564 | } |
| 1565 | |
| 1566 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1567 | mm_answer_term(int sock, Buffer *req) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1568 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1569 | extern struct monitor *pmonitor; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1570 | int res, status; |
| 1571 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1572 | debug3("%s: tearing down sessions", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1573 | |
| 1574 | /* The child is terminating */ |
| 1575 | session_destroy_all(&mm_session_close); |
| 1576 | |
Darren Tucker | 52358d6 | 2008-03-11 22:58:25 +1100 | [diff] [blame] | 1577 | #ifdef USE_PAM |
| 1578 | if (options.use_pam) |
| 1579 | sshpam_cleanup(); |
| 1580 | #endif |
| 1581 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1582 | while (waitpid(pmonitor->m_pid, &status, 0) == -1) |
Ben Lindstrom | 47fd811 | 2002-04-02 20:48:19 +0000 | [diff] [blame] | 1583 | if (errno != EINTR) |
| 1584 | exit(1); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1585 | |
| 1586 | res = WIFEXITED(status) ? WEXITSTATUS(status) : 1; |
| 1587 | |
| 1588 | /* Terminate process */ |
Darren Tucker | 1f8311c | 2004-05-13 16:39:33 +1000 | [diff] [blame] | 1589 | exit(res); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1592 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1593 | /* Report that an audit event occurred */ |
| 1594 | int |
| 1595 | mm_answer_audit_event(int socket, Buffer *m) |
| 1596 | { |
| 1597 | ssh_audit_event_t event; |
| 1598 | |
| 1599 | debug3("%s entering", __func__); |
| 1600 | |
| 1601 | event = buffer_get_int(m); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1602 | switch(event) { |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1603 | case SSH_AUTH_FAIL_PUBKEY: |
| 1604 | case SSH_AUTH_FAIL_HOSTBASED: |
| 1605 | case SSH_AUTH_FAIL_GSSAPI: |
| 1606 | case SSH_LOGIN_EXCEED_MAXTRIES: |
| 1607 | case SSH_LOGIN_ROOT_DENIED: |
| 1608 | case SSH_CONNECTION_CLOSE: |
| 1609 | case SSH_INVALID_USER: |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1610 | audit_event(event); |
| 1611 | break; |
| 1612 | default: |
| 1613 | fatal("Audit event type %d not permitted", event); |
| 1614 | } |
| 1615 | |
| 1616 | return (0); |
| 1617 | } |
| 1618 | |
| 1619 | int |
| 1620 | mm_answer_audit_command(int socket, Buffer *m) |
| 1621 | { |
| 1622 | u_int len; |
| 1623 | char *cmd; |
| 1624 | |
| 1625 | debug3("%s entering", __func__); |
| 1626 | cmd = buffer_get_string(m, &len); |
| 1627 | /* sanity check command, if so how? */ |
| 1628 | audit_run_command(cmd); |
| 1629 | xfree(cmd); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1630 | return (0); |
| 1631 | } |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1632 | #endif /* SSH_AUDIT_EVENTS */ |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1633 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1634 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1635 | monitor_apply_keystate(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1636 | { |
| 1637 | if (compat20) { |
| 1638 | set_newkeys(MODE_IN); |
| 1639 | set_newkeys(MODE_OUT); |
| 1640 | } else { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1641 | packet_set_protocol_flags(child_state.ssh1protoflags); |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 1642 | packet_set_encryption_key(child_state.ssh1key, |
| 1643 | child_state.ssh1keylen, child_state.ssh1cipher); |
| 1644 | xfree(child_state.ssh1key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 1647 | /* for rc4 and other stateful ciphers */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1648 | packet_set_keycontext(MODE_OUT, child_state.keyout); |
| 1649 | xfree(child_state.keyout); |
| 1650 | packet_set_keycontext(MODE_IN, child_state.keyin); |
| 1651 | xfree(child_state.keyin); |
| 1652 | |
| 1653 | if (!compat20) { |
| 1654 | packet_set_iv(MODE_OUT, child_state.ivout); |
| 1655 | xfree(child_state.ivout); |
| 1656 | packet_set_iv(MODE_IN, child_state.ivin); |
| 1657 | xfree(child_state.ivin); |
| 1658 | } |
| 1659 | |
| 1660 | memcpy(&incoming_stream, &child_state.incoming, |
| 1661 | sizeof(incoming_stream)); |
| 1662 | memcpy(&outgoing_stream, &child_state.outgoing, |
| 1663 | sizeof(outgoing_stream)); |
| 1664 | |
| 1665 | /* Update with new address */ |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 1666 | if (options.compression) |
| 1667 | mm_init_compression(pmonitor->m_zlib); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1668 | |
| 1669 | /* Network I/O buffers */ |
| 1670 | /* XXX inefficient for large buffers, need: buffer_init_from_string */ |
| 1671 | buffer_clear(&input); |
| 1672 | buffer_append(&input, child_state.input, child_state.ilen); |
| 1673 | memset(child_state.input, 0, child_state.ilen); |
| 1674 | xfree(child_state.input); |
| 1675 | |
| 1676 | buffer_clear(&output); |
| 1677 | buffer_append(&output, child_state.output, child_state.olen); |
| 1678 | memset(child_state.output, 0, child_state.olen); |
| 1679 | xfree(child_state.output); |
| 1680 | } |
| 1681 | |
| 1682 | static Kex * |
| 1683 | mm_get_kex(Buffer *m) |
| 1684 | { |
| 1685 | Kex *kex; |
| 1686 | void *blob; |
| 1687 | u_int bloblen; |
| 1688 | |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 1689 | kex = xcalloc(1, sizeof(*kex)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1690 | kex->session_id = buffer_get_string(m, &kex->session_id_len); |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1691 | if ((session_id2 == NULL) || |
| 1692 | (kex->session_id_len != session_id2_len) || |
| 1693 | (memcmp(kex->session_id, session_id2, session_id2_len) != 0)) |
| 1694 | fatal("mm_get_get: internal error: bad session id"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1695 | kex->we_need = buffer_get_int(m); |
Damien Miller | b062c29 | 2003-03-24 09:12:09 +1100 | [diff] [blame] | 1696 | kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; |
Damien Miller | f675fc4 | 2004-06-15 10:30:09 +1000 | [diff] [blame] | 1697 | kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; |
Damien Miller | b062c29 | 2003-03-24 09:12:09 +1100 | [diff] [blame] | 1698 | kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; |
Damien Miller | a63128d | 2006-03-15 12:08:28 +1100 | [diff] [blame] | 1699 | kex->kex[KEX_DH_GEX_SHA256] = kexgex_server; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1700 | kex->server = 1; |
| 1701 | kex->hostkey_type = buffer_get_int(m); |
| 1702 | kex->kex_type = buffer_get_int(m); |
| 1703 | blob = buffer_get_string(m, &bloblen); |
| 1704 | buffer_init(&kex->my); |
| 1705 | buffer_append(&kex->my, blob, bloblen); |
| 1706 | xfree(blob); |
| 1707 | blob = buffer_get_string(m, &bloblen); |
| 1708 | buffer_init(&kex->peer); |
| 1709 | buffer_append(&kex->peer, blob, bloblen); |
| 1710 | xfree(blob); |
| 1711 | kex->done = 1; |
| 1712 | kex->flags = buffer_get_int(m); |
| 1713 | kex->client_version_string = buffer_get_string(m, NULL); |
| 1714 | kex->server_version_string = buffer_get_string(m, NULL); |
| 1715 | kex->load_host_key=&get_hostkey_by_type; |
| 1716 | kex->host_key_index=&get_hostkey_index; |
| 1717 | |
| 1718 | return (kex); |
| 1719 | } |
| 1720 | |
| 1721 | /* This function requries careful sanity checking */ |
| 1722 | |
| 1723 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1724 | mm_get_keystate(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1725 | { |
| 1726 | Buffer m; |
| 1727 | u_char *blob, *p; |
| 1728 | u_int bloblen, plen; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1729 | u_int32_t seqnr, packets; |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 1730 | u_int64_t blocks, bytes; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1731 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1732 | debug3("%s: Waiting for new keys", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1733 | |
| 1734 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1735 | mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1736 | if (!compat20) { |
| 1737 | child_state.ssh1protoflags = buffer_get_int(&m); |
| 1738 | child_state.ssh1cipher = buffer_get_int(&m); |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 1739 | child_state.ssh1key = buffer_get_string(&m, |
| 1740 | &child_state.ssh1keylen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1741 | child_state.ivout = buffer_get_string(&m, |
| 1742 | &child_state.ivoutlen); |
| 1743 | child_state.ivin = buffer_get_string(&m, &child_state.ivinlen); |
| 1744 | goto skip; |
| 1745 | } else { |
| 1746 | /* Get the Kex for rekeying */ |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1747 | *pmonitor->m_pkex = mm_get_kex(&m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | blob = buffer_get_string(&m, &bloblen); |
| 1751 | current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen); |
| 1752 | xfree(blob); |
| 1753 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1754 | debug3("%s: Waiting for second key", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1755 | blob = buffer_get_string(&m, &bloblen); |
| 1756 | current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen); |
| 1757 | xfree(blob); |
| 1758 | |
| 1759 | /* Now get sequence numbers for the packets */ |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1760 | seqnr = buffer_get_int(&m); |
| 1761 | blocks = buffer_get_int64(&m); |
| 1762 | packets = buffer_get_int(&m); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 1763 | bytes = buffer_get_int64(&m); |
| 1764 | packet_set_state(MODE_OUT, seqnr, blocks, packets, bytes); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1765 | seqnr = buffer_get_int(&m); |
| 1766 | blocks = buffer_get_int64(&m); |
| 1767 | packets = buffer_get_int(&m); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 1768 | bytes = buffer_get_int64(&m); |
| 1769 | packet_set_state(MODE_IN, seqnr, blocks, packets, bytes); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1770 | |
| 1771 | skip: |
| 1772 | /* Get the key context */ |
| 1773 | child_state.keyout = buffer_get_string(&m, &child_state.keyoutlen); |
| 1774 | child_state.keyin = buffer_get_string(&m, &child_state.keyinlen); |
| 1775 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1776 | debug3("%s: Getting compression state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1777 | /* Get compression state */ |
| 1778 | p = buffer_get_string(&m, &plen); |
| 1779 | if (plen != sizeof(child_state.outgoing)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1780 | fatal("%s: bad request size", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1781 | memcpy(&child_state.outgoing, p, sizeof(child_state.outgoing)); |
| 1782 | xfree(p); |
| 1783 | |
| 1784 | p = buffer_get_string(&m, &plen); |
| 1785 | if (plen != sizeof(child_state.incoming)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1786 | fatal("%s: bad request size", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1787 | memcpy(&child_state.incoming, p, sizeof(child_state.incoming)); |
| 1788 | xfree(p); |
| 1789 | |
| 1790 | /* Network I/O buffers */ |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1791 | debug3("%s: Getting Network I/O buffers", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1792 | child_state.input = buffer_get_string(&m, &child_state.ilen); |
| 1793 | child_state.output = buffer_get_string(&m, &child_state.olen); |
| 1794 | |
| 1795 | buffer_free(&m); |
| 1796 | } |
| 1797 | |
| 1798 | |
| 1799 | /* Allocation functions for zlib */ |
| 1800 | void * |
| 1801 | mm_zalloc(struct mm_master *mm, u_int ncount, u_int size) |
| 1802 | { |
Ben Lindstrom | 41ee2b0 | 2002-11-09 15:47:47 +0000 | [diff] [blame] | 1803 | size_t len = (size_t) size * ncount; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1804 | void *address; |
| 1805 | |
Ben Lindstrom | 0a4f754 | 2002-08-20 18:36:25 +0000 | [diff] [blame] | 1806 | if (len == 0 || ncount > SIZE_T_MAX / size) |
Damien Miller | 530a754 | 2002-06-26 23:27:11 +1000 | [diff] [blame] | 1807 | fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size); |
| 1808 | |
| 1809 | address = mm_malloc(mm, len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1810 | |
| 1811 | return (address); |
| 1812 | } |
| 1813 | |
| 1814 | void |
| 1815 | mm_zfree(struct mm_master *mm, void *address) |
| 1816 | { |
| 1817 | mm_free(mm, address); |
| 1818 | } |
| 1819 | |
| 1820 | void |
| 1821 | mm_init_compression(struct mm_master *mm) |
| 1822 | { |
| 1823 | outgoing_stream.zalloc = (alloc_func)mm_zalloc; |
| 1824 | outgoing_stream.zfree = (free_func)mm_zfree; |
| 1825 | outgoing_stream.opaque = mm; |
| 1826 | |
| 1827 | incoming_stream.zalloc = (alloc_func)mm_zalloc; |
| 1828 | incoming_stream.zfree = (free_func)mm_zfree; |
| 1829 | incoming_stream.opaque = mm; |
| 1830 | } |
| 1831 | |
| 1832 | /* XXX */ |
| 1833 | |
| 1834 | #define FD_CLOSEONEXEC(x) do { \ |
| 1835 | if (fcntl(x, F_SETFD, 1) == -1) \ |
| 1836 | fatal("fcntl(%d, F_SETFD)", x); \ |
| 1837 | } while (0) |
| 1838 | |
| 1839 | static void |
| 1840 | monitor_socketpair(int *pair) |
| 1841 | { |
Kevin Steves | fe6ca54 | 2002-04-10 22:04:54 +0000 | [diff] [blame] | 1842 | #ifdef HAVE_SOCKETPAIR |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1843 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1844 | fatal("%s: socketpair", __func__); |
Kevin Steves | fe6ca54 | 2002-04-10 22:04:54 +0000 | [diff] [blame] | 1845 | #else |
| 1846 | fatal("%s: UsePrivilegeSeparation=yes not supported", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1847 | __func__); |
Kevin Steves | fe6ca54 | 2002-04-10 22:04:54 +0000 | [diff] [blame] | 1848 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1849 | FD_CLOSEONEXEC(pair[0]); |
| 1850 | FD_CLOSEONEXEC(pair[1]); |
| 1851 | } |
| 1852 | |
| 1853 | #define MM_MEMSIZE 65536 |
| 1854 | |
| 1855 | struct monitor * |
| 1856 | monitor_init(void) |
| 1857 | { |
| 1858 | struct monitor *mon; |
| 1859 | int pair[2]; |
| 1860 | |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 1861 | mon = xcalloc(1, sizeof(*mon)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1862 | |
| 1863 | monitor_socketpair(pair); |
| 1864 | |
| 1865 | mon->m_recvfd = pair[0]; |
| 1866 | mon->m_sendfd = pair[1]; |
| 1867 | |
| 1868 | /* Used to share zlib space across processes */ |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 1869 | if (options.compression) { |
| 1870 | mon->m_zback = mm_create(NULL, MM_MEMSIZE); |
| 1871 | mon->m_zlib = mm_create(mon->m_zback, 20 * MM_MEMSIZE); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1872 | |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 1873 | /* Compression needs to share state across borders */ |
| 1874 | mm_init_compression(mon->m_zlib); |
| 1875 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1876 | |
| 1877 | return mon; |
| 1878 | } |
| 1879 | |
| 1880 | void |
| 1881 | monitor_reinit(struct monitor *mon) |
| 1882 | { |
| 1883 | int pair[2]; |
| 1884 | |
| 1885 | monitor_socketpair(pair); |
| 1886 | |
| 1887 | mon->m_recvfd = pair[0]; |
| 1888 | mon->m_sendfd = pair[1]; |
| 1889 | } |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1890 | |
| 1891 | #ifdef GSSAPI |
| 1892 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1893 | mm_answer_gss_setup_ctx(int sock, Buffer *m) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1894 | { |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1895 | gss_OID_desc goid; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1896 | OM_uint32 major; |
| 1897 | u_int len; |
| 1898 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1899 | goid.elements = buffer_get_string(m, &len); |
| 1900 | goid.length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1901 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1902 | major = ssh_gssapi_server_ctx(&gsscontext, &goid); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1903 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1904 | xfree(goid.elements); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1905 | |
| 1906 | buffer_clear(m); |
| 1907 | buffer_put_int(m, major); |
| 1908 | |
Damien Miller | 6fd6def | 2005-11-05 15:07:05 +1100 | [diff] [blame] | 1909 | mm_request_send(sock, MONITOR_ANS_GSSSETUP, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1910 | |
| 1911 | /* Now we have a context, enable the step */ |
| 1912 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 1); |
| 1913 | |
| 1914 | return (0); |
| 1915 | } |
| 1916 | |
| 1917 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1918 | mm_answer_gss_accept_ctx(int sock, Buffer *m) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1919 | { |
| 1920 | gss_buffer_desc in; |
| 1921 | gss_buffer_desc out = GSS_C_EMPTY_BUFFER; |
Damien Miller | 6fd6def | 2005-11-05 15:07:05 +1100 | [diff] [blame] | 1922 | OM_uint32 major, minor; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1923 | OM_uint32 flags = 0; /* GSI needs this */ |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1924 | u_int len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1925 | |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1926 | in.value = buffer_get_string(m, &len); |
| 1927 | in.length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1928 | major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags); |
| 1929 | xfree(in.value); |
| 1930 | |
| 1931 | buffer_clear(m); |
| 1932 | buffer_put_int(m, major); |
| 1933 | buffer_put_string(m, out.value, out.length); |
| 1934 | buffer_put_int(m, flags); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1935 | mm_request_send(sock, MONITOR_ANS_GSSSTEP, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1936 | |
| 1937 | gss_release_buffer(&minor, &out); |
| 1938 | |
Damien Miller | 6fd6def | 2005-11-05 15:07:05 +1100 | [diff] [blame] | 1939 | if (major == GSS_S_COMPLETE) { |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1940 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0); |
| 1941 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1942 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1943 | } |
| 1944 | return (0); |
| 1945 | } |
| 1946 | |
| 1947 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1948 | mm_answer_gss_checkmic(int sock, Buffer *m) |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1949 | { |
| 1950 | gss_buffer_desc gssbuf, mic; |
| 1951 | OM_uint32 ret; |
| 1952 | u_int len; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1953 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1954 | gssbuf.value = buffer_get_string(m, &len); |
| 1955 | gssbuf.length = len; |
| 1956 | mic.value = buffer_get_string(m, &len); |
| 1957 | mic.length = len; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1958 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1959 | ret = ssh_gssapi_checkmic(gsscontext, &gssbuf, &mic); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1960 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1961 | xfree(gssbuf.value); |
| 1962 | xfree(mic.value); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1963 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1964 | buffer_clear(m); |
| 1965 | buffer_put_int(m, ret); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1966 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1967 | mm_request_send(sock, MONITOR_ANS_GSSCHECKMIC, m); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1968 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1969 | if (!GSS_ERROR(ret)) |
| 1970 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1971 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1972 | return (0); |
| 1973 | } |
| 1974 | |
| 1975 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1976 | mm_answer_gss_userok(int sock, Buffer *m) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1977 | { |
| 1978 | int authenticated; |
| 1979 | |
| 1980 | authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user); |
| 1981 | |
| 1982 | buffer_clear(m); |
| 1983 | buffer_put_int(m, authenticated); |
| 1984 | |
| 1985 | debug3("%s: sending result %d", __func__, authenticated); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1986 | mm_request_send(sock, MONITOR_ANS_GSSUSEROK, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1987 | |
Damien Miller | 6fd6def | 2005-11-05 15:07:05 +1100 | [diff] [blame] | 1988 | auth_method = "gssapi-with-mic"; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1989 | |
| 1990 | /* Monitor loop will terminate if authenticated */ |
| 1991 | return (authenticated); |
| 1992 | } |
| 1993 | #endif /* GSSAPI */ |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1994 | |
| 1995 | #ifdef JPAKE |
| 1996 | int |
| 1997 | mm_answer_jpake_step1(int sock, Buffer *m) |
| 1998 | { |
| 1999 | struct jpake_ctx *pctx; |
| 2000 | u_char *x3_proof, *x4_proof; |
| 2001 | u_int x3_proof_len, x4_proof_len; |
| 2002 | |
| 2003 | if (!options.zero_knowledge_password_authentication) |
| 2004 | fatal("zero_knowledge_password_authentication disabled"); |
| 2005 | |
| 2006 | if (authctxt->jpake_ctx != NULL) |
| 2007 | fatal("%s: authctxt->jpake_ctx already set (%p)", |
| 2008 | __func__, authctxt->jpake_ctx); |
| 2009 | authctxt->jpake_ctx = pctx = jpake_new(); |
| 2010 | |
| 2011 | jpake_step1(pctx->grp, |
| 2012 | &pctx->server_id, &pctx->server_id_len, |
| 2013 | &pctx->x3, &pctx->x4, &pctx->g_x3, &pctx->g_x4, |
| 2014 | &x3_proof, &x3_proof_len, |
| 2015 | &x4_proof, &x4_proof_len); |
| 2016 | |
| 2017 | JPAKE_DEBUG_CTX((pctx, "step1 done in %s", __func__)); |
| 2018 | |
| 2019 | buffer_clear(m); |
| 2020 | |
| 2021 | buffer_put_string(m, pctx->server_id, pctx->server_id_len); |
| 2022 | buffer_put_bignum2(m, pctx->g_x3); |
| 2023 | buffer_put_bignum2(m, pctx->g_x4); |
| 2024 | buffer_put_string(m, x3_proof, x3_proof_len); |
| 2025 | buffer_put_string(m, x4_proof, x4_proof_len); |
| 2026 | |
| 2027 | debug3("%s: sending step1", __func__); |
| 2028 | mm_request_send(sock, MONITOR_ANS_JPAKE_STEP1, m); |
| 2029 | |
| 2030 | bzero(x3_proof, x3_proof_len); |
| 2031 | bzero(x4_proof, x4_proof_len); |
| 2032 | xfree(x3_proof); |
| 2033 | xfree(x4_proof); |
| 2034 | |
| 2035 | monitor_permit(mon_dispatch, MONITOR_REQ_JPAKE_GET_PWDATA, 1); |
| 2036 | monitor_permit(mon_dispatch, MONITOR_REQ_JPAKE_STEP1, 0); |
| 2037 | |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
| 2041 | int |
| 2042 | mm_answer_jpake_get_pwdata(int sock, Buffer *m) |
| 2043 | { |
| 2044 | struct jpake_ctx *pctx = authctxt->jpake_ctx; |
| 2045 | char *hash_scheme, *salt; |
| 2046 | |
| 2047 | if (pctx == NULL) |
| 2048 | fatal("%s: pctx == NULL", __func__); |
| 2049 | |
| 2050 | auth2_jpake_get_pwdata(authctxt, &pctx->s, &hash_scheme, &salt); |
| 2051 | |
| 2052 | buffer_clear(m); |
| 2053 | /* pctx->s is sensitive, not returned to slave */ |
| 2054 | buffer_put_cstring(m, hash_scheme); |
| 2055 | buffer_put_cstring(m, salt); |
| 2056 | |
| 2057 | debug3("%s: sending pwdata", __func__); |
| 2058 | mm_request_send(sock, MONITOR_ANS_JPAKE_GET_PWDATA, m); |
| 2059 | |
| 2060 | bzero(hash_scheme, strlen(hash_scheme)); |
| 2061 | bzero(salt, strlen(salt)); |
| 2062 | xfree(hash_scheme); |
| 2063 | xfree(salt); |
| 2064 | |
| 2065 | monitor_permit(mon_dispatch, MONITOR_REQ_JPAKE_STEP2, 1); |
| 2066 | |
| 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | int |
| 2071 | mm_answer_jpake_step2(int sock, Buffer *m) |
| 2072 | { |
| 2073 | struct jpake_ctx *pctx = authctxt->jpake_ctx; |
| 2074 | u_char *x1_proof, *x2_proof, *x4_s_proof; |
| 2075 | u_int x1_proof_len, x2_proof_len, x4_s_proof_len; |
| 2076 | |
| 2077 | if (pctx == NULL) |
| 2078 | fatal("%s: pctx == NULL", __func__); |
| 2079 | |
| 2080 | if ((pctx->g_x1 = BN_new()) == NULL || |
| 2081 | (pctx->g_x2 = BN_new()) == NULL) |
| 2082 | fatal("%s: BN_new", __func__); |
| 2083 | buffer_get_bignum2(m, pctx->g_x1); |
| 2084 | buffer_get_bignum2(m, pctx->g_x2); |
| 2085 | pctx->client_id = buffer_get_string(m, &pctx->client_id_len); |
| 2086 | x1_proof = buffer_get_string(m, &x1_proof_len); |
| 2087 | x2_proof = buffer_get_string(m, &x2_proof_len); |
| 2088 | |
| 2089 | jpake_step2(pctx->grp, pctx->s, pctx->g_x3, |
| 2090 | pctx->g_x1, pctx->g_x2, pctx->x4, |
| 2091 | pctx->client_id, pctx->client_id_len, |
| 2092 | pctx->server_id, pctx->server_id_len, |
| 2093 | x1_proof, x1_proof_len, |
| 2094 | x2_proof, x2_proof_len, |
| 2095 | &pctx->b, |
| 2096 | &x4_s_proof, &x4_s_proof_len); |
| 2097 | |
| 2098 | JPAKE_DEBUG_CTX((pctx, "step2 done in %s", __func__)); |
| 2099 | |
| 2100 | bzero(x1_proof, x1_proof_len); |
| 2101 | bzero(x2_proof, x2_proof_len); |
| 2102 | xfree(x1_proof); |
| 2103 | xfree(x2_proof); |
| 2104 | |
| 2105 | buffer_clear(m); |
| 2106 | |
| 2107 | buffer_put_bignum2(m, pctx->b); |
| 2108 | buffer_put_string(m, x4_s_proof, x4_s_proof_len); |
| 2109 | |
| 2110 | debug3("%s: sending step2", __func__); |
| 2111 | mm_request_send(sock, MONITOR_ANS_JPAKE_STEP2, m); |
| 2112 | |
| 2113 | bzero(x4_s_proof, x4_s_proof_len); |
| 2114 | xfree(x4_s_proof); |
| 2115 | |
| 2116 | monitor_permit(mon_dispatch, MONITOR_REQ_JPAKE_KEY_CONFIRM, 1); |
| 2117 | |
| 2118 | return 0; |
| 2119 | } |
| 2120 | |
| 2121 | int |
| 2122 | mm_answer_jpake_key_confirm(int sock, Buffer *m) |
| 2123 | { |
| 2124 | struct jpake_ctx *pctx = authctxt->jpake_ctx; |
| 2125 | u_char *x2_s_proof; |
| 2126 | u_int x2_s_proof_len; |
| 2127 | |
| 2128 | if (pctx == NULL) |
| 2129 | fatal("%s: pctx == NULL", __func__); |
| 2130 | |
| 2131 | if ((pctx->a = BN_new()) == NULL) |
| 2132 | fatal("%s: BN_new", __func__); |
| 2133 | buffer_get_bignum2(m, pctx->a); |
| 2134 | x2_s_proof = buffer_get_string(m, &x2_s_proof_len); |
| 2135 | |
| 2136 | jpake_key_confirm(pctx->grp, pctx->s, pctx->a, |
| 2137 | pctx->x4, pctx->g_x3, pctx->g_x4, pctx->g_x1, pctx->g_x2, |
| 2138 | pctx->server_id, pctx->server_id_len, |
| 2139 | pctx->client_id, pctx->client_id_len, |
| 2140 | session_id2, session_id2_len, |
| 2141 | x2_s_proof, x2_s_proof_len, |
| 2142 | &pctx->k, |
| 2143 | &pctx->h_k_sid_sessid, &pctx->h_k_sid_sessid_len); |
| 2144 | |
| 2145 | JPAKE_DEBUG_CTX((pctx, "key_confirm done in %s", __func__)); |
| 2146 | |
| 2147 | bzero(x2_s_proof, x2_s_proof_len); |
| 2148 | buffer_clear(m); |
| 2149 | |
| 2150 | /* pctx->k is sensitive, not sent */ |
| 2151 | buffer_put_string(m, pctx->h_k_sid_sessid, pctx->h_k_sid_sessid_len); |
| 2152 | |
| 2153 | debug3("%s: sending confirmation hash", __func__); |
| 2154 | mm_request_send(sock, MONITOR_ANS_JPAKE_KEY_CONFIRM, m); |
| 2155 | |
| 2156 | monitor_permit(mon_dispatch, MONITOR_REQ_JPAKE_CHECK_CONFIRM, 1); |
| 2157 | |
| 2158 | return 0; |
| 2159 | } |
| 2160 | |
| 2161 | int |
| 2162 | mm_answer_jpake_check_confirm(int sock, Buffer *m) |
| 2163 | { |
| 2164 | int authenticated = 0; |
| 2165 | u_char *peer_confirm_hash; |
| 2166 | u_int peer_confirm_hash_len; |
| 2167 | struct jpake_ctx *pctx = authctxt->jpake_ctx; |
| 2168 | |
| 2169 | if (pctx == NULL) |
| 2170 | fatal("%s: pctx == NULL", __func__); |
| 2171 | |
| 2172 | peer_confirm_hash = buffer_get_string(m, &peer_confirm_hash_len); |
| 2173 | |
| 2174 | authenticated = jpake_check_confirm(pctx->k, |
| 2175 | pctx->client_id, pctx->client_id_len, |
| 2176 | session_id2, session_id2_len, |
| 2177 | peer_confirm_hash, peer_confirm_hash_len) && authctxt->valid; |
| 2178 | |
| 2179 | JPAKE_DEBUG_CTX((pctx, "check_confirm done in %s", __func__)); |
| 2180 | |
| 2181 | bzero(peer_confirm_hash, peer_confirm_hash_len); |
| 2182 | xfree(peer_confirm_hash); |
| 2183 | |
| 2184 | buffer_clear(m); |
| 2185 | buffer_put_int(m, authenticated); |
| 2186 | |
| 2187 | debug3("%s: sending result %d", __func__, authenticated); |
| 2188 | mm_request_send(sock, MONITOR_ANS_JPAKE_CHECK_CONFIRM, m); |
| 2189 | |
| 2190 | monitor_permit(mon_dispatch, MONITOR_REQ_JPAKE_STEP1, 1); |
| 2191 | |
| 2192 | auth_method = "jpake-01@openssh.com"; |
| 2193 | return authenticated; |
| 2194 | } |
| 2195 | |
| 2196 | #endif /* JPAKE */ |