Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
| 3 | * Copyright 2002 Markus Friedl <markus@openbsd.org> |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "includes.h" |
Darren Tucker | 6aaa58c | 2003-08-02 22:24:49 +1000 | [diff] [blame^] | 28 | RCSID("$OpenBSD: monitor_wrap.c,v 1.28 2003/07/22 13:35:22 markus Exp $"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 29 | |
| 30 | #include <openssl/bn.h> |
| 31 | #include <openssl/dh.h> |
| 32 | |
| 33 | #include "ssh.h" |
| 34 | #include "dh.h" |
| 35 | #include "kex.h" |
| 36 | #include "auth.h" |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 37 | #include "auth-options.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 38 | #include "buffer.h" |
| 39 | #include "bufaux.h" |
| 40 | #include "packet.h" |
| 41 | #include "mac.h" |
| 42 | #include "log.h" |
| 43 | #include "zlib.h" |
| 44 | #include "monitor.h" |
| 45 | #include "monitor_wrap.h" |
| 46 | #include "xmalloc.h" |
| 47 | #include "atomicio.h" |
| 48 | #include "monitor_fdpass.h" |
| 49 | #include "getput.h" |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 50 | #include "servconf.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 51 | |
| 52 | #include "auth.h" |
| 53 | #include "channels.h" |
| 54 | #include "session.h" |
| 55 | |
| 56 | /* Imports */ |
| 57 | extern int compat20; |
| 58 | extern Newkeys *newkeys[]; |
| 59 | extern z_stream incoming_stream; |
| 60 | extern z_stream outgoing_stream; |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 61 | extern struct monitor *pmonitor; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 62 | extern Buffer input, output; |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 63 | extern ServerOptions options; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 64 | |
| 65 | void |
| 66 | mm_request_send(int socket, enum monitor_reqtype type, Buffer *m) |
| 67 | { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 68 | u_int mlen = buffer_len(m); |
Ben Lindstrom | b1bdc5a | 2002-07-04 00:09:26 +0000 | [diff] [blame] | 69 | u_char buf[5]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 70 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 71 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 72 | |
| 73 | PUT_32BIT(buf, mlen + 1); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 74 | buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */ |
Darren Tucker | 9f63f22 | 2003-07-03 13:46:56 +1000 | [diff] [blame] | 75 | if (atomicio(vwrite, socket, buf, sizeof(buf)) != sizeof(buf)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 76 | fatal("%s: write", __func__); |
Darren Tucker | 9f63f22 | 2003-07-03 13:46:56 +1000 | [diff] [blame] | 77 | if (atomicio(vwrite, socket, buffer_ptr(m), mlen) != mlen) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 78 | fatal("%s: write", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void |
| 82 | mm_request_receive(int socket, Buffer *m) |
| 83 | { |
| 84 | u_char buf[4]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 85 | u_int msg_len; |
Ben Lindstrom | b1bdc5a | 2002-07-04 00:09:26 +0000 | [diff] [blame] | 86 | ssize_t res; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 87 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 88 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 89 | |
| 90 | res = atomicio(read, socket, buf, sizeof(buf)); |
| 91 | if (res != sizeof(buf)) { |
| 92 | if (res == 0) |
| 93 | fatal_cleanup(); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 94 | fatal("%s: read: %ld", __func__, (long)res); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 95 | } |
| 96 | msg_len = GET_32BIT(buf); |
| 97 | if (msg_len > 256 * 1024) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 98 | fatal("%s: read: bad msg_len %d", __func__, msg_len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 99 | buffer_clear(m); |
| 100 | buffer_append_space(m, msg_len); |
| 101 | res = atomicio(read, socket, buffer_ptr(m), msg_len); |
| 102 | if (res != msg_len) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 103 | fatal("%s: read: %ld != msg_len", __func__, (long)res); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void |
| 107 | mm_request_receive_expect(int socket, enum monitor_reqtype type, Buffer *m) |
| 108 | { |
| 109 | u_char rtype; |
| 110 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 111 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 112 | |
| 113 | mm_request_receive(socket, m); |
| 114 | rtype = buffer_get_char(m); |
| 115 | if (rtype != type) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 116 | fatal("%s: read: rtype %d != type %d", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 117 | rtype, type); |
| 118 | } |
| 119 | |
| 120 | DH * |
| 121 | mm_choose_dh(int min, int nbits, int max) |
| 122 | { |
| 123 | BIGNUM *p, *g; |
| 124 | int success = 0; |
| 125 | Buffer m; |
| 126 | |
| 127 | buffer_init(&m); |
| 128 | buffer_put_int(&m, min); |
| 129 | buffer_put_int(&m, nbits); |
| 130 | buffer_put_int(&m, max); |
| 131 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 132 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 133 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 134 | debug3("%s: waiting for MONITOR_ANS_MODULI", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 135 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 136 | |
| 137 | success = buffer_get_char(&m); |
| 138 | if (success == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 139 | fatal("%s: MONITOR_ANS_MODULI failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 140 | |
| 141 | if ((p = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 142 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 143 | if ((g = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 144 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 145 | buffer_get_bignum2(&m, p); |
| 146 | buffer_get_bignum2(&m, g); |
| 147 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 148 | debug3("%s: remaining %d", __func__, buffer_len(&m)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 149 | buffer_free(&m); |
| 150 | |
| 151 | return (dh_new_group(g, p)); |
| 152 | } |
| 153 | |
| 154 | int |
| 155 | mm_key_sign(Key *key, u_char **sigp, u_int *lenp, u_char *data, u_int datalen) |
| 156 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 157 | Kex *kex = *pmonitor->m_pkex; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 158 | Buffer m; |
| 159 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 160 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 161 | |
| 162 | buffer_init(&m); |
| 163 | buffer_put_int(&m, kex->host_key_index(key)); |
| 164 | buffer_put_string(&m, data, datalen); |
| 165 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 166 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 167 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 168 | debug3("%s: waiting for MONITOR_ANS_SIGN", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 169 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 170 | *sigp = buffer_get_string(&m, lenp); |
| 171 | buffer_free(&m); |
| 172 | |
| 173 | return (0); |
| 174 | } |
| 175 | |
| 176 | struct passwd * |
| 177 | mm_getpwnamallow(const char *login) |
| 178 | { |
| 179 | Buffer m; |
| 180 | struct passwd *pw; |
| 181 | u_int pwlen; |
| 182 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 183 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 184 | |
| 185 | buffer_init(&m); |
| 186 | buffer_put_cstring(&m, login); |
| 187 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 188 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 189 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 190 | debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 191 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 192 | |
| 193 | if (buffer_get_char(&m) == 0) { |
| 194 | buffer_free(&m); |
| 195 | return (NULL); |
| 196 | } |
| 197 | pw = buffer_get_string(&m, &pwlen); |
| 198 | if (pwlen != sizeof(struct passwd)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 199 | fatal("%s: struct passwd size mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 200 | pw->pw_name = buffer_get_string(&m, NULL); |
| 201 | pw->pw_passwd = buffer_get_string(&m, NULL); |
| 202 | pw->pw_gecos = buffer_get_string(&m, NULL); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 203 | #ifdef HAVE_PW_CLASS_IN_PASSWD |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 204 | pw->pw_class = buffer_get_string(&m, NULL); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 205 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 206 | pw->pw_dir = buffer_get_string(&m, NULL); |
| 207 | pw->pw_shell = buffer_get_string(&m, NULL); |
| 208 | buffer_free(&m); |
| 209 | |
| 210 | return (pw); |
| 211 | } |
| 212 | |
Ben Lindstrom | a962c2f | 2002-07-04 00:14:17 +0000 | [diff] [blame] | 213 | char *mm_auth2_read_banner(void) |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 214 | { |
| 215 | Buffer m; |
| 216 | char *banner; |
| 217 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 218 | debug3("%s entering", __func__); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 219 | |
| 220 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 221 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 222 | buffer_clear(&m); |
| 223 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 224 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTH2_READ_BANNER, &m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 225 | banner = buffer_get_string(&m, NULL); |
| 226 | buffer_free(&m); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 227 | |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 228 | return (banner); |
| 229 | } |
| 230 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 231 | /* Inform the privileged process about service and style */ |
| 232 | |
| 233 | void |
| 234 | mm_inform_authserv(char *service, char *style) |
| 235 | { |
| 236 | Buffer m; |
| 237 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 238 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 239 | |
| 240 | buffer_init(&m); |
| 241 | buffer_put_cstring(&m, service); |
| 242 | buffer_put_cstring(&m, style ? style : ""); |
| 243 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 244 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 245 | |
| 246 | buffer_free(&m); |
| 247 | } |
| 248 | |
| 249 | /* Do the password authentication */ |
| 250 | int |
| 251 | mm_auth_password(Authctxt *authctxt, char *password) |
| 252 | { |
| 253 | Buffer m; |
| 254 | int authenticated = 0; |
| 255 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 256 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 257 | |
| 258 | buffer_init(&m); |
| 259 | buffer_put_cstring(&m, password); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 260 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 261 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 262 | debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 263 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 264 | |
| 265 | authenticated = buffer_get_int(&m); |
| 266 | |
| 267 | buffer_free(&m); |
| 268 | |
| 269 | debug3("%s: user %sauthenticated", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 270 | __func__, authenticated ? "" : "not "); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 271 | return (authenticated); |
| 272 | } |
| 273 | |
| 274 | int |
| 275 | mm_user_key_allowed(struct passwd *pw, Key *key) |
| 276 | { |
| 277 | return (mm_key_allowed(MM_USERKEY, NULL, NULL, key)); |
| 278 | } |
| 279 | |
| 280 | int |
| 281 | mm_hostbased_key_allowed(struct passwd *pw, char *user, char *host, |
| 282 | Key *key) |
| 283 | { |
| 284 | return (mm_key_allowed(MM_HOSTKEY, user, host, key)); |
| 285 | } |
| 286 | |
| 287 | int |
| 288 | mm_auth_rhosts_rsa_key_allowed(struct passwd *pw, char *user, |
| 289 | char *host, Key *key) |
| 290 | { |
| 291 | int ret; |
| 292 | |
| 293 | key->type = KEY_RSA; /* XXX hack for key_to_blob */ |
| 294 | ret = mm_key_allowed(MM_RSAHOSTKEY, user, host, key); |
| 295 | key->type = KEY_RSA1; |
| 296 | return (ret); |
| 297 | } |
| 298 | |
| 299 | static void |
| 300 | mm_send_debug(Buffer *m) |
| 301 | { |
| 302 | char *msg; |
| 303 | |
| 304 | while (buffer_len(m)) { |
| 305 | msg = buffer_get_string(m, NULL); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 306 | debug3("%s: Sending debug: %s", __func__, msg); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 307 | packet_send_debug("%s", msg); |
| 308 | xfree(msg); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | int |
| 313 | mm_key_allowed(enum mm_keytype type, char *user, char *host, Key *key) |
| 314 | { |
| 315 | Buffer m; |
| 316 | u_char *blob; |
| 317 | u_int len; |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 318 | int allowed = 0, have_forced = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 319 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 320 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 321 | |
| 322 | /* Convert the key to a blob and the pass it over */ |
| 323 | if (!key_to_blob(key, &blob, &len)) |
| 324 | return (0); |
| 325 | |
| 326 | buffer_init(&m); |
| 327 | buffer_put_int(&m, type); |
| 328 | buffer_put_cstring(&m, user ? user : ""); |
| 329 | buffer_put_cstring(&m, host ? host : ""); |
| 330 | buffer_put_string(&m, blob, len); |
| 331 | xfree(blob); |
| 332 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 333 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 334 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 335 | debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 336 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 337 | |
| 338 | allowed = buffer_get_int(&m); |
| 339 | |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 340 | /* fake forced command */ |
| 341 | auth_clear_options(); |
| 342 | have_forced = buffer_get_int(&m); |
| 343 | forced_command = have_forced ? xstrdup("true") : NULL; |
| 344 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 345 | /* Send potential debug messages */ |
| 346 | mm_send_debug(&m); |
| 347 | |
| 348 | buffer_free(&m); |
| 349 | |
| 350 | return (allowed); |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | * This key verify needs to send the key type along, because the |
| 355 | * privileged parent makes the decision if the key is allowed |
| 356 | * for authentication. |
| 357 | */ |
| 358 | |
| 359 | int |
| 360 | mm_key_verify(Key *key, u_char *sig, u_int siglen, u_char *data, u_int datalen) |
| 361 | { |
| 362 | Buffer m; |
| 363 | u_char *blob; |
| 364 | u_int len; |
| 365 | int verified = 0; |
| 366 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 367 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 368 | |
| 369 | /* Convert the key to a blob and the pass it over */ |
| 370 | if (!key_to_blob(key, &blob, &len)) |
| 371 | return (0); |
| 372 | |
| 373 | buffer_init(&m); |
| 374 | buffer_put_string(&m, blob, len); |
| 375 | buffer_put_string(&m, sig, siglen); |
| 376 | buffer_put_string(&m, data, datalen); |
| 377 | xfree(blob); |
| 378 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 379 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 380 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 381 | debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 382 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 383 | |
| 384 | verified = buffer_get_int(&m); |
| 385 | |
| 386 | buffer_free(&m); |
| 387 | |
| 388 | return (verified); |
| 389 | } |
| 390 | |
| 391 | /* Export key state after authentication */ |
| 392 | Newkeys * |
| 393 | mm_newkeys_from_blob(u_char *blob, int blen) |
| 394 | { |
| 395 | Buffer b; |
| 396 | u_int len; |
| 397 | Newkeys *newkey = NULL; |
| 398 | Enc *enc; |
| 399 | Mac *mac; |
| 400 | Comp *comp; |
| 401 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 402 | debug3("%s: %p(%d)", __func__, blob, blen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 403 | #ifdef DEBUG_PK |
| 404 | dump_base64(stderr, blob, blen); |
| 405 | #endif |
| 406 | buffer_init(&b); |
| 407 | buffer_append(&b, blob, blen); |
| 408 | |
| 409 | newkey = xmalloc(sizeof(*newkey)); |
| 410 | enc = &newkey->enc; |
| 411 | mac = &newkey->mac; |
| 412 | comp = &newkey->comp; |
| 413 | |
| 414 | /* Enc structure */ |
| 415 | enc->name = buffer_get_string(&b, NULL); |
| 416 | buffer_get(&b, &enc->cipher, sizeof(enc->cipher)); |
| 417 | enc->enabled = buffer_get_int(&b); |
| 418 | enc->block_size = buffer_get_int(&b); |
| 419 | enc->key = buffer_get_string(&b, &enc->key_len); |
| 420 | enc->iv = buffer_get_string(&b, &len); |
| 421 | if (len != enc->block_size) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 422 | fatal("%s: bad ivlen: expected %u != %u", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 423 | enc->block_size, len); |
| 424 | |
| 425 | if (enc->name == NULL || cipher_by_name(enc->name) != enc->cipher) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 426 | fatal("%s: bad cipher name %s or pointer %p", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 427 | enc->name, enc->cipher); |
| 428 | |
| 429 | /* Mac structure */ |
| 430 | mac->name = buffer_get_string(&b, NULL); |
| 431 | if (mac->name == NULL || mac_init(mac, mac->name) == -1) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 432 | fatal("%s: can not init mac %s", __func__, mac->name); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 433 | mac->enabled = buffer_get_int(&b); |
| 434 | mac->key = buffer_get_string(&b, &len); |
| 435 | if (len > mac->key_len) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 436 | fatal("%s: bad mac key length: %u > %d", __func__, len, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 437 | mac->key_len); |
| 438 | mac->key_len = len; |
| 439 | |
| 440 | /* Comp structure */ |
| 441 | comp->type = buffer_get_int(&b); |
| 442 | comp->enabled = buffer_get_int(&b); |
| 443 | comp->name = buffer_get_string(&b, NULL); |
| 444 | |
| 445 | len = buffer_len(&b); |
| 446 | if (len != 0) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 447 | error("newkeys_from_blob: remaining bytes in blob %u", len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 448 | buffer_free(&b); |
| 449 | return (newkey); |
| 450 | } |
| 451 | |
| 452 | int |
| 453 | mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp) |
| 454 | { |
| 455 | Buffer b; |
| 456 | int len; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 457 | Enc *enc; |
| 458 | Mac *mac; |
| 459 | Comp *comp; |
| 460 | Newkeys *newkey = newkeys[mode]; |
| 461 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 462 | debug3("%s: converting %p", __func__, newkey); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 463 | |
| 464 | if (newkey == NULL) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 465 | error("%s: newkey == NULL", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | enc = &newkey->enc; |
| 469 | mac = &newkey->mac; |
| 470 | comp = &newkey->comp; |
| 471 | |
| 472 | buffer_init(&b); |
| 473 | /* Enc structure */ |
| 474 | buffer_put_cstring(&b, enc->name); |
| 475 | /* The cipher struct is constant and shared, you export pointer */ |
| 476 | buffer_append(&b, &enc->cipher, sizeof(enc->cipher)); |
| 477 | buffer_put_int(&b, enc->enabled); |
| 478 | buffer_put_int(&b, enc->block_size); |
| 479 | buffer_put_string(&b, enc->key, enc->key_len); |
| 480 | packet_get_keyiv(mode, enc->iv, enc->block_size); |
| 481 | buffer_put_string(&b, enc->iv, enc->block_size); |
| 482 | |
| 483 | /* Mac structure */ |
| 484 | buffer_put_cstring(&b, mac->name); |
| 485 | buffer_put_int(&b, mac->enabled); |
| 486 | buffer_put_string(&b, mac->key, mac->key_len); |
| 487 | |
| 488 | /* Comp structure */ |
| 489 | buffer_put_int(&b, comp->type); |
| 490 | buffer_put_int(&b, comp->enabled); |
| 491 | buffer_put_cstring(&b, comp->name); |
| 492 | |
| 493 | len = buffer_len(&b); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 494 | if (lenp != NULL) |
| 495 | *lenp = len; |
Ben Lindstrom | 2bf759c | 2002-07-07 22:13:31 +0000 | [diff] [blame] | 496 | if (blobp != NULL) { |
| 497 | *blobp = xmalloc(len); |
| 498 | memcpy(*blobp, buffer_ptr(&b), len); |
| 499 | } |
| 500 | memset(buffer_ptr(&b), 0, len); |
| 501 | buffer_free(&b); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 502 | return len; |
| 503 | } |
| 504 | |
| 505 | static void |
| 506 | mm_send_kex(Buffer *m, Kex *kex) |
| 507 | { |
| 508 | buffer_put_string(m, kex->session_id, kex->session_id_len); |
| 509 | buffer_put_int(m, kex->we_need); |
| 510 | buffer_put_int(m, kex->hostkey_type); |
| 511 | buffer_put_int(m, kex->kex_type); |
| 512 | buffer_put_string(m, buffer_ptr(&kex->my), buffer_len(&kex->my)); |
| 513 | buffer_put_string(m, buffer_ptr(&kex->peer), buffer_len(&kex->peer)); |
| 514 | buffer_put_int(m, kex->flags); |
| 515 | buffer_put_cstring(m, kex->client_version_string); |
| 516 | buffer_put_cstring(m, kex->server_version_string); |
| 517 | } |
| 518 | |
| 519 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 520 | mm_send_keystate(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 521 | { |
| 522 | Buffer m; |
| 523 | u_char *blob, *p; |
| 524 | u_int bloblen, plen; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 525 | u_int32_t seqnr, packets; |
| 526 | u_int64_t blocks; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 527 | |
| 528 | buffer_init(&m); |
| 529 | |
| 530 | if (!compat20) { |
| 531 | u_char iv[24]; |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 532 | u_char *key; |
| 533 | u_int ivlen, keylen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 534 | |
| 535 | buffer_put_int(&m, packet_get_protocol_flags()); |
| 536 | |
| 537 | buffer_put_int(&m, packet_get_ssh1_cipher()); |
| 538 | |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 539 | debug3("%s: Sending ssh1 KEY+IV", __func__); |
| 540 | keylen = packet_get_encryption_key(NULL); |
| 541 | key = xmalloc(keylen+1); /* add 1 if keylen == 0 */ |
| 542 | keylen = packet_get_encryption_key(key); |
| 543 | buffer_put_string(&m, key, keylen); |
| 544 | memset(key, 0, keylen); |
| 545 | xfree(key); |
| 546 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 547 | ivlen = packet_get_keyiv_len(MODE_OUT); |
| 548 | packet_get_keyiv(MODE_OUT, iv, ivlen); |
| 549 | buffer_put_string(&m, iv, ivlen); |
| 550 | ivlen = packet_get_keyiv_len(MODE_OUT); |
| 551 | packet_get_keyiv(MODE_IN, iv, ivlen); |
| 552 | buffer_put_string(&m, iv, ivlen); |
| 553 | goto skip; |
| 554 | } else { |
| 555 | /* Kex for rekeying */ |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 556 | mm_send_kex(&m, *pmonitor->m_pkex); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | debug3("%s: Sending new keys: %p %p", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 560 | __func__, newkeys[MODE_OUT], newkeys[MODE_IN]); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 561 | |
| 562 | /* Keys from Kex */ |
| 563 | if (!mm_newkeys_to_blob(MODE_OUT, &blob, &bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 564 | fatal("%s: conversion of newkeys failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 565 | |
| 566 | buffer_put_string(&m, blob, bloblen); |
| 567 | xfree(blob); |
| 568 | |
| 569 | if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 570 | fatal("%s: conversion of newkeys failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 571 | |
| 572 | buffer_put_string(&m, blob, bloblen); |
| 573 | xfree(blob); |
| 574 | |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 575 | packet_get_state(MODE_OUT, &seqnr, &blocks, &packets); |
| 576 | buffer_put_int(&m, seqnr); |
| 577 | buffer_put_int64(&m, blocks); |
| 578 | buffer_put_int(&m, packets); |
Damien Miller | b1ecd9c | 2003-04-09 20:51:24 +1000 | [diff] [blame] | 579 | packet_get_state(MODE_IN, &seqnr, &blocks, &packets); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 580 | buffer_put_int(&m, seqnr); |
| 581 | buffer_put_int64(&m, blocks); |
| 582 | buffer_put_int(&m, packets); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 583 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 584 | debug3("%s: New keys have been sent", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 585 | skip: |
| 586 | /* More key context */ |
| 587 | plen = packet_get_keycontext(MODE_OUT, NULL); |
| 588 | p = xmalloc(plen+1); |
| 589 | packet_get_keycontext(MODE_OUT, p); |
| 590 | buffer_put_string(&m, p, plen); |
| 591 | xfree(p); |
| 592 | |
| 593 | plen = packet_get_keycontext(MODE_IN, NULL); |
| 594 | p = xmalloc(plen+1); |
| 595 | packet_get_keycontext(MODE_IN, p); |
| 596 | buffer_put_string(&m, p, plen); |
| 597 | xfree(p); |
| 598 | |
| 599 | /* Compression state */ |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 600 | debug3("%s: Sending compression state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 601 | buffer_put_string(&m, &outgoing_stream, sizeof(outgoing_stream)); |
| 602 | buffer_put_string(&m, &incoming_stream, sizeof(incoming_stream)); |
| 603 | |
| 604 | /* Network I/O buffers */ |
| 605 | buffer_put_string(&m, buffer_ptr(&input), buffer_len(&input)); |
| 606 | buffer_put_string(&m, buffer_ptr(&output), buffer_len(&output)); |
| 607 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 608 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYEXPORT, &m); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 609 | debug3("%s: Finished sending state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 610 | |
| 611 | buffer_free(&m); |
| 612 | } |
| 613 | |
| 614 | int |
| 615 | mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) |
| 616 | { |
| 617 | Buffer m; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 618 | char *p; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 619 | int success = 0; |
| 620 | |
| 621 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 622 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 623 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 624 | debug3("%s: waiting for MONITOR_ANS_PTY", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 625 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 626 | |
| 627 | success = buffer_get_int(&m); |
| 628 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 629 | debug3("%s: pty alloc failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 630 | buffer_free(&m); |
| 631 | return (0); |
| 632 | } |
| 633 | p = buffer_get_string(&m, NULL); |
| 634 | buffer_free(&m); |
| 635 | |
| 636 | strlcpy(namebuf, p, namebuflen); /* Possible truncation */ |
| 637 | xfree(p); |
| 638 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 639 | *ptyfd = mm_receive_fd(pmonitor->m_recvfd); |
| 640 | *ttyfd = mm_receive_fd(pmonitor->m_recvfd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 641 | |
| 642 | /* Success */ |
| 643 | return (1); |
| 644 | } |
| 645 | |
| 646 | void |
| 647 | mm_session_pty_cleanup2(void *session) |
| 648 | { |
| 649 | Session *s = session; |
| 650 | Buffer m; |
| 651 | |
| 652 | if (s->ttyfd == -1) |
| 653 | return; |
| 654 | buffer_init(&m); |
| 655 | buffer_put_cstring(&m, s->tty); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 656 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 657 | buffer_free(&m); |
| 658 | |
| 659 | /* closed dup'ed master */ |
| 660 | if (close(s->ptymaster) < 0) |
| 661 | error("close(s->ptymaster): %s", strerror(errno)); |
| 662 | |
| 663 | /* unlink pty from session */ |
| 664 | s->ttyfd = -1; |
| 665 | } |
| 666 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 667 | #ifdef USE_PAM |
| 668 | void |
| 669 | mm_start_pam(char *user) |
| 670 | { |
| 671 | Buffer m; |
| 672 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 673 | debug3("%s entering", __func__); |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 674 | if (!options.use_pam) |
| 675 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 676 | |
| 677 | buffer_init(&m); |
| 678 | buffer_put_cstring(&m, user); |
| 679 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 680 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, &m); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 681 | |
| 682 | buffer_free(&m); |
| 683 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 684 | |
| 685 | void * |
| 686 | mm_sshpam_init_ctx(Authctxt *authctxt) |
| 687 | { |
| 688 | Buffer m; |
| 689 | int success; |
| 690 | |
| 691 | debug3("%s", __func__); |
| 692 | buffer_init(&m); |
| 693 | buffer_put_cstring(&m, authctxt->user); |
| 694 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_INIT_CTX, &m); |
| 695 | debug3("%s: waiting for MONITOR_ANS_PAM_INIT_CTX", __func__); |
| 696 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_INIT_CTX, &m); |
| 697 | success = buffer_get_int(&m); |
| 698 | if (success == 0) { |
| 699 | debug3("%s: pam_init_ctx failed", __func__); |
| 700 | buffer_free(&m); |
| 701 | return (NULL); |
| 702 | } |
| 703 | buffer_free(&m); |
| 704 | return (authctxt); |
| 705 | } |
| 706 | |
| 707 | int |
| 708 | mm_sshpam_query(void *ctx, char **name, char **info, |
| 709 | u_int *num, char ***prompts, u_int **echo_on) |
| 710 | { |
| 711 | Buffer m; |
| 712 | int i, ret; |
| 713 | |
| 714 | debug3("%s", __func__); |
| 715 | buffer_init(&m); |
| 716 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_QUERY, &m); |
| 717 | debug3("%s: waiting for MONITOR_ANS_PAM_QUERY", __func__); |
| 718 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_QUERY, &m); |
| 719 | ret = buffer_get_int(&m); |
| 720 | debug3("%s: pam_query returned %d", __func__, ret); |
| 721 | *name = buffer_get_string(&m, NULL); |
| 722 | *info = buffer_get_string(&m, NULL); |
| 723 | *num = buffer_get_int(&m); |
| 724 | *prompts = xmalloc((*num + 1) * sizeof(char *)); |
| 725 | *echo_on = xmalloc((*num + 1) * sizeof(u_int)); |
| 726 | for (i = 0; i < *num; ++i) { |
| 727 | (*prompts)[i] = buffer_get_string(&m, NULL); |
| 728 | (*echo_on)[i] = buffer_get_int(&m); |
| 729 | } |
| 730 | buffer_free(&m); |
| 731 | return (ret); |
| 732 | } |
| 733 | |
| 734 | int |
| 735 | mm_sshpam_respond(void *ctx, u_int num, char **resp) |
| 736 | { |
| 737 | Buffer m; |
| 738 | int i, ret; |
| 739 | |
| 740 | debug3("%s", __func__); |
| 741 | buffer_init(&m); |
| 742 | buffer_put_int(&m, num); |
| 743 | for (i = 0; i < num; ++i) |
| 744 | buffer_put_cstring(&m, resp[i]); |
| 745 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_RESPOND, &m); |
| 746 | debug3("%s: waiting for MONITOR_ANS_PAM_RESPOND", __func__); |
| 747 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_RESPOND, &m); |
| 748 | ret = buffer_get_int(&m); |
| 749 | debug3("%s: pam_respond returned %d", __func__, ret); |
| 750 | buffer_free(&m); |
| 751 | return (ret); |
| 752 | } |
| 753 | |
| 754 | void |
| 755 | mm_sshpam_free_ctx(void *ctxtp) |
| 756 | { |
| 757 | Buffer m; |
| 758 | |
| 759 | debug3("%s", __func__); |
| 760 | buffer_init(&m); |
| 761 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_FREE_CTX, &m); |
| 762 | debug3("%s: waiting for MONITOR_ANS_PAM_FREE_CTX", __func__); |
| 763 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_FREE_CTX, &m); |
| 764 | buffer_free(&m); |
| 765 | } |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 766 | #endif /* USE_PAM */ |
| 767 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 768 | /* Request process termination */ |
| 769 | |
| 770 | void |
| 771 | mm_terminate(void) |
| 772 | { |
| 773 | Buffer m; |
| 774 | |
| 775 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 776 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 777 | buffer_free(&m); |
| 778 | } |
| 779 | |
| 780 | int |
| 781 | mm_ssh1_session_key(BIGNUM *num) |
| 782 | { |
| 783 | int rsafail; |
| 784 | Buffer m; |
| 785 | |
| 786 | buffer_init(&m); |
| 787 | buffer_put_bignum2(&m, num); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 788 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSKEY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 789 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 790 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SESSKEY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 791 | |
| 792 | rsafail = buffer_get_int(&m); |
| 793 | buffer_get_bignum2(&m, num); |
| 794 | |
| 795 | buffer_free(&m); |
| 796 | |
| 797 | return (rsafail); |
| 798 | } |
| 799 | |
| 800 | static void |
| 801 | mm_chall_setup(char **name, char **infotxt, u_int *numprompts, |
| 802 | char ***prompts, u_int **echo_on) |
| 803 | { |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 804 | *name = xstrdup(""); |
| 805 | *infotxt = xstrdup(""); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 806 | *numprompts = 1; |
Ben Lindstrom | a962c2f | 2002-07-04 00:14:17 +0000 | [diff] [blame] | 807 | *prompts = xmalloc(*numprompts * sizeof(char *)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 808 | *echo_on = xmalloc(*numprompts * sizeof(u_int)); |
| 809 | (*echo_on)[0] = 0; |
| 810 | } |
| 811 | |
| 812 | int |
| 813 | mm_bsdauth_query(void *ctx, char **name, char **infotxt, |
| 814 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 815 | { |
| 816 | Buffer m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 817 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 818 | char *challenge; |
| 819 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 820 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 821 | |
| 822 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 823 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 824 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 825 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 826 | &m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 827 | success = buffer_get_int(&m); |
| 828 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 829 | debug3("%s: no challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 830 | buffer_free(&m); |
| 831 | return (-1); |
| 832 | } |
| 833 | |
| 834 | /* Get the challenge, and format the response */ |
| 835 | challenge = buffer_get_string(&m, NULL); |
| 836 | buffer_free(&m); |
| 837 | |
| 838 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 839 | (*prompts)[0] = challenge; |
| 840 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 841 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 842 | |
| 843 | return (0); |
| 844 | } |
| 845 | |
| 846 | int |
| 847 | mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses) |
| 848 | { |
| 849 | Buffer m; |
| 850 | int authok; |
| 851 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 852 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 853 | if (numresponses != 1) |
| 854 | return (-1); |
| 855 | |
| 856 | buffer_init(&m); |
| 857 | buffer_put_cstring(&m, responses[0]); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 858 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 859 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 860 | mm_request_receive_expect(pmonitor->m_recvfd, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 861 | MONITOR_ANS_BSDAUTHRESPOND, &m); |
| 862 | |
| 863 | authok = buffer_get_int(&m); |
| 864 | buffer_free(&m); |
| 865 | |
| 866 | return ((authok == 0) ? -1 : 0); |
| 867 | } |
| 868 | |
| 869 | int |
| 870 | mm_skey_query(void *ctx, char **name, char **infotxt, |
| 871 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 872 | { |
| 873 | Buffer m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 874 | int len; |
| 875 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 876 | char *p, *challenge; |
| 877 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 878 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 879 | |
| 880 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 881 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYQUERY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 882 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 883 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SKEYQUERY, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 884 | &m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 885 | success = buffer_get_int(&m); |
| 886 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 887 | debug3("%s: no challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 888 | buffer_free(&m); |
| 889 | return (-1); |
| 890 | } |
| 891 | |
| 892 | /* Get the challenge, and format the response */ |
| 893 | challenge = buffer_get_string(&m, NULL); |
| 894 | buffer_free(&m); |
| 895 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 896 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 897 | |
| 898 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 899 | |
| 900 | len = strlen(challenge) + strlen(SKEY_PROMPT) + 1; |
| 901 | p = xmalloc(len); |
| 902 | strlcpy(p, challenge, len); |
| 903 | strlcat(p, SKEY_PROMPT, len); |
| 904 | (*prompts)[0] = p; |
| 905 | xfree(challenge); |
| 906 | |
| 907 | return (0); |
| 908 | } |
| 909 | |
| 910 | int |
| 911 | mm_skey_respond(void *ctx, u_int numresponses, char **responses) |
| 912 | { |
| 913 | Buffer m; |
| 914 | int authok; |
| 915 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 916 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 917 | if (numresponses != 1) |
| 918 | return (-1); |
| 919 | |
| 920 | buffer_init(&m); |
| 921 | buffer_put_cstring(&m, responses[0]); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 922 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYRESPOND, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 923 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 924 | mm_request_receive_expect(pmonitor->m_recvfd, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 925 | MONITOR_ANS_SKEYRESPOND, &m); |
| 926 | |
| 927 | authok = buffer_get_int(&m); |
| 928 | buffer_free(&m); |
| 929 | |
| 930 | return ((authok == 0) ? -1 : 0); |
| 931 | } |
| 932 | |
| 933 | void |
| 934 | mm_ssh1_session_id(u_char session_id[16]) |
| 935 | { |
| 936 | Buffer m; |
| 937 | int i; |
| 938 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 939 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 940 | |
| 941 | buffer_init(&m); |
| 942 | for (i = 0; i < 16; i++) |
| 943 | buffer_put_char(&m, session_id[i]); |
| 944 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 945 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSID, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 946 | buffer_free(&m); |
| 947 | } |
| 948 | |
| 949 | int |
| 950 | mm_auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey) |
| 951 | { |
| 952 | Buffer m; |
| 953 | Key *key; |
| 954 | u_char *blob; |
| 955 | u_int blen; |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 956 | int allowed = 0, have_forced = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 957 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 958 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 959 | |
| 960 | buffer_init(&m); |
| 961 | buffer_put_bignum2(&m, client_n); |
| 962 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 963 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSAKEYALLOWED, &m); |
| 964 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSAKEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 965 | |
| 966 | allowed = buffer_get_int(&m); |
| 967 | |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 968 | /* fake forced command */ |
| 969 | auth_clear_options(); |
| 970 | have_forced = buffer_get_int(&m); |
| 971 | forced_command = have_forced ? xstrdup("true") : NULL; |
| 972 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 973 | if (allowed && rkey != NULL) { |
| 974 | blob = buffer_get_string(&m, &blen); |
| 975 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 976 | fatal("%s: key_from_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 977 | *rkey = key; |
| 978 | xfree(blob); |
| 979 | } |
| 980 | mm_send_debug(&m); |
| 981 | buffer_free(&m); |
| 982 | |
| 983 | return (allowed); |
| 984 | } |
| 985 | |
| 986 | BIGNUM * |
| 987 | mm_auth_rsa_generate_challenge(Key *key) |
| 988 | { |
| 989 | Buffer m; |
| 990 | BIGNUM *challenge; |
| 991 | u_char *blob; |
| 992 | u_int blen; |
| 993 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 994 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 995 | |
| 996 | if ((challenge = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 997 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 998 | |
| 999 | key->type = KEY_RSA; /* XXX cheat for key_to_blob */ |
| 1000 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1001 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1002 | key->type = KEY_RSA1; |
| 1003 | |
| 1004 | buffer_init(&m); |
| 1005 | buffer_put_string(&m, blob, blen); |
| 1006 | xfree(blob); |
| 1007 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1008 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSACHALLENGE, &m); |
| 1009 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSACHALLENGE, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1010 | |
| 1011 | buffer_get_bignum2(&m, challenge); |
| 1012 | buffer_free(&m); |
| 1013 | |
| 1014 | return (challenge); |
| 1015 | } |
| 1016 | |
| 1017 | int |
| 1018 | mm_auth_rsa_verify_response(Key *key, BIGNUM *p, u_char response[16]) |
| 1019 | { |
| 1020 | Buffer m; |
| 1021 | u_char *blob; |
| 1022 | u_int blen; |
| 1023 | int success = 0; |
| 1024 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1025 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1026 | |
| 1027 | key->type = KEY_RSA; /* XXX cheat for key_to_blob */ |
| 1028 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1029 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1030 | key->type = KEY_RSA1; |
| 1031 | |
| 1032 | buffer_init(&m); |
| 1033 | buffer_put_string(&m, blob, blen); |
| 1034 | buffer_put_string(&m, response, 16); |
| 1035 | xfree(blob); |
| 1036 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1037 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSARESPONSE, &m); |
| 1038 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSARESPONSE, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1039 | |
| 1040 | success = buffer_get_int(&m); |
| 1041 | buffer_free(&m); |
| 1042 | |
| 1043 | return (success); |
| 1044 | } |
Damien Miller | 25162f2 | 2002-09-12 09:47:29 +1000 | [diff] [blame] | 1045 | |
| 1046 | #ifdef KRB5 |
| 1047 | int |
| 1048 | mm_auth_krb5(void *ctx, void *argp, char **userp, void *resp) |
| 1049 | { |
| 1050 | krb5_data *tkt, *reply; |
| 1051 | Buffer m; |
| 1052 | int success; |
| 1053 | |
| 1054 | debug3("%s entering", __func__); |
| 1055 | tkt = (krb5_data *) argp; |
| 1056 | reply = (krb5_data *) resp; |
| 1057 | |
| 1058 | buffer_init(&m); |
| 1059 | buffer_put_string(&m, tkt->data, tkt->length); |
| 1060 | |
| 1061 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KRB5, &m); |
| 1062 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KRB5, &m); |
| 1063 | |
| 1064 | success = buffer_get_int(&m); |
| 1065 | if (success) { |
| 1066 | u_int len; |
| 1067 | |
| 1068 | *userp = buffer_get_string(&m, NULL); |
| 1069 | reply->data = buffer_get_string(&m, &len); |
| 1070 | reply->length = len; |
| 1071 | } else { |
| 1072 | memset(reply, 0, sizeof(*reply)); |
| 1073 | *userp = NULL; |
| 1074 | } |
| 1075 | |
| 1076 | buffer_free(&m); |
| 1077 | return (success); |
| 1078 | } |
| 1079 | #endif |