Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 1 | /* $OpenBSD: monitor_wrap.c,v 1.72 2011/05/23 03:30:07 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" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 29 | |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 30 | #include <sys/types.h> |
Darren Tucker | 1a3d6e7 | 2006-08-05 18:46:47 +1000 | [diff] [blame] | 31 | #include <sys/uio.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 32 | |
Darren Tucker | 3997249 | 2006-07-12 22:22:46 +1000 | [diff] [blame] | 33 | #include <errno.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 34 | #include <pwd.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 35 | #include <signal.h> |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 36 | #include <stdarg.h> |
Damien Miller | a7a73ee | 2006-08-05 11:37:59 +1000 | [diff] [blame] | 37 | #include <stdio.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 38 | #include <string.h> |
Darren Tucker | 1a3d6e7 | 2006-08-05 18:46:47 +1000 | [diff] [blame] | 39 | #include <unistd.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 40 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 41 | #include <openssl/bn.h> |
| 42 | #include <openssl/dh.h> |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 43 | #include <openssl/evp.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 44 | |
Damien Miller | b84886b | 2008-05-19 15:05:07 +1000 | [diff] [blame] | 45 | #include "openbsd-compat/sys-queue.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 46 | #include "xmalloc.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 47 | #include "ssh.h" |
| 48 | #include "dh.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 49 | #include "buffer.h" |
| 50 | #include "key.h" |
| 51 | #include "cipher.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 52 | #include "kex.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 53 | #include "hostfile.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 54 | #include "auth.h" |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 55 | #include "auth-options.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 56 | #include "packet.h" |
| 57 | #include "mac.h" |
| 58 | #include "log.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 59 | #ifdef TARGET_OS_MAC /* XXX Broken krb5 headers on Mac */ |
| 60 | #undef TARGET_OS_MAC |
Ben Lindstrom | 1b9f2a6 | 2004-04-08 05:11:03 +0000 | [diff] [blame] | 61 | #include "zlib.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 62 | #define TARGET_OS_MAC 1 |
| 63 | #else |
| 64 | #include "zlib.h" |
| 65 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 66 | #include "monitor.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 67 | #ifdef GSSAPI |
| 68 | #include "ssh-gss.h" |
| 69 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 70 | #include "monitor_wrap.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 71 | #include "atomicio.h" |
| 72 | #include "monitor_fdpass.h" |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 73 | #include "misc.h" |
Damien Miller | cee8523 | 2009-03-06 00:58:22 +1100 | [diff] [blame] | 74 | #include "schnorr.h" |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 75 | #include "jpake.h" |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 76 | #include "uuencode.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 77 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 78 | #include "channels.h" |
| 79 | #include "session.h" |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 80 | #include "servconf.h" |
Darren Tucker | c5564e1 | 2009-06-21 18:53:53 +1000 | [diff] [blame] | 81 | #include "roaming.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 82 | |
| 83 | /* Imports */ |
| 84 | extern int compat20; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 85 | extern z_stream incoming_stream; |
| 86 | extern z_stream outgoing_stream; |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 87 | extern struct monitor *pmonitor; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 88 | extern Buffer loginmsg; |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 89 | extern ServerOptions options; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 90 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 91 | int |
| 92 | mm_is_monitor(void) |
| 93 | { |
| 94 | /* |
| 95 | * m_pid is only set in the privileged part, and |
| 96 | * points to the unprivileged child. |
| 97 | */ |
Darren Tucker | a47c9bc | 2003-11-03 20:03:25 +1100 | [diff] [blame] | 98 | return (pmonitor && pmonitor->m_pid > 0); |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 99 | } |
| 100 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 101 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 102 | mm_request_send(int sock, enum monitor_reqtype type, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 103 | { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 104 | u_int mlen = buffer_len(m); |
Ben Lindstrom | b1bdc5a | 2002-07-04 00:09:26 +0000 | [diff] [blame] | 105 | u_char buf[5]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 106 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 107 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 108 | |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 109 | put_u32(buf, mlen + 1); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 110 | buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */ |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 111 | if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 112 | fatal("%s: write: %s", __func__, strerror(errno)); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 113 | if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 114 | fatal("%s: write: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 118 | mm_request_receive(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 119 | { |
| 120 | u_char buf[4]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 121 | u_int msg_len; |
| 122 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 123 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 124 | |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 125 | if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { |
| 126 | if (errno == EPIPE) |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 127 | cleanup_exit(255); |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 128 | fatal("%s: read: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 129 | } |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 130 | msg_len = get_u32(buf); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 131 | if (msg_len > 256 * 1024) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 132 | fatal("%s: read: bad msg_len %d", __func__, msg_len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 133 | buffer_clear(m); |
| 134 | buffer_append_space(m, msg_len); |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 135 | if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len) |
| 136 | fatal("%s: read: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 140 | mm_request_receive_expect(int sock, enum monitor_reqtype type, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 141 | { |
| 142 | u_char rtype; |
| 143 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 144 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 145 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 146 | mm_request_receive(sock, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 147 | rtype = buffer_get_char(m); |
| 148 | if (rtype != type) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 149 | fatal("%s: read: rtype %d != type %d", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 150 | rtype, type); |
| 151 | } |
| 152 | |
| 153 | DH * |
| 154 | mm_choose_dh(int min, int nbits, int max) |
| 155 | { |
| 156 | BIGNUM *p, *g; |
| 157 | int success = 0; |
| 158 | Buffer m; |
| 159 | |
| 160 | buffer_init(&m); |
| 161 | buffer_put_int(&m, min); |
| 162 | buffer_put_int(&m, nbits); |
| 163 | buffer_put_int(&m, max); |
| 164 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 165 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 166 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 167 | debug3("%s: waiting for MONITOR_ANS_MODULI", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 168 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 169 | |
| 170 | success = buffer_get_char(&m); |
| 171 | if (success == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 172 | fatal("%s: MONITOR_ANS_MODULI failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 173 | |
| 174 | if ((p = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 175 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 176 | if ((g = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 177 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 178 | buffer_get_bignum2(&m, p); |
| 179 | buffer_get_bignum2(&m, g); |
| 180 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 181 | debug3("%s: remaining %d", __func__, buffer_len(&m)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 182 | buffer_free(&m); |
| 183 | |
| 184 | return (dh_new_group(g, p)); |
| 185 | } |
| 186 | |
| 187 | int |
| 188 | mm_key_sign(Key *key, u_char **sigp, u_int *lenp, u_char *data, u_int datalen) |
| 189 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 190 | Kex *kex = *pmonitor->m_pkex; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 191 | Buffer m; |
| 192 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 193 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 194 | |
| 195 | buffer_init(&m); |
| 196 | buffer_put_int(&m, kex->host_key_index(key)); |
| 197 | buffer_put_string(&m, data, datalen); |
| 198 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 199 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 200 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 201 | debug3("%s: waiting for MONITOR_ANS_SIGN", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 202 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 203 | *sigp = buffer_get_string(&m, lenp); |
| 204 | buffer_free(&m); |
| 205 | |
| 206 | return (0); |
| 207 | } |
| 208 | |
| 209 | struct passwd * |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 210 | mm_getpwnamallow(const char *username) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 211 | { |
| 212 | Buffer m; |
| 213 | struct passwd *pw; |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 214 | u_int len, i; |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 215 | ServerOptions *newopts; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 216 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 217 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 218 | |
| 219 | buffer_init(&m); |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 220 | buffer_put_cstring(&m, username); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 221 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 222 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 223 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 224 | debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 225 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 226 | |
| 227 | if (buffer_get_char(&m) == 0) { |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 228 | pw = NULL; |
| 229 | goto out; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 230 | } |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 231 | pw = buffer_get_string(&m, &len); |
| 232 | if (len != sizeof(struct passwd)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 233 | fatal("%s: struct passwd size mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 234 | pw->pw_name = buffer_get_string(&m, NULL); |
| 235 | pw->pw_passwd = buffer_get_string(&m, NULL); |
| 236 | pw->pw_gecos = buffer_get_string(&m, NULL); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 237 | #ifdef HAVE_PW_CLASS_IN_PASSWD |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 238 | pw->pw_class = buffer_get_string(&m, NULL); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 239 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 240 | pw->pw_dir = buffer_get_string(&m, NULL); |
| 241 | pw->pw_shell = buffer_get_string(&m, NULL); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 242 | |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 243 | out: |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 244 | /* copy options block as a Match directive may have changed some */ |
| 245 | newopts = buffer_get_string(&m, &len); |
| 246 | if (len != sizeof(*newopts)) |
| 247 | fatal("%s: option block size mismatch", __func__); |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 248 | |
| 249 | #define M_CP_STROPT(x) do { \ |
| 250 | if (newopts->x != NULL) \ |
| 251 | newopts->x = buffer_get_string(&m, NULL); \ |
| 252 | } while (0) |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 253 | #define M_CP_STRARRAYOPT(x, nx) do { \ |
| 254 | for (i = 0; i < newopts->nx; i++) \ |
| 255 | newopts->x[i] = buffer_get_string(&m, NULL); \ |
| 256 | } while (0) |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 257 | /* See comment in servconf.h */ |
| 258 | COPY_MATCH_STRING_OPTS(); |
| 259 | #undef M_CP_STROPT |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 260 | #undef M_CP_STRARRAYOPT |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 261 | |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 262 | copy_set_server_options(&options, newopts, 1); |
| 263 | xfree(newopts); |
| 264 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 265 | buffer_free(&m); |
| 266 | |
| 267 | return (pw); |
| 268 | } |
| 269 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 270 | char * |
| 271 | mm_auth2_read_banner(void) |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 272 | { |
| 273 | Buffer m; |
| 274 | char *banner; |
| 275 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 276 | debug3("%s entering", __func__); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 277 | |
| 278 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 279 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 280 | buffer_clear(&m); |
| 281 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 282 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 283 | MONITOR_ANS_AUTH2_READ_BANNER, &m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 284 | banner = buffer_get_string(&m, NULL); |
| 285 | buffer_free(&m); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 286 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 287 | /* treat empty banner as missing banner */ |
| 288 | if (strlen(banner) == 0) { |
| 289 | xfree(banner); |
| 290 | banner = NULL; |
| 291 | } |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 292 | return (banner); |
| 293 | } |
| 294 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 295 | /* Inform the privileged process about service and style */ |
| 296 | |
| 297 | void |
| 298 | mm_inform_authserv(char *service, char *style) |
| 299 | { |
| 300 | Buffer m; |
| 301 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 302 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 303 | |
| 304 | buffer_init(&m); |
| 305 | buffer_put_cstring(&m, service); |
| 306 | buffer_put_cstring(&m, style ? style : ""); |
| 307 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 308 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 309 | |
| 310 | buffer_free(&m); |
| 311 | } |
| 312 | |
| 313 | /* Do the password authentication */ |
| 314 | int |
| 315 | mm_auth_password(Authctxt *authctxt, char *password) |
| 316 | { |
| 317 | Buffer m; |
| 318 | int authenticated = 0; |
| 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 | buffer_init(&m); |
| 323 | buffer_put_cstring(&m, password); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 324 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 325 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 326 | debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 327 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 328 | |
| 329 | authenticated = buffer_get_int(&m); |
| 330 | |
| 331 | buffer_free(&m); |
| 332 | |
| 333 | debug3("%s: user %sauthenticated", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 334 | __func__, authenticated ? "" : "not "); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 335 | return (authenticated); |
| 336 | } |
| 337 | |
| 338 | int |
| 339 | mm_user_key_allowed(struct passwd *pw, Key *key) |
| 340 | { |
| 341 | return (mm_key_allowed(MM_USERKEY, NULL, NULL, key)); |
| 342 | } |
| 343 | |
| 344 | int |
| 345 | mm_hostbased_key_allowed(struct passwd *pw, char *user, char *host, |
| 346 | Key *key) |
| 347 | { |
| 348 | return (mm_key_allowed(MM_HOSTKEY, user, host, key)); |
| 349 | } |
| 350 | |
| 351 | int |
| 352 | mm_auth_rhosts_rsa_key_allowed(struct passwd *pw, char *user, |
| 353 | char *host, Key *key) |
| 354 | { |
| 355 | int ret; |
| 356 | |
| 357 | key->type = KEY_RSA; /* XXX hack for key_to_blob */ |
| 358 | ret = mm_key_allowed(MM_RSAHOSTKEY, user, host, key); |
| 359 | key->type = KEY_RSA1; |
| 360 | return (ret); |
| 361 | } |
| 362 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 363 | int |
| 364 | mm_key_allowed(enum mm_keytype type, char *user, char *host, Key *key) |
| 365 | { |
| 366 | Buffer m; |
| 367 | u_char *blob; |
| 368 | u_int len; |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 369 | int allowed = 0, have_forced = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 370 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 371 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 372 | |
| 373 | /* Convert the key to a blob and the pass it over */ |
| 374 | if (!key_to_blob(key, &blob, &len)) |
| 375 | return (0); |
| 376 | |
| 377 | buffer_init(&m); |
| 378 | buffer_put_int(&m, type); |
| 379 | buffer_put_cstring(&m, user ? user : ""); |
| 380 | buffer_put_cstring(&m, host ? host : ""); |
| 381 | buffer_put_string(&m, blob, len); |
| 382 | xfree(blob); |
| 383 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 384 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 385 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 386 | debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 387 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 388 | |
| 389 | allowed = buffer_get_int(&m); |
| 390 | |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 391 | /* fake forced command */ |
| 392 | auth_clear_options(); |
| 393 | have_forced = buffer_get_int(&m); |
| 394 | forced_command = have_forced ? xstrdup("true") : NULL; |
| 395 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 396 | buffer_free(&m); |
| 397 | |
| 398 | return (allowed); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * This key verify needs to send the key type along, because the |
| 403 | * privileged parent makes the decision if the key is allowed |
| 404 | * for authentication. |
| 405 | */ |
| 406 | |
| 407 | int |
| 408 | mm_key_verify(Key *key, u_char *sig, u_int siglen, u_char *data, u_int datalen) |
| 409 | { |
| 410 | Buffer m; |
| 411 | u_char *blob; |
| 412 | u_int len; |
| 413 | int verified = 0; |
| 414 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 415 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 416 | |
| 417 | /* Convert the key to a blob and the pass it over */ |
| 418 | if (!key_to_blob(key, &blob, &len)) |
| 419 | return (0); |
| 420 | |
| 421 | buffer_init(&m); |
| 422 | buffer_put_string(&m, blob, len); |
| 423 | buffer_put_string(&m, sig, siglen); |
| 424 | buffer_put_string(&m, data, datalen); |
| 425 | xfree(blob); |
| 426 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 427 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 428 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 429 | debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 430 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 431 | |
| 432 | verified = buffer_get_int(&m); |
| 433 | |
| 434 | buffer_free(&m); |
| 435 | |
| 436 | return (verified); |
| 437 | } |
| 438 | |
| 439 | /* Export key state after authentication */ |
| 440 | Newkeys * |
| 441 | mm_newkeys_from_blob(u_char *blob, int blen) |
| 442 | { |
| 443 | Buffer b; |
| 444 | u_int len; |
| 445 | Newkeys *newkey = NULL; |
| 446 | Enc *enc; |
| 447 | Mac *mac; |
| 448 | Comp *comp; |
| 449 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 450 | debug3("%s: %p(%d)", __func__, blob, blen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 451 | #ifdef DEBUG_PK |
| 452 | dump_base64(stderr, blob, blen); |
| 453 | #endif |
| 454 | buffer_init(&b); |
| 455 | buffer_append(&b, blob, blen); |
| 456 | |
| 457 | newkey = xmalloc(sizeof(*newkey)); |
| 458 | enc = &newkey->enc; |
| 459 | mac = &newkey->mac; |
| 460 | comp = &newkey->comp; |
| 461 | |
| 462 | /* Enc structure */ |
| 463 | enc->name = buffer_get_string(&b, NULL); |
| 464 | buffer_get(&b, &enc->cipher, sizeof(enc->cipher)); |
| 465 | enc->enabled = buffer_get_int(&b); |
| 466 | enc->block_size = buffer_get_int(&b); |
| 467 | enc->key = buffer_get_string(&b, &enc->key_len); |
| 468 | enc->iv = buffer_get_string(&b, &len); |
| 469 | if (len != enc->block_size) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 470 | fatal("%s: bad ivlen: expected %u != %u", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 471 | enc->block_size, len); |
| 472 | |
| 473 | if (enc->name == NULL || cipher_by_name(enc->name) != enc->cipher) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 474 | fatal("%s: bad cipher name %s or pointer %p", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 475 | enc->name, enc->cipher); |
| 476 | |
| 477 | /* Mac structure */ |
| 478 | mac->name = buffer_get_string(&b, NULL); |
Darren Tucker | 5f3d5be | 2007-06-05 18:30:18 +1000 | [diff] [blame] | 479 | if (mac->name == NULL || mac_setup(mac, mac->name) == -1) |
Damien Miller | e45796f | 2007-06-11 14:01:42 +1000 | [diff] [blame] | 480 | fatal("%s: can not setup mac %s", __func__, mac->name); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 481 | mac->enabled = buffer_get_int(&b); |
| 482 | mac->key = buffer_get_string(&b, &len); |
| 483 | if (len > mac->key_len) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 484 | fatal("%s: bad mac key length: %u > %d", __func__, len, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 485 | mac->key_len); |
| 486 | mac->key_len = len; |
| 487 | |
| 488 | /* Comp structure */ |
| 489 | comp->type = buffer_get_int(&b); |
| 490 | comp->enabled = buffer_get_int(&b); |
| 491 | comp->name = buffer_get_string(&b, NULL); |
| 492 | |
| 493 | len = buffer_len(&b); |
| 494 | if (len != 0) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 495 | error("newkeys_from_blob: remaining bytes in blob %u", len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 496 | buffer_free(&b); |
| 497 | return (newkey); |
| 498 | } |
| 499 | |
| 500 | int |
| 501 | mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp) |
| 502 | { |
| 503 | Buffer b; |
| 504 | int len; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 505 | Enc *enc; |
| 506 | Mac *mac; |
| 507 | Comp *comp; |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 508 | Newkeys *newkey = (Newkeys *)packet_get_newkeys(mode); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 509 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 510 | debug3("%s: converting %p", __func__, newkey); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 511 | |
| 512 | if (newkey == NULL) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 513 | error("%s: newkey == NULL", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 514 | return 0; |
| 515 | } |
| 516 | enc = &newkey->enc; |
| 517 | mac = &newkey->mac; |
| 518 | comp = &newkey->comp; |
| 519 | |
| 520 | buffer_init(&b); |
| 521 | /* Enc structure */ |
| 522 | buffer_put_cstring(&b, enc->name); |
| 523 | /* The cipher struct is constant and shared, you export pointer */ |
| 524 | buffer_append(&b, &enc->cipher, sizeof(enc->cipher)); |
| 525 | buffer_put_int(&b, enc->enabled); |
| 526 | buffer_put_int(&b, enc->block_size); |
| 527 | buffer_put_string(&b, enc->key, enc->key_len); |
| 528 | packet_get_keyiv(mode, enc->iv, enc->block_size); |
| 529 | buffer_put_string(&b, enc->iv, enc->block_size); |
| 530 | |
| 531 | /* Mac structure */ |
| 532 | buffer_put_cstring(&b, mac->name); |
| 533 | buffer_put_int(&b, mac->enabled); |
| 534 | buffer_put_string(&b, mac->key, mac->key_len); |
| 535 | |
| 536 | /* Comp structure */ |
| 537 | buffer_put_int(&b, comp->type); |
| 538 | buffer_put_int(&b, comp->enabled); |
| 539 | buffer_put_cstring(&b, comp->name); |
| 540 | |
| 541 | len = buffer_len(&b); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 542 | if (lenp != NULL) |
| 543 | *lenp = len; |
Ben Lindstrom | 2bf759c | 2002-07-07 22:13:31 +0000 | [diff] [blame] | 544 | if (blobp != NULL) { |
| 545 | *blobp = xmalloc(len); |
| 546 | memcpy(*blobp, buffer_ptr(&b), len); |
| 547 | } |
| 548 | memset(buffer_ptr(&b), 0, len); |
| 549 | buffer_free(&b); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 550 | return len; |
| 551 | } |
| 552 | |
| 553 | static void |
| 554 | mm_send_kex(Buffer *m, Kex *kex) |
| 555 | { |
| 556 | buffer_put_string(m, kex->session_id, kex->session_id_len); |
| 557 | buffer_put_int(m, kex->we_need); |
| 558 | buffer_put_int(m, kex->hostkey_type); |
| 559 | buffer_put_int(m, kex->kex_type); |
| 560 | buffer_put_string(m, buffer_ptr(&kex->my), buffer_len(&kex->my)); |
| 561 | buffer_put_string(m, buffer_ptr(&kex->peer), buffer_len(&kex->peer)); |
| 562 | buffer_put_int(m, kex->flags); |
| 563 | buffer_put_cstring(m, kex->client_version_string); |
| 564 | buffer_put_cstring(m, kex->server_version_string); |
| 565 | } |
| 566 | |
| 567 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 568 | mm_send_keystate(struct monitor *monitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 569 | { |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 570 | Buffer m, *input, *output; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 571 | u_char *blob, *p; |
| 572 | u_int bloblen, plen; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 573 | u_int32_t seqnr, packets; |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 574 | u_int64_t blocks, bytes; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 575 | |
| 576 | buffer_init(&m); |
| 577 | |
| 578 | if (!compat20) { |
| 579 | u_char iv[24]; |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 580 | u_char *key; |
| 581 | u_int ivlen, keylen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 582 | |
| 583 | buffer_put_int(&m, packet_get_protocol_flags()); |
| 584 | |
| 585 | buffer_put_int(&m, packet_get_ssh1_cipher()); |
| 586 | |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 587 | debug3("%s: Sending ssh1 KEY+IV", __func__); |
| 588 | keylen = packet_get_encryption_key(NULL); |
| 589 | key = xmalloc(keylen+1); /* add 1 if keylen == 0 */ |
| 590 | keylen = packet_get_encryption_key(key); |
| 591 | buffer_put_string(&m, key, keylen); |
| 592 | memset(key, 0, keylen); |
| 593 | xfree(key); |
| 594 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 595 | ivlen = packet_get_keyiv_len(MODE_OUT); |
| 596 | packet_get_keyiv(MODE_OUT, iv, ivlen); |
| 597 | buffer_put_string(&m, iv, ivlen); |
| 598 | ivlen = packet_get_keyiv_len(MODE_OUT); |
| 599 | packet_get_keyiv(MODE_IN, iv, ivlen); |
| 600 | buffer_put_string(&m, iv, ivlen); |
| 601 | goto skip; |
| 602 | } else { |
| 603 | /* Kex for rekeying */ |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 604 | mm_send_kex(&m, *monitor->m_pkex); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | debug3("%s: Sending new keys: %p %p", |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 608 | __func__, packet_get_newkeys(MODE_OUT), |
| 609 | packet_get_newkeys(MODE_IN)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 610 | |
| 611 | /* Keys from Kex */ |
| 612 | if (!mm_newkeys_to_blob(MODE_OUT, &blob, &bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 613 | fatal("%s: conversion of newkeys failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 614 | |
| 615 | buffer_put_string(&m, blob, bloblen); |
| 616 | xfree(blob); |
| 617 | |
| 618 | if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 619 | fatal("%s: conversion of newkeys failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 620 | |
| 621 | buffer_put_string(&m, blob, bloblen); |
| 622 | xfree(blob); |
| 623 | |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 624 | packet_get_state(MODE_OUT, &seqnr, &blocks, &packets, &bytes); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 625 | buffer_put_int(&m, seqnr); |
| 626 | buffer_put_int64(&m, blocks); |
| 627 | buffer_put_int(&m, packets); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 628 | buffer_put_int64(&m, bytes); |
| 629 | packet_get_state(MODE_IN, &seqnr, &blocks, &packets, &bytes); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 630 | buffer_put_int(&m, seqnr); |
| 631 | buffer_put_int64(&m, blocks); |
| 632 | buffer_put_int(&m, packets); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 633 | buffer_put_int64(&m, bytes); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 634 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 635 | debug3("%s: New keys have been sent", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 636 | skip: |
| 637 | /* More key context */ |
| 638 | plen = packet_get_keycontext(MODE_OUT, NULL); |
| 639 | p = xmalloc(plen+1); |
| 640 | packet_get_keycontext(MODE_OUT, p); |
| 641 | buffer_put_string(&m, p, plen); |
| 642 | xfree(p); |
| 643 | |
| 644 | plen = packet_get_keycontext(MODE_IN, NULL); |
| 645 | p = xmalloc(plen+1); |
| 646 | packet_get_keycontext(MODE_IN, p); |
| 647 | buffer_put_string(&m, p, plen); |
| 648 | xfree(p); |
| 649 | |
| 650 | /* Compression state */ |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 651 | debug3("%s: Sending compression state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 652 | buffer_put_string(&m, &outgoing_stream, sizeof(outgoing_stream)); |
| 653 | buffer_put_string(&m, &incoming_stream, sizeof(incoming_stream)); |
| 654 | |
| 655 | /* Network I/O buffers */ |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 656 | input = (Buffer *)packet_get_input(); |
| 657 | output = (Buffer *)packet_get_output(); |
| 658 | buffer_put_string(&m, buffer_ptr(input), buffer_len(input)); |
| 659 | buffer_put_string(&m, buffer_ptr(output), buffer_len(output)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 660 | |
Darren Tucker | c5564e1 | 2009-06-21 18:53:53 +1000 | [diff] [blame] | 661 | /* Roaming */ |
| 662 | if (compat20) { |
| 663 | buffer_put_int64(&m, get_sent_bytes()); |
| 664 | buffer_put_int64(&m, get_recv_bytes()); |
| 665 | } |
| 666 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 667 | mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, &m); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 668 | debug3("%s: Finished sending state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 669 | |
| 670 | buffer_free(&m); |
| 671 | } |
| 672 | |
| 673 | int |
Damien Miller | 71a7367 | 2006-03-26 14:04:36 +1100 | [diff] [blame] | 674 | mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 675 | { |
| 676 | Buffer m; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 677 | char *p, *msg; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 678 | int success = 0, tmp1 = -1, tmp2 = -1; |
| 679 | |
| 680 | /* Kludge: ensure there are fds free to receive the pty/tty */ |
| 681 | if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 || |
| 682 | (tmp2 = dup(pmonitor->m_recvfd)) == -1) { |
| 683 | error("%s: cannot allocate fds for pty", __func__); |
| 684 | if (tmp1 > 0) |
| 685 | close(tmp1); |
| 686 | if (tmp2 > 0) |
| 687 | close(tmp2); |
| 688 | return 0; |
| 689 | } |
| 690 | close(tmp1); |
| 691 | close(tmp2); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 692 | |
| 693 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 694 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 695 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 696 | debug3("%s: waiting for MONITOR_ANS_PTY", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 697 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 698 | |
| 699 | success = buffer_get_int(&m); |
| 700 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 701 | debug3("%s: pty alloc failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 702 | buffer_free(&m); |
| 703 | return (0); |
| 704 | } |
| 705 | p = buffer_get_string(&m, NULL); |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 706 | msg = buffer_get_string(&m, NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 707 | buffer_free(&m); |
| 708 | |
| 709 | strlcpy(namebuf, p, namebuflen); /* Possible truncation */ |
| 710 | xfree(p); |
| 711 | |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 712 | buffer_append(&loginmsg, msg, strlen(msg)); |
| 713 | xfree(msg); |
| 714 | |
Damien Miller | 54fd7cf | 2007-09-17 12:04:08 +1000 | [diff] [blame] | 715 | if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 || |
| 716 | (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1) |
| 717 | fatal("%s: receive fds failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 718 | |
| 719 | /* Success */ |
| 720 | return (1); |
| 721 | } |
| 722 | |
| 723 | void |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 724 | mm_session_pty_cleanup2(Session *s) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 725 | { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 726 | Buffer m; |
| 727 | |
| 728 | if (s->ttyfd == -1) |
| 729 | return; |
| 730 | buffer_init(&m); |
| 731 | buffer_put_cstring(&m, s->tty); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 732 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 733 | buffer_free(&m); |
| 734 | |
| 735 | /* closed dup'ed master */ |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 736 | if (s->ptymaster != -1 && close(s->ptymaster) < 0) |
| 737 | error("close(s->ptymaster/%d): %s", |
| 738 | s->ptymaster, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 739 | |
| 740 | /* unlink pty from session */ |
| 741 | s->ttyfd = -1; |
| 742 | } |
| 743 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 744 | #ifdef USE_PAM |
| 745 | void |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 746 | mm_start_pam(Authctxt *authctxt) |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 747 | { |
| 748 | Buffer m; |
| 749 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 750 | debug3("%s entering", __func__); |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 751 | if (!options.use_pam) |
| 752 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 753 | |
| 754 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 755 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, &m); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 756 | |
| 757 | buffer_free(&m); |
| 758 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 759 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 760 | u_int |
| 761 | mm_do_pam_account(void) |
| 762 | { |
| 763 | Buffer m; |
| 764 | u_int ret; |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 765 | char *msg; |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 766 | |
| 767 | debug3("%s entering", __func__); |
| 768 | if (!options.use_pam) |
| 769 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
| 770 | |
| 771 | buffer_init(&m); |
| 772 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_ACCOUNT, &m); |
| 773 | |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 774 | mm_request_receive_expect(pmonitor->m_recvfd, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 775 | MONITOR_ANS_PAM_ACCOUNT, &m); |
| 776 | ret = buffer_get_int(&m); |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 777 | msg = buffer_get_string(&m, NULL); |
| 778 | buffer_append(&loginmsg, msg, strlen(msg)); |
| 779 | xfree(msg); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 780 | |
| 781 | buffer_free(&m); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 782 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 783 | debug3("%s returning %d", __func__, ret); |
| 784 | |
| 785 | return (ret); |
| 786 | } |
| 787 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 788 | void * |
| 789 | mm_sshpam_init_ctx(Authctxt *authctxt) |
| 790 | { |
| 791 | Buffer m; |
| 792 | int success; |
| 793 | |
| 794 | debug3("%s", __func__); |
| 795 | buffer_init(&m); |
| 796 | buffer_put_cstring(&m, authctxt->user); |
| 797 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_INIT_CTX, &m); |
| 798 | debug3("%s: waiting for MONITOR_ANS_PAM_INIT_CTX", __func__); |
| 799 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_INIT_CTX, &m); |
| 800 | success = buffer_get_int(&m); |
| 801 | if (success == 0) { |
| 802 | debug3("%s: pam_init_ctx failed", __func__); |
| 803 | buffer_free(&m); |
| 804 | return (NULL); |
| 805 | } |
| 806 | buffer_free(&m); |
| 807 | return (authctxt); |
| 808 | } |
| 809 | |
| 810 | int |
| 811 | mm_sshpam_query(void *ctx, char **name, char **info, |
| 812 | u_int *num, char ***prompts, u_int **echo_on) |
| 813 | { |
| 814 | Buffer m; |
Damien Miller | 04b6533 | 2005-07-17 17:53:31 +1000 | [diff] [blame] | 815 | u_int i; |
| 816 | int ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 817 | |
| 818 | debug3("%s", __func__); |
| 819 | buffer_init(&m); |
| 820 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_QUERY, &m); |
| 821 | debug3("%s: waiting for MONITOR_ANS_PAM_QUERY", __func__); |
| 822 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_QUERY, &m); |
| 823 | ret = buffer_get_int(&m); |
| 824 | debug3("%s: pam_query returned %d", __func__, ret); |
| 825 | *name = buffer_get_string(&m, NULL); |
| 826 | *info = buffer_get_string(&m, NULL); |
| 827 | *num = buffer_get_int(&m); |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 828 | if (*num > PAM_MAX_NUM_MSG) |
| 829 | fatal("%s: recieved %u PAM messages, expected <= %u", |
| 830 | __func__, *num, PAM_MAX_NUM_MSG); |
| 831 | *prompts = xcalloc((*num + 1), sizeof(char *)); |
| 832 | *echo_on = xcalloc((*num + 1), sizeof(u_int)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 833 | for (i = 0; i < *num; ++i) { |
| 834 | (*prompts)[i] = buffer_get_string(&m, NULL); |
| 835 | (*echo_on)[i] = buffer_get_int(&m); |
| 836 | } |
| 837 | buffer_free(&m); |
| 838 | return (ret); |
| 839 | } |
| 840 | |
| 841 | int |
| 842 | mm_sshpam_respond(void *ctx, u_int num, char **resp) |
| 843 | { |
| 844 | Buffer m; |
Damien Miller | 04b6533 | 2005-07-17 17:53:31 +1000 | [diff] [blame] | 845 | u_int i; |
| 846 | int ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 847 | |
| 848 | debug3("%s", __func__); |
| 849 | buffer_init(&m); |
| 850 | buffer_put_int(&m, num); |
| 851 | for (i = 0; i < num; ++i) |
| 852 | buffer_put_cstring(&m, resp[i]); |
| 853 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_RESPOND, &m); |
| 854 | debug3("%s: waiting for MONITOR_ANS_PAM_RESPOND", __func__); |
| 855 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_RESPOND, &m); |
| 856 | ret = buffer_get_int(&m); |
| 857 | debug3("%s: pam_respond returned %d", __func__, ret); |
| 858 | buffer_free(&m); |
| 859 | return (ret); |
| 860 | } |
| 861 | |
| 862 | void |
| 863 | mm_sshpam_free_ctx(void *ctxtp) |
| 864 | { |
| 865 | Buffer m; |
| 866 | |
| 867 | debug3("%s", __func__); |
| 868 | buffer_init(&m); |
| 869 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_FREE_CTX, &m); |
| 870 | debug3("%s: waiting for MONITOR_ANS_PAM_FREE_CTX", __func__); |
| 871 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_FREE_CTX, &m); |
| 872 | buffer_free(&m); |
| 873 | } |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 874 | #endif /* USE_PAM */ |
| 875 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 876 | /* Request process termination */ |
| 877 | |
| 878 | void |
| 879 | mm_terminate(void) |
| 880 | { |
| 881 | Buffer m; |
| 882 | |
| 883 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 884 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 885 | buffer_free(&m); |
| 886 | } |
| 887 | |
| 888 | int |
| 889 | mm_ssh1_session_key(BIGNUM *num) |
| 890 | { |
| 891 | int rsafail; |
| 892 | Buffer m; |
| 893 | |
| 894 | buffer_init(&m); |
| 895 | buffer_put_bignum2(&m, num); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 896 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSKEY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 897 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 898 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SESSKEY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 899 | |
| 900 | rsafail = buffer_get_int(&m); |
| 901 | buffer_get_bignum2(&m, num); |
| 902 | |
| 903 | buffer_free(&m); |
| 904 | |
| 905 | return (rsafail); |
| 906 | } |
| 907 | |
| 908 | static void |
| 909 | mm_chall_setup(char **name, char **infotxt, u_int *numprompts, |
| 910 | char ***prompts, u_int **echo_on) |
| 911 | { |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 912 | *name = xstrdup(""); |
| 913 | *infotxt = xstrdup(""); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 914 | *numprompts = 1; |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 915 | *prompts = xcalloc(*numprompts, sizeof(char *)); |
| 916 | *echo_on = xcalloc(*numprompts, sizeof(u_int)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 917 | (*echo_on)[0] = 0; |
| 918 | } |
| 919 | |
| 920 | int |
| 921 | mm_bsdauth_query(void *ctx, char **name, char **infotxt, |
| 922 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 923 | { |
| 924 | Buffer m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 925 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 926 | char *challenge; |
| 927 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 928 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 929 | |
| 930 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 931 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 932 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 933 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 934 | &m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 935 | success = buffer_get_int(&m); |
| 936 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 937 | debug3("%s: no challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 938 | buffer_free(&m); |
| 939 | return (-1); |
| 940 | } |
| 941 | |
| 942 | /* Get the challenge, and format the response */ |
| 943 | challenge = buffer_get_string(&m, NULL); |
| 944 | buffer_free(&m); |
| 945 | |
| 946 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 947 | (*prompts)[0] = challenge; |
| 948 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 949 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 950 | |
| 951 | return (0); |
| 952 | } |
| 953 | |
| 954 | int |
| 955 | mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses) |
| 956 | { |
| 957 | Buffer m; |
| 958 | int authok; |
| 959 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 960 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 961 | if (numresponses != 1) |
| 962 | return (-1); |
| 963 | |
| 964 | buffer_init(&m); |
| 965 | buffer_put_cstring(&m, responses[0]); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 966 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 967 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 968 | mm_request_receive_expect(pmonitor->m_recvfd, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 969 | MONITOR_ANS_BSDAUTHRESPOND, &m); |
| 970 | |
| 971 | authok = buffer_get_int(&m); |
| 972 | buffer_free(&m); |
| 973 | |
| 974 | return ((authok == 0) ? -1 : 0); |
| 975 | } |
| 976 | |
Darren Tucker | 042e2e8 | 2004-07-08 23:09:42 +1000 | [diff] [blame] | 977 | #ifdef SKEY |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 978 | int |
| 979 | mm_skey_query(void *ctx, char **name, char **infotxt, |
| 980 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 981 | { |
| 982 | Buffer m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 983 | u_int success; |
Darren Tucker | d6a23f2 | 2006-08-05 18:50:35 +1000 | [diff] [blame] | 984 | char *challenge; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 985 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 986 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 987 | |
| 988 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 989 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYQUERY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 990 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 991 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SKEYQUERY, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 992 | &m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 993 | success = buffer_get_int(&m); |
| 994 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 995 | debug3("%s: no challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 996 | buffer_free(&m); |
| 997 | return (-1); |
| 998 | } |
| 999 | |
| 1000 | /* Get the challenge, and format the response */ |
| 1001 | challenge = buffer_get_string(&m, NULL); |
| 1002 | buffer_free(&m); |
| 1003 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1004 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1005 | |
| 1006 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 1007 | |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 1008 | xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1009 | xfree(challenge); |
| 1010 | |
| 1011 | return (0); |
| 1012 | } |
| 1013 | |
| 1014 | int |
| 1015 | mm_skey_respond(void *ctx, u_int numresponses, char **responses) |
| 1016 | { |
| 1017 | Buffer m; |
| 1018 | int authok; |
| 1019 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1020 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1021 | if (numresponses != 1) |
| 1022 | return (-1); |
| 1023 | |
| 1024 | buffer_init(&m); |
| 1025 | buffer_put_cstring(&m, responses[0]); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1026 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYRESPOND, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1027 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1028 | mm_request_receive_expect(pmonitor->m_recvfd, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1029 | MONITOR_ANS_SKEYRESPOND, &m); |
| 1030 | |
| 1031 | authok = buffer_get_int(&m); |
| 1032 | buffer_free(&m); |
| 1033 | |
| 1034 | return ((authok == 0) ? -1 : 0); |
| 1035 | } |
Darren Tucker | 042e2e8 | 2004-07-08 23:09:42 +1000 | [diff] [blame] | 1036 | #endif /* SKEY */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1037 | |
| 1038 | void |
| 1039 | mm_ssh1_session_id(u_char session_id[16]) |
| 1040 | { |
| 1041 | Buffer m; |
| 1042 | int i; |
| 1043 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1044 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1045 | |
| 1046 | buffer_init(&m); |
| 1047 | for (i = 0; i < 16; i++) |
| 1048 | buffer_put_char(&m, session_id[i]); |
| 1049 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1050 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSID, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1051 | buffer_free(&m); |
| 1052 | } |
| 1053 | |
| 1054 | int |
| 1055 | mm_auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey) |
| 1056 | { |
| 1057 | Buffer m; |
| 1058 | Key *key; |
| 1059 | u_char *blob; |
| 1060 | u_int blen; |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1061 | int allowed = 0, have_forced = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1062 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1063 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1064 | |
| 1065 | buffer_init(&m); |
| 1066 | buffer_put_bignum2(&m, client_n); |
| 1067 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1068 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSAKEYALLOWED, &m); |
| 1069 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSAKEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1070 | |
| 1071 | allowed = buffer_get_int(&m); |
| 1072 | |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1073 | /* fake forced command */ |
| 1074 | auth_clear_options(); |
| 1075 | have_forced = buffer_get_int(&m); |
| 1076 | forced_command = have_forced ? xstrdup("true") : NULL; |
| 1077 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1078 | if (allowed && rkey != NULL) { |
| 1079 | blob = buffer_get_string(&m, &blen); |
| 1080 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1081 | fatal("%s: key_from_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1082 | *rkey = key; |
| 1083 | xfree(blob); |
| 1084 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1085 | buffer_free(&m); |
| 1086 | |
| 1087 | return (allowed); |
| 1088 | } |
| 1089 | |
| 1090 | BIGNUM * |
| 1091 | mm_auth_rsa_generate_challenge(Key *key) |
| 1092 | { |
| 1093 | Buffer m; |
| 1094 | BIGNUM *challenge; |
| 1095 | u_char *blob; |
| 1096 | u_int blen; |
| 1097 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1098 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1099 | |
| 1100 | if ((challenge = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1101 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1102 | |
| 1103 | key->type = KEY_RSA; /* XXX cheat for key_to_blob */ |
| 1104 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1105 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1106 | key->type = KEY_RSA1; |
| 1107 | |
| 1108 | buffer_init(&m); |
| 1109 | buffer_put_string(&m, blob, blen); |
| 1110 | xfree(blob); |
| 1111 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1112 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSACHALLENGE, &m); |
| 1113 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSACHALLENGE, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1114 | |
| 1115 | buffer_get_bignum2(&m, challenge); |
| 1116 | buffer_free(&m); |
| 1117 | |
| 1118 | return (challenge); |
| 1119 | } |
| 1120 | |
| 1121 | int |
| 1122 | mm_auth_rsa_verify_response(Key *key, BIGNUM *p, u_char response[16]) |
| 1123 | { |
| 1124 | Buffer m; |
| 1125 | u_char *blob; |
| 1126 | u_int blen; |
| 1127 | int success = 0; |
| 1128 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1129 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1130 | |
| 1131 | key->type = KEY_RSA; /* XXX cheat for key_to_blob */ |
| 1132 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1133 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1134 | key->type = KEY_RSA1; |
| 1135 | |
| 1136 | buffer_init(&m); |
| 1137 | buffer_put_string(&m, blob, blen); |
| 1138 | buffer_put_string(&m, response, 16); |
| 1139 | xfree(blob); |
| 1140 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1141 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSARESPONSE, &m); |
| 1142 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSARESPONSE, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1143 | |
| 1144 | success = buffer_get_int(&m); |
| 1145 | buffer_free(&m); |
| 1146 | |
| 1147 | return (success); |
| 1148 | } |
Damien Miller | 25162f2 | 2002-09-12 09:47:29 +1000 | [diff] [blame] | 1149 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1150 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1151 | void |
| 1152 | mm_audit_event(ssh_audit_event_t event) |
| 1153 | { |
| 1154 | Buffer m; |
| 1155 | |
| 1156 | debug3("%s entering", __func__); |
| 1157 | |
| 1158 | buffer_init(&m); |
| 1159 | buffer_put_int(&m, event); |
| 1160 | |
| 1161 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_EVENT, &m); |
| 1162 | buffer_free(&m); |
| 1163 | } |
| 1164 | |
| 1165 | void |
| 1166 | mm_audit_run_command(const char *command) |
| 1167 | { |
| 1168 | Buffer m; |
| 1169 | |
| 1170 | debug3("%s entering command %s", __func__, command); |
| 1171 | |
| 1172 | buffer_init(&m); |
| 1173 | buffer_put_cstring(&m, command); |
| 1174 | |
| 1175 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_COMMAND, &m); |
| 1176 | buffer_free(&m); |
| 1177 | } |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1178 | #endif /* SSH_AUDIT_EVENTS */ |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1179 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1180 | #ifdef GSSAPI |
| 1181 | OM_uint32 |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1182 | mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1183 | { |
| 1184 | Buffer m; |
| 1185 | OM_uint32 major; |
| 1186 | |
| 1187 | /* Client doesn't get to see the context */ |
| 1188 | *ctx = NULL; |
| 1189 | |
| 1190 | buffer_init(&m); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1191 | buffer_put_string(&m, goid->elements, goid->length); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1192 | |
| 1193 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, &m); |
| 1194 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, &m); |
| 1195 | |
| 1196 | major = buffer_get_int(&m); |
| 1197 | |
| 1198 | buffer_free(&m); |
| 1199 | return (major); |
| 1200 | } |
| 1201 | |
| 1202 | OM_uint32 |
| 1203 | mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in, |
| 1204 | gss_buffer_desc *out, OM_uint32 *flags) |
| 1205 | { |
| 1206 | Buffer m; |
| 1207 | OM_uint32 major; |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1208 | u_int len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1209 | |
| 1210 | buffer_init(&m); |
| 1211 | buffer_put_string(&m, in->value, in->length); |
| 1212 | |
| 1213 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, &m); |
| 1214 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, &m); |
| 1215 | |
| 1216 | major = buffer_get_int(&m); |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1217 | out->value = buffer_get_string(&m, &len); |
| 1218 | out->length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1219 | if (flags) |
| 1220 | *flags = buffer_get_int(&m); |
| 1221 | |
| 1222 | buffer_free(&m); |
| 1223 | |
| 1224 | return (major); |
| 1225 | } |
| 1226 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1227 | OM_uint32 |
| 1228 | mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) |
| 1229 | { |
| 1230 | Buffer m; |
| 1231 | OM_uint32 major; |
| 1232 | |
| 1233 | buffer_init(&m); |
| 1234 | buffer_put_string(&m, gssbuf->value, gssbuf->length); |
| 1235 | buffer_put_string(&m, gssmic->value, gssmic->length); |
| 1236 | |
| 1237 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, &m); |
| 1238 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSCHECKMIC, |
| 1239 | &m); |
| 1240 | |
| 1241 | major = buffer_get_int(&m); |
| 1242 | buffer_free(&m); |
| 1243 | return(major); |
| 1244 | } |
| 1245 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1246 | int |
| 1247 | mm_ssh_gssapi_userok(char *user) |
| 1248 | { |
| 1249 | Buffer m; |
| 1250 | int authenticated = 0; |
| 1251 | |
| 1252 | buffer_init(&m); |
| 1253 | |
| 1254 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, &m); |
| 1255 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUSEROK, |
| 1256 | &m); |
| 1257 | |
| 1258 | authenticated = buffer_get_int(&m); |
| 1259 | |
| 1260 | buffer_free(&m); |
| 1261 | debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not "); |
| 1262 | return (authenticated); |
| 1263 | } |
| 1264 | #endif /* GSSAPI */ |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1265 | |
| 1266 | #ifdef JPAKE |
| 1267 | void |
| 1268 | mm_auth2_jpake_get_pwdata(Authctxt *authctxt, BIGNUM **s, |
| 1269 | char **hash_scheme, char **salt) |
| 1270 | { |
| 1271 | Buffer m; |
| 1272 | |
| 1273 | debug3("%s entering", __func__); |
| 1274 | |
| 1275 | buffer_init(&m); |
| 1276 | mm_request_send(pmonitor->m_recvfd, |
| 1277 | MONITOR_REQ_JPAKE_GET_PWDATA, &m); |
| 1278 | |
| 1279 | debug3("%s: waiting for MONITOR_ANS_JPAKE_GET_PWDATA", __func__); |
| 1280 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 1281 | MONITOR_ANS_JPAKE_GET_PWDATA, &m); |
| 1282 | |
| 1283 | *hash_scheme = buffer_get_string(&m, NULL); |
| 1284 | *salt = buffer_get_string(&m, NULL); |
| 1285 | |
| 1286 | buffer_free(&m); |
| 1287 | } |
| 1288 | |
| 1289 | void |
Damien Miller | cee8523 | 2009-03-06 00:58:22 +1100 | [diff] [blame] | 1290 | mm_jpake_step1(struct modp_group *grp, |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1291 | u_char **id, u_int *id_len, |
| 1292 | BIGNUM **priv1, BIGNUM **priv2, BIGNUM **g_priv1, BIGNUM **g_priv2, |
| 1293 | u_char **priv1_proof, u_int *priv1_proof_len, |
| 1294 | u_char **priv2_proof, u_int *priv2_proof_len) |
| 1295 | { |
| 1296 | Buffer m; |
| 1297 | |
| 1298 | debug3("%s entering", __func__); |
| 1299 | |
| 1300 | buffer_init(&m); |
| 1301 | mm_request_send(pmonitor->m_recvfd, |
| 1302 | MONITOR_REQ_JPAKE_STEP1, &m); |
| 1303 | |
| 1304 | debug3("%s: waiting for MONITOR_ANS_JPAKE_STEP1", __func__); |
| 1305 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 1306 | MONITOR_ANS_JPAKE_STEP1, &m); |
| 1307 | |
| 1308 | if ((*priv1 = BN_new()) == NULL || |
| 1309 | (*priv2 = BN_new()) == NULL || |
| 1310 | (*g_priv1 = BN_new()) == NULL || |
| 1311 | (*g_priv2 = BN_new()) == NULL) |
| 1312 | fatal("%s: BN_new", __func__); |
| 1313 | |
| 1314 | *id = buffer_get_string(&m, id_len); |
| 1315 | /* priv1 and priv2 are, well, private */ |
| 1316 | buffer_get_bignum2(&m, *g_priv1); |
| 1317 | buffer_get_bignum2(&m, *g_priv2); |
| 1318 | *priv1_proof = buffer_get_string(&m, priv1_proof_len); |
| 1319 | *priv2_proof = buffer_get_string(&m, priv2_proof_len); |
| 1320 | |
| 1321 | buffer_free(&m); |
| 1322 | } |
| 1323 | |
| 1324 | void |
Damien Miller | cee8523 | 2009-03-06 00:58:22 +1100 | [diff] [blame] | 1325 | mm_jpake_step2(struct modp_group *grp, BIGNUM *s, |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1326 | BIGNUM *mypub1, BIGNUM *theirpub1, BIGNUM *theirpub2, BIGNUM *mypriv2, |
| 1327 | const u_char *theirid, u_int theirid_len, |
| 1328 | const u_char *myid, u_int myid_len, |
| 1329 | const u_char *theirpub1_proof, u_int theirpub1_proof_len, |
| 1330 | const u_char *theirpub2_proof, u_int theirpub2_proof_len, |
| 1331 | BIGNUM **newpub, |
| 1332 | u_char **newpub_exponent_proof, u_int *newpub_exponent_proof_len) |
| 1333 | { |
| 1334 | Buffer m; |
| 1335 | |
| 1336 | debug3("%s entering", __func__); |
| 1337 | |
| 1338 | buffer_init(&m); |
| 1339 | /* monitor already has all bignums except theirpub1, theirpub2 */ |
| 1340 | buffer_put_bignum2(&m, theirpub1); |
| 1341 | buffer_put_bignum2(&m, theirpub2); |
| 1342 | /* monitor already knows our id */ |
| 1343 | buffer_put_string(&m, theirid, theirid_len); |
| 1344 | buffer_put_string(&m, theirpub1_proof, theirpub1_proof_len); |
| 1345 | buffer_put_string(&m, theirpub2_proof, theirpub2_proof_len); |
| 1346 | |
| 1347 | mm_request_send(pmonitor->m_recvfd, |
| 1348 | MONITOR_REQ_JPAKE_STEP2, &m); |
| 1349 | |
| 1350 | debug3("%s: waiting for MONITOR_ANS_JPAKE_STEP2", __func__); |
| 1351 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 1352 | MONITOR_ANS_JPAKE_STEP2, &m); |
| 1353 | |
| 1354 | if ((*newpub = BN_new()) == NULL) |
| 1355 | fatal("%s: BN_new", __func__); |
| 1356 | |
| 1357 | buffer_get_bignum2(&m, *newpub); |
| 1358 | *newpub_exponent_proof = buffer_get_string(&m, |
| 1359 | newpub_exponent_proof_len); |
| 1360 | |
| 1361 | buffer_free(&m); |
| 1362 | } |
| 1363 | |
| 1364 | void |
Damien Miller | cee8523 | 2009-03-06 00:58:22 +1100 | [diff] [blame] | 1365 | mm_jpake_key_confirm(struct modp_group *grp, BIGNUM *s, BIGNUM *step2_val, |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1366 | BIGNUM *mypriv2, BIGNUM *mypub1, BIGNUM *mypub2, |
| 1367 | BIGNUM *theirpub1, BIGNUM *theirpub2, |
| 1368 | const u_char *my_id, u_int my_id_len, |
| 1369 | const u_char *their_id, u_int their_id_len, |
| 1370 | const u_char *sess_id, u_int sess_id_len, |
| 1371 | const u_char *theirpriv2_s_proof, u_int theirpriv2_s_proof_len, |
| 1372 | BIGNUM **k, |
| 1373 | u_char **confirm_hash, u_int *confirm_hash_len) |
| 1374 | { |
| 1375 | Buffer m; |
| 1376 | |
| 1377 | debug3("%s entering", __func__); |
| 1378 | |
| 1379 | buffer_init(&m); |
| 1380 | /* monitor already has all bignums except step2_val */ |
| 1381 | buffer_put_bignum2(&m, step2_val); |
| 1382 | /* monitor already knows all the ids */ |
| 1383 | buffer_put_string(&m, theirpriv2_s_proof, theirpriv2_s_proof_len); |
| 1384 | |
| 1385 | mm_request_send(pmonitor->m_recvfd, |
| 1386 | MONITOR_REQ_JPAKE_KEY_CONFIRM, &m); |
| 1387 | |
| 1388 | debug3("%s: waiting for MONITOR_ANS_JPAKE_KEY_CONFIRM", __func__); |
| 1389 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 1390 | MONITOR_ANS_JPAKE_KEY_CONFIRM, &m); |
| 1391 | |
| 1392 | /* 'k' is sensitive and stays in the monitor */ |
| 1393 | *confirm_hash = buffer_get_string(&m, confirm_hash_len); |
| 1394 | |
| 1395 | buffer_free(&m); |
| 1396 | } |
| 1397 | |
| 1398 | int |
| 1399 | mm_jpake_check_confirm(const BIGNUM *k, |
| 1400 | const u_char *peer_id, u_int peer_id_len, |
| 1401 | const u_char *sess_id, u_int sess_id_len, |
| 1402 | const u_char *peer_confirm_hash, u_int peer_confirm_hash_len) |
| 1403 | { |
| 1404 | Buffer m; |
| 1405 | int success = 0; |
| 1406 | |
| 1407 | debug3("%s entering", __func__); |
| 1408 | |
| 1409 | buffer_init(&m); |
| 1410 | /* k is dummy in slave, ignored */ |
| 1411 | /* monitor knows all the ids */ |
| 1412 | buffer_put_string(&m, peer_confirm_hash, peer_confirm_hash_len); |
| 1413 | mm_request_send(pmonitor->m_recvfd, |
| 1414 | MONITOR_REQ_JPAKE_CHECK_CONFIRM, &m); |
| 1415 | |
| 1416 | debug3("%s: waiting for MONITOR_ANS_JPAKE_CHECK_CONFIRM", __func__); |
| 1417 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 1418 | MONITOR_ANS_JPAKE_CHECK_CONFIRM, &m); |
| 1419 | |
| 1420 | success = buffer_get_int(&m); |
| 1421 | buffer_free(&m); |
| 1422 | |
| 1423 | debug3("%s: success = %d", __func__, success); |
| 1424 | return success; |
| 1425 | } |
| 1426 | #endif /* JPAKE */ |