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