2 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
3 * Copyright 2002 Markus Friedl <markus@openbsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 RCSID("$OpenBSD: monitor_wrap.c,v 1.19 2002/09/26 11:38:43 markus Exp $");
29 RCSID("$FreeBSD: src/crypto/openssh/monitor_wrap.c,v 1.3.2.2 2003/02/03 17:31:07 des Exp $");
30 RCSID("$DragonFly: src/crypto/openssh/Attic/monitor_wrap.c,v 1.2 2003/06/17 04:24:36 dillon Exp $");
32 #include <openssl/bn.h>
33 #include <openssl/dh.h>
46 #include "monitor_wrap.h"
49 #include "monitor_fdpass.h"
58 extern Newkeys *newkeys[];
59 extern z_stream incoming_stream;
60 extern z_stream outgoing_stream;
61 extern struct monitor *pmonitor;
62 extern Buffer input, output;
65 mm_request_send(int socket, enum monitor_reqtype type, Buffer *m)
67 u_int mlen = buffer_len(m);
70 debug3("%s entering: type %d", __func__, type);
72 PUT_32BIT(buf, mlen + 1);
73 buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
74 if (atomicio(write, socket, buf, sizeof(buf)) != sizeof(buf))
75 fatal("%s: write", __func__);
76 if (atomicio(write, socket, buffer_ptr(m), mlen) != mlen)
77 fatal("%s: write", __func__);
81 mm_request_receive(int socket, Buffer *m)
87 debug3("%s entering", __func__);
89 res = atomicio(read, socket, buf, sizeof(buf));
90 if (res != sizeof(buf)) {
93 fatal("%s: read: %ld", __func__, (long)res);
95 msg_len = GET_32BIT(buf);
96 if (msg_len > 256 * 1024)
97 fatal("%s: read: bad msg_len %d", __func__, msg_len);
99 buffer_append_space(m, msg_len);
100 res = atomicio(read, socket, buffer_ptr(m), msg_len);
102 fatal("%s: read: %ld != msg_len", __func__, (long)res);
106 mm_request_receive_expect(int socket, enum monitor_reqtype type, Buffer *m)
110 debug3("%s entering: type %d", __func__, type);
112 mm_request_receive(socket, m);
113 rtype = buffer_get_char(m);
115 fatal("%s: read: rtype %d != type %d", __func__,
120 mm_choose_dh(int min, int nbits, int max)
127 buffer_put_int(&m, min);
128 buffer_put_int(&m, nbits);
129 buffer_put_int(&m, max);
131 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m);
133 debug3("%s: waiting for MONITOR_ANS_MODULI", __func__);
134 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m);
136 success = buffer_get_char(&m);
138 fatal("%s: MONITOR_ANS_MODULI failed", __func__);
140 if ((p = BN_new()) == NULL)
141 fatal("%s: BN_new failed", __func__);
142 if ((g = BN_new()) == NULL)
143 fatal("%s: BN_new failed", __func__);
144 buffer_get_bignum2(&m, p);
145 buffer_get_bignum2(&m, g);
147 debug3("%s: remaining %d", __func__, buffer_len(&m));
150 return (dh_new_group(g, p));
154 mm_key_sign(Key *key, u_char **sigp, u_int *lenp, u_char *data, u_int datalen)
156 Kex *kex = *pmonitor->m_pkex;
159 debug3("%s entering", __func__);
162 buffer_put_int(&m, kex->host_key_index(key));
163 buffer_put_string(&m, data, datalen);
165 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m);
167 debug3("%s: waiting for MONITOR_ANS_SIGN", __func__);
168 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m);
169 *sigp = buffer_get_string(&m, lenp);
176 mm_getpwnamallow(const char *login)
182 debug3("%s entering", __func__);
185 buffer_put_cstring(&m, login);
187 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m);
189 debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__);
190 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m);
192 if (buffer_get_char(&m) == 0) {
196 pw = buffer_get_string(&m, &pwlen);
197 if (pwlen != sizeof(struct passwd))
198 fatal("%s: struct passwd size mismatch", __func__);
199 pw->pw_name = buffer_get_string(&m, NULL);
200 pw->pw_passwd = buffer_get_string(&m, NULL);
201 pw->pw_gecos = buffer_get_string(&m, NULL);
202 #ifdef HAVE_PW_CLASS_IN_PASSWD
203 pw->pw_class = buffer_get_string(&m, NULL);
205 pw->pw_dir = buffer_get_string(&m, NULL);
206 pw->pw_shell = buffer_get_string(&m, NULL);
212 char *mm_auth2_read_banner(void)
217 debug3("%s entering", __func__);
220 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m);
223 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTH2_READ_BANNER, &m);
224 banner = buffer_get_string(&m, NULL);
230 /* Inform the privileged process about service and style */
233 mm_inform_authserv(char *service, char *style)
237 debug3("%s entering", __func__);
240 buffer_put_cstring(&m, service);
241 buffer_put_cstring(&m, style ? style : "");
243 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
248 /* Do the password authentication */
250 mm_auth_password(Authctxt *authctxt, char *password)
253 int authenticated = 0;
255 debug3("%s entering", __func__);
258 buffer_put_cstring(&m, password);
259 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m);
261 debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__);
262 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m);
264 authenticated = buffer_get_int(&m);
268 debug3("%s: user %sauthenticated",
269 __func__, authenticated ? "" : "not ");
270 return (authenticated);
274 mm_user_key_allowed(struct passwd *pw, Key *key)
276 return (mm_key_allowed(MM_USERKEY, NULL, NULL, key));
280 mm_hostbased_key_allowed(struct passwd *pw, char *user, char *host,
283 return (mm_key_allowed(MM_HOSTKEY, user, host, key));
287 mm_auth_rhosts_rsa_key_allowed(struct passwd *pw, char *user,
288 char *host, Key *key)
292 key->type = KEY_RSA; /* XXX hack for key_to_blob */
293 ret = mm_key_allowed(MM_RSAHOSTKEY, user, host, key);
294 key->type = KEY_RSA1;
299 mm_send_debug(Buffer *m)
303 while (buffer_len(m)) {
304 msg = buffer_get_string(m, NULL);
305 debug3("%s: Sending debug: %s", __func__, msg);
306 packet_send_debug("%s", msg);
312 mm_key_allowed(enum mm_keytype type, char *user, char *host, Key *key)
319 debug3("%s entering", __func__);
321 /* Convert the key to a blob and the pass it over */
322 if (!key_to_blob(key, &blob, &len))
326 buffer_put_int(&m, type);
327 buffer_put_cstring(&m, user ? user : "");
328 buffer_put_cstring(&m, host ? host : "");
329 buffer_put_string(&m, blob, len);
332 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m);
334 debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__);
335 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m);
337 allowed = buffer_get_int(&m);
339 /* Send potential debug messages */
348 * This key verify needs to send the key type along, because the
349 * privileged parent makes the decision if the key is allowed
350 * for authentication.
354 mm_key_verify(Key *key, u_char *sig, u_int siglen, u_char *data, u_int datalen)
361 debug3("%s entering", __func__);
363 /* Convert the key to a blob and the pass it over */
364 if (!key_to_blob(key, &blob, &len))
368 buffer_put_string(&m, blob, len);
369 buffer_put_string(&m, sig, siglen);
370 buffer_put_string(&m, data, datalen);
373 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m);
375 debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__);
376 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m);
378 verified = buffer_get_int(&m);
385 /* Export key state after authentication */
387 mm_newkeys_from_blob(u_char *blob, int blen)
391 Newkeys *newkey = NULL;
396 debug3("%s: %p(%d)", __func__, blob, blen);
398 dump_base64(stderr, blob, blen);
401 buffer_append(&b, blob, blen);
403 newkey = xmalloc(sizeof(*newkey));
406 comp = &newkey->comp;
409 enc->name = buffer_get_string(&b, NULL);
410 buffer_get(&b, &enc->cipher, sizeof(enc->cipher));
411 enc->enabled = buffer_get_int(&b);
412 enc->block_size = buffer_get_int(&b);
413 enc->key = buffer_get_string(&b, &enc->key_len);
414 enc->iv = buffer_get_string(&b, &len);
415 if (len != enc->block_size)
416 fatal("%s: bad ivlen: expected %u != %u", __func__,
417 enc->block_size, len);
419 if (enc->name == NULL || cipher_by_name(enc->name) != enc->cipher)
420 fatal("%s: bad cipher name %s or pointer %p", __func__,
421 enc->name, enc->cipher);
424 mac->name = buffer_get_string(&b, NULL);
425 if (mac->name == NULL || mac_init(mac, mac->name) == -1)
426 fatal("%s: can not init mac %s", __func__, mac->name);
427 mac->enabled = buffer_get_int(&b);
428 mac->key = buffer_get_string(&b, &len);
429 if (len > mac->key_len)
430 fatal("%s: bad mac key length: %u > %d", __func__, len,
435 comp->type = buffer_get_int(&b);
436 comp->enabled = buffer_get_int(&b);
437 comp->name = buffer_get_string(&b, NULL);
439 len = buffer_len(&b);
441 error("newkeys_from_blob: remaining bytes in blob %u", len);
447 mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp)
454 Newkeys *newkey = newkeys[mode];
456 debug3("%s: converting %p", __func__, newkey);
458 if (newkey == NULL) {
459 error("%s: newkey == NULL", __func__);
464 comp = &newkey->comp;
468 buffer_put_cstring(&b, enc->name);
469 /* The cipher struct is constant and shared, you export pointer */
470 buffer_append(&b, &enc->cipher, sizeof(enc->cipher));
471 buffer_put_int(&b, enc->enabled);
472 buffer_put_int(&b, enc->block_size);
473 buffer_put_string(&b, enc->key, enc->key_len);
474 packet_get_keyiv(mode, enc->iv, enc->block_size);
475 buffer_put_string(&b, enc->iv, enc->block_size);
478 buffer_put_cstring(&b, mac->name);
479 buffer_put_int(&b, mac->enabled);
480 buffer_put_string(&b, mac->key, mac->key_len);
483 buffer_put_int(&b, comp->type);
484 buffer_put_int(&b, comp->enabled);
485 buffer_put_cstring(&b, comp->name);
487 len = buffer_len(&b);
491 *blobp = xmalloc(len);
492 memcpy(*blobp, buffer_ptr(&b), len);
494 memset(buffer_ptr(&b), 0, len);
500 mm_send_kex(Buffer *m, Kex *kex)
502 buffer_put_string(m, kex->session_id, kex->session_id_len);
503 buffer_put_int(m, kex->we_need);
504 buffer_put_int(m, kex->hostkey_type);
505 buffer_put_int(m, kex->kex_type);
506 buffer_put_string(m, buffer_ptr(&kex->my), buffer_len(&kex->my));
507 buffer_put_string(m, buffer_ptr(&kex->peer), buffer_len(&kex->peer));
508 buffer_put_int(m, kex->flags);
509 buffer_put_cstring(m, kex->client_version_string);
510 buffer_put_cstring(m, kex->server_version_string);
514 mm_send_keystate(struct monitor *pmonitor)
527 buffer_put_int(&m, packet_get_protocol_flags());
529 buffer_put_int(&m, packet_get_ssh1_cipher());
531 debug3("%s: Sending ssh1 KEY+IV", __func__);
532 keylen = packet_get_encryption_key(NULL);
533 key = xmalloc(keylen+1); /* add 1 if keylen == 0 */
534 keylen = packet_get_encryption_key(key);
535 buffer_put_string(&m, key, keylen);
536 memset(key, 0, keylen);
539 ivlen = packet_get_keyiv_len(MODE_OUT);
540 packet_get_keyiv(MODE_OUT, iv, ivlen);
541 buffer_put_string(&m, iv, ivlen);
542 ivlen = packet_get_keyiv_len(MODE_OUT);
543 packet_get_keyiv(MODE_IN, iv, ivlen);
544 buffer_put_string(&m, iv, ivlen);
547 /* Kex for rekeying */
548 mm_send_kex(&m, *pmonitor->m_pkex);
551 debug3("%s: Sending new keys: %p %p",
552 __func__, newkeys[MODE_OUT], newkeys[MODE_IN]);
555 if (!mm_newkeys_to_blob(MODE_OUT, &blob, &bloblen))
556 fatal("%s: conversion of newkeys failed", __func__);
558 buffer_put_string(&m, blob, bloblen);
561 if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen))
562 fatal("%s: conversion of newkeys failed", __func__);
564 buffer_put_string(&m, blob, bloblen);
567 buffer_put_int(&m, packet_get_seqnr(MODE_OUT));
568 buffer_put_int(&m, packet_get_seqnr(MODE_IN));
570 debug3("%s: New keys have been sent", __func__);
572 /* More key context */
573 plen = packet_get_keycontext(MODE_OUT, NULL);
575 packet_get_keycontext(MODE_OUT, p);
576 buffer_put_string(&m, p, plen);
579 plen = packet_get_keycontext(MODE_IN, NULL);
581 packet_get_keycontext(MODE_IN, p);
582 buffer_put_string(&m, p, plen);
585 /* Compression state */
586 debug3("%s: Sending compression state", __func__);
587 buffer_put_string(&m, &outgoing_stream, sizeof(outgoing_stream));
588 buffer_put_string(&m, &incoming_stream, sizeof(incoming_stream));
590 /* Network I/O buffers */
591 buffer_put_string(&m, buffer_ptr(&input), buffer_len(&input));
592 buffer_put_string(&m, buffer_ptr(&output), buffer_len(&output));
594 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYEXPORT, &m);
595 debug3("%s: Finished sending state", __func__);
601 mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
608 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
610 debug3("%s: waiting for MONITOR_ANS_PTY", __func__);
611 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m);
613 success = buffer_get_int(&m);
615 debug3("%s: pty alloc failed", __func__);
619 p = buffer_get_string(&m, NULL);
622 strlcpy(namebuf, p, namebuflen); /* Possible truncation */
625 *ptyfd = mm_receive_fd(pmonitor->m_recvfd);
626 *ttyfd = mm_receive_fd(pmonitor->m_recvfd);
633 mm_session_pty_cleanup2(void *session)
635 Session *s = session;
641 buffer_put_cstring(&m, s->tty);
642 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m);
645 /* closed dup'ed master */
646 if (close(s->ptymaster) < 0)
647 error("close(s->ptymaster): %s", strerror(errno));
649 /* unlink pty from session */
655 mm_start_pam(char *user)
659 debug3("%s entering", __func__);
662 buffer_put_cstring(&m, user);
664 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, &m);
670 mm_pam_init_ctx(Authctxt *authctxt)
675 debug3("%s", __func__);
677 buffer_put_cstring(&m, authctxt->user);
678 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_INIT_CTX, &m);
679 debug3("%s: waiting for MONITOR_ANS_PAM_INIT_CTX", __func__);
680 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_INIT_CTX, &m);
681 success = buffer_get_int(&m);
683 debug3("%s: pam_init_ctx failed", __func__);
692 mm_pam_query(void *ctx, char **name, char **info,
693 u_int *num, char ***prompts, u_int **echo_on)
698 debug3("%s", __func__);
700 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_QUERY, &m);
701 debug3("%s: waiting for MONITOR_ANS_PAM_QUERY", __func__);
702 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_QUERY, &m);
703 ret = buffer_get_int(&m);
704 debug3("%s: pam_query returned %d", __func__, ret);
705 *name = buffer_get_string(&m, NULL);
706 *info = buffer_get_string(&m, NULL);
707 *num = buffer_get_int(&m);
708 *prompts = xmalloc((*num + 1) * sizeof(char *));
709 *echo_on = xmalloc((*num + 1) * sizeof(u_int));
710 for (i = 0; i < *num; ++i) {
711 (*prompts)[i] = buffer_get_string(&m, NULL);
712 (*echo_on)[i] = buffer_get_int(&m);
719 mm_pam_respond(void *ctx, u_int num, char **resp)
724 debug3("%s", __func__);
726 buffer_put_int(&m, num);
727 for (i = 0; i < num; ++i)
728 buffer_put_cstring(&m, resp[i]);
729 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_RESPOND, &m);
730 debug3("%s: waiting for MONITOR_ANS_PAM_RESPOND", __func__);
731 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_RESPOND, &m);
732 ret = buffer_get_int(&m);
733 debug3("%s: pam_respond returned %d", __func__, ret);
739 mm_pam_free_ctx(void *ctxtp)
743 debug3("%s", __func__);
745 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_FREE_CTX, &m);
746 debug3("%s: waiting for MONITOR_ANS_PAM_FREE_CTX", __func__);
747 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_FREE_CTX, &m);
752 /* Request process termination */
760 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m);
765 mm_ssh1_session_key(BIGNUM *num)
771 buffer_put_bignum2(&m, num);
772 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSKEY, &m);
774 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SESSKEY, &m);
776 rsafail = buffer_get_int(&m);
777 buffer_get_bignum2(&m, num);
785 mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
786 char ***prompts, u_int **echo_on)
789 *infotxt = xstrdup("");
791 *prompts = xmalloc(*numprompts * sizeof(char *));
792 *echo_on = xmalloc(*numprompts * sizeof(u_int));
797 mm_bsdauth_query(void *ctx, char **name, char **infotxt,
798 u_int *numprompts, char ***prompts, u_int **echo_on)
804 debug3("%s: entering", __func__);
807 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m);
809 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY,
811 res = buffer_get_int(&m);
813 debug3("%s: no challenge", __func__);
818 /* Get the challenge, and format the response */
819 challenge = buffer_get_string(&m, NULL);
822 mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
823 (*prompts)[0] = challenge;
825 debug3("%s: received challenge: %s", __func__, challenge);
831 mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses)
836 debug3("%s: entering", __func__);
837 if (numresponses != 1)
841 buffer_put_cstring(&m, responses[0]);
842 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m);
844 mm_request_receive_expect(pmonitor->m_recvfd,
845 MONITOR_ANS_BSDAUTHRESPOND, &m);
847 authok = buffer_get_int(&m);
850 return ((authok == 0) ? -1 : 0);
855 mm_skey_query(void *ctx, char **name, char **infotxt,
856 u_int *numprompts, char ***prompts, u_int **echo_on)
862 debug3("%s: entering", __func__);
865 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYQUERY, &m);
867 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SKEYQUERY,
869 res = buffer_get_int(&m);
871 debug3("%s: no challenge", __func__);
876 /* Get the challenge, and format the response */
877 challenge = buffer_get_string(&m, NULL);
880 debug3("%s: received challenge: %s", __func__, challenge);
882 mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
884 len = strlen(challenge) + strlen(SKEY_PROMPT) + 1;
886 strlcpy(p, challenge, len);
887 strlcat(p, SKEY_PROMPT, len);
895 mm_skey_respond(void *ctx, u_int numresponses, char **responses)
900 debug3("%s: entering", __func__);
901 if (numresponses != 1)
905 buffer_put_cstring(&m, responses[0]);
906 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYRESPOND, &m);
908 mm_request_receive_expect(pmonitor->m_recvfd,
909 MONITOR_ANS_SKEYRESPOND, &m);
911 authok = buffer_get_int(&m);
914 return ((authok == 0) ? -1 : 0);
919 mm_ssh1_session_id(u_char session_id[16])
924 debug3("%s entering", __func__);
927 for (i = 0; i < 16; i++)
928 buffer_put_char(&m, session_id[i]);
930 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSID, &m);
935 mm_auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey)
943 debug3("%s entering", __func__);
946 buffer_put_bignum2(&m, client_n);
948 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSAKEYALLOWED, &m);
949 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSAKEYALLOWED, &m);
951 allowed = buffer_get_int(&m);
953 if (allowed && rkey != NULL) {
954 blob = buffer_get_string(&m, &blen);
955 if ((key = key_from_blob(blob, blen)) == NULL)
956 fatal("%s: key_from_blob failed", __func__);
967 mm_auth_rsa_generate_challenge(Key *key)
974 debug3("%s entering", __func__);
976 if ((challenge = BN_new()) == NULL)
977 fatal("%s: BN_new failed", __func__);
979 key->type = KEY_RSA; /* XXX cheat for key_to_blob */
980 if (key_to_blob(key, &blob, &blen) == 0)
981 fatal("%s: key_to_blob failed", __func__);
982 key->type = KEY_RSA1;
985 buffer_put_string(&m, blob, blen);
988 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSACHALLENGE, &m);
989 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSACHALLENGE, &m);
991 buffer_get_bignum2(&m, challenge);
998 mm_auth_rsa_verify_response(Key *key, BIGNUM *p, u_char response[16])
1005 debug3("%s entering", __func__);
1007 key->type = KEY_RSA; /* XXX cheat for key_to_blob */
1008 if (key_to_blob(key, &blob, &blen) == 0)
1009 fatal("%s: key_to_blob failed", __func__);
1010 key->type = KEY_RSA1;
1013 buffer_put_string(&m, blob, blen);
1014 buffer_put_string(&m, response, 16);
1017 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSARESPONSE, &m);
1018 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSARESPONSE, &m);
1020 success = buffer_get_int(&m);
1028 mm_auth_krb4(Authctxt *authctxt, void *_auth, char **client, void *_reply)
1036 debug3("%s entering", __func__);
1041 buffer_put_string(&m, auth->dat, auth->length);
1043 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KRB4, &m);
1044 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KRB4, &m);
1046 success = buffer_get_int(&m);
1048 *client = buffer_get_string(&m, NULL);
1049 p = buffer_get_string(&m, &rlen);
1050 if (rlen >= MAX_KTXT_LEN)
1051 fatal("%s: reply from monitor too large", __func__);
1052 reply->length = rlen;
1053 memcpy(reply->dat, p, rlen);
1064 mm_auth_krb5(void *ctx, void *argp, char **userp, void *resp)
1066 krb5_data *tkt, *reply;
1070 debug3("%s entering", __func__);
1071 tkt = (krb5_data *) argp;
1072 reply = (krb5_data *) resp;
1075 buffer_put_string(&m, tkt->data, tkt->length);
1077 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KRB5, &m);
1078 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KRB5, &m);
1080 success = buffer_get_int(&m);
1084 *userp = buffer_get_string(&m, NULL);
1085 reply->data = buffer_get_string(&m, &len);
1086 reply->length = len;
1088 memset(reply, 0, sizeof(*reply));