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