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