blob: c57387b71423ee864a869b8211e7a64e54096530 [file] [log] [blame]
deraadt@openbsd.org72687c82019-11-13 04:47:52 +00001/* $OpenBSD: auth2-chall.c,v 1.52 2019/11/13 04:47:52 deraadt Exp $ */
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00002/*
Ben Lindstrom92a2e382001-03-05 06:59:27 +00003 * Copyright (c) 2001 Markus Friedl. All rights reserved.
Ben Lindstrom551ea372001-06-05 18:56:16 +00004 * Copyright (c) 2001 Per Allansson. All rights reserved.
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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.
25 */
Damien Millerd7834352006-08-05 12:39:39 +100026
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000027#include "includes.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000028
Damien Millerd7834352006-08-05 12:39:39 +100029#include <sys/types.h>
30
djm@openbsd.orgbe02d7c2019-09-06 04:53:27 +000031#include <stdlib.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100032#include <stdio.h>
Damien Millere3476ed2006-07-24 14:13:33 +100033#include <string.h>
deraadt@openbsd.org72687c82019-11-13 04:47:52 +000034#include <stdarg.h>
Damien Millere3476ed2006-07-24 14:13:33 +100035
Damien Millerd7834352006-08-05 12:39:39 +100036#include "xmalloc.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000037#include "ssh2.h"
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000038#include "sshkey.h"
Damien Millerd7834352006-08-05 12:39:39 +100039#include "hostfile.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000040#include "auth.h"
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000041#include "sshbuf.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000042#include "packet.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000043#include "dispatch.h"
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000044#include "ssherr.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000045#include "log.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100046#include "misc.h"
Darren Tucker3c660802005-01-20 22:20:50 +110047#include "servconf.h"
48
49/* import */
50extern ServerOptions options;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000051
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +000052static int auth2_challenge_start(struct ssh *);
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000053static int send_userauth_info_request(struct ssh *);
markus@openbsd.org2ae666a2017-05-30 14:23:52 +000054static int input_userauth_info_response(int, u_int32_t, struct ssh *);
Ben Lindstrom551ea372001-06-05 18:56:16 +000055
56#ifdef BSD_AUTH
57extern KbdintDevice bsdauth_device;
58#else
Damien Miller4f9f42a2003-05-10 19:28:02 +100059#ifdef USE_PAM
60extern KbdintDevice sshpam_device;
61#endif
Ben Lindstrom551ea372001-06-05 18:56:16 +000062#endif
63
64KbdintDevice *devices[] = {
65#ifdef BSD_AUTH
66 &bsdauth_device,
67#else
Damien Miller4f9f42a2003-05-10 19:28:02 +100068#ifdef USE_PAM
69 &sshpam_device,
70#endif
Ben Lindstrom551ea372001-06-05 18:56:16 +000071#endif
72 NULL
73};
74
75typedef struct KbdintAuthctxt KbdintAuthctxt;
76struct KbdintAuthctxt
77{
78 char *devices;
79 void *ctxt;
80 KbdintDevice *device;
Damien Millerfb7fd952002-06-26 23:58:39 +100081 u_int nreq;
djm@openbsd.org5b64f852015-07-18 07:57:14 +000082 u_int devices_done;
Ben Lindstrom551ea372001-06-05 18:56:16 +000083};
84
Darren Tucker3c660802005-01-20 22:20:50 +110085#ifdef USE_PAM
86void
87remove_kbdint_device(const char *devname)
88{
89 int i, j;
90
91 for (i = 0; devices[i] != NULL; i++)
92 if (strcmp(devices[i]->name, devname) == 0) {
93 for (j = i; devices[j] != NULL; j++)
94 devices[j] = devices[j+1];
95 i--;
96 }
97}
98#endif
99
Ben Lindstrombba81212001-06-25 05:01:22 +0000100static KbdintAuthctxt *
Ben Lindstrom551ea372001-06-05 18:56:16 +0000101kbdint_alloc(const char *devs)
102{
103 KbdintAuthctxt *kbdintctxt;
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000104 struct sshbuf *b;
105 int i, r;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000106
Darren Tucker3c660802005-01-20 22:20:50 +1100107#ifdef USE_PAM
108 if (!options.use_pam)
109 remove_kbdint_device("pam");
110#endif
111
Damien Miller6c81fee2013-11-08 12:19:55 +1100112 kbdintctxt = xcalloc(1, sizeof(KbdintAuthctxt));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000113 if (strcmp(devs, "") == 0) {
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000114 if ((b = sshbuf_new()) == NULL)
115 fatal("%s: sshbuf_new failed", __func__);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000116 for (i = 0; devices[i]; i++) {
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000117 if ((r = sshbuf_putf(b, "%s%s",
118 sshbuf_len(b) ? "," : "", devices[i]->name)) != 0)
119 fatal("%s: buffer error: %s",
120 __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000121 }
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000122 if ((kbdintctxt->devices = sshbuf_dup_string(b)) == NULL)
djm@openbsd.org1a31d022016-05-02 08:49:03 +0000123 fatal("%s: sshbuf_dup_string failed", __func__);
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000124 sshbuf_free(b);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000125 } else {
126 kbdintctxt->devices = xstrdup(devs);
127 }
Damien Miller0e3b8722002-01-22 23:26:38 +1100128 debug("kbdint_alloc: devices '%s'", kbdintctxt->devices);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000129 kbdintctxt->ctxt = NULL;
130 kbdintctxt->device = NULL;
Damien Millerfb7fd952002-06-26 23:58:39 +1000131 kbdintctxt->nreq = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000132
133 return kbdintctxt;
134}
Ben Lindstrombba81212001-06-25 05:01:22 +0000135static void
Ben Lindstrom551ea372001-06-05 18:56:16 +0000136kbdint_reset_device(KbdintAuthctxt *kbdintctxt)
137{
138 if (kbdintctxt->ctxt) {
139 kbdintctxt->device->free_ctx(kbdintctxt->ctxt);
140 kbdintctxt->ctxt = NULL;
141 }
142 kbdintctxt->device = NULL;
143}
Ben Lindstrombba81212001-06-25 05:01:22 +0000144static void
Ben Lindstrom551ea372001-06-05 18:56:16 +0000145kbdint_free(KbdintAuthctxt *kbdintctxt)
146{
147 if (kbdintctxt->device)
148 kbdint_reset_device(kbdintctxt);
Darren Tuckera627d422013-06-02 07:31:17 +1000149 free(kbdintctxt->devices);
Damien Miller1d2c4562014-02-04 11:18:20 +1100150 explicit_bzero(kbdintctxt, sizeof(*kbdintctxt));
Darren Tuckera627d422013-06-02 07:31:17 +1000151 free(kbdintctxt);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000152}
153/* get next device */
Ben Lindstrombba81212001-06-25 05:01:22 +0000154static int
Damien Miller91a55f22013-04-23 15:18:10 +1000155kbdint_next_device(Authctxt *authctxt, KbdintAuthctxt *kbdintctxt)
Ben Lindstrom551ea372001-06-05 18:56:16 +0000156{
157 size_t len;
158 char *t;
159 int i;
160
161 if (kbdintctxt->device)
162 kbdint_reset_device(kbdintctxt);
163 do {
164 len = kbdintctxt->devices ?
165 strcspn(kbdintctxt->devices, ",") : 0;
166
167 if (len == 0)
168 break;
Damien Miller91a55f22013-04-23 15:18:10 +1000169 for (i = 0; devices[i]; i++) {
djm@openbsd.org5b64f852015-07-18 07:57:14 +0000170 if ((kbdintctxt->devices_done & (1 << i)) != 0 ||
171 !auth2_method_allowed(authctxt,
Damien Miller91a55f22013-04-23 15:18:10 +1000172 "keyboard-interactive", devices[i]->name))
173 continue;
djm@openbsd.org5b64f852015-07-18 07:57:14 +0000174 if (strncmp(kbdintctxt->devices, devices[i]->name,
175 len) == 0) {
Ben Lindstrom551ea372001-06-05 18:56:16 +0000176 kbdintctxt->device = devices[i];
djm@openbsd.org5b64f852015-07-18 07:57:14 +0000177 kbdintctxt->devices_done |= 1 << i;
178 }
Damien Miller91a55f22013-04-23 15:18:10 +1000179 }
Ben Lindstrom551ea372001-06-05 18:56:16 +0000180 t = kbdintctxt->devices;
181 kbdintctxt->devices = t[len] ? xstrdup(t+len+1) : NULL;
Darren Tuckera627d422013-06-02 07:31:17 +1000182 free(t);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000183 debug2("kbdint_next_device: devices %s", kbdintctxt->devices ?
Damien Miller0dc1bef2005-07-17 17:22:45 +1000184 kbdintctxt->devices : "<empty>");
Ben Lindstrom551ea372001-06-05 18:56:16 +0000185 } while (kbdintctxt->devices && !kbdintctxt->device);
186
187 return kbdintctxt->device ? 1 : 0;
188}
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000189
190/*
Ben Lindstrombdfb4df2001-10-03 17:12:43 +0000191 * try challenge-response, set authctxt->postponed if we have to
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000192 * wait for the response.
193 */
194int
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000195auth2_challenge(struct ssh *ssh, char *devs)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000196{
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000197 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000198 debug("auth2_challenge: user=%s devs=%s",
199 authctxt->user ? authctxt->user : "<nouser>",
200 devs ? devs : "<no devs>");
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000201
Ben Lindstrom742e89e2001-06-09 01:17:23 +0000202 if (authctxt->user == NULL || !devs)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000203 return 0;
Damien Miller9f0f5c62001-12-21 14:45:46 +1100204 if (authctxt->kbdintctxt == NULL)
Ben Lindstrom551ea372001-06-05 18:56:16 +0000205 authctxt->kbdintctxt = kbdint_alloc(devs);
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000206 return auth2_challenge_start(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000207}
208
Damien Milleree116252001-12-21 12:42:34 +1100209/* unregister kbd-int callbacks and context */
210void
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000211auth2_challenge_stop(struct ssh *ssh)
Damien Milleree116252001-12-21 12:42:34 +1100212{
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000213 Authctxt *authctxt = ssh->authctxt;
Damien Milleree116252001-12-21 12:42:34 +1100214 /* unregister callback */
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000215 ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL);
Damien Miller80163902007-01-05 16:30:16 +1100216 if (authctxt->kbdintctxt != NULL) {
Damien Milleree116252001-12-21 12:42:34 +1100217 kbdint_free(authctxt->kbdintctxt);
218 authctxt->kbdintctxt = NULL;
219 }
220}
221
Ben Lindstrom551ea372001-06-05 18:56:16 +0000222/* side effect: sets authctxt->postponed if a reply was sent*/
223static int
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000224auth2_challenge_start(struct ssh *ssh)
Ben Lindstrom551ea372001-06-05 18:56:16 +0000225{
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000226 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000227 KbdintAuthctxt *kbdintctxt = authctxt->kbdintctxt;
228
229 debug2("auth2_challenge_start: devices %s",
230 kbdintctxt->devices ? kbdintctxt->devices : "<empty>");
231
Damien Miller91a55f22013-04-23 15:18:10 +1000232 if (kbdint_next_device(authctxt, kbdintctxt) == 0) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000233 auth2_challenge_stop(ssh);
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000234 return 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000235 }
236 debug("auth2_challenge_start: trying authentication method '%s'",
237 kbdintctxt->device->name);
238
239 if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000240 auth2_challenge_stop(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000241 return 0;
242 }
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000243 if (send_userauth_info_request(ssh) == 0) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000244 auth2_challenge_stop(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000245 return 0;
246 }
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000247 ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_INFO_RESPONSE,
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000248 &input_userauth_info_response);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000249
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000250 authctxt->postponed = 1;
251 return 0;
252}
253
Ben Lindstrom551ea372001-06-05 18:56:16 +0000254static int
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000255send_userauth_info_request(struct ssh *ssh)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000256{
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000257 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000258 KbdintAuthctxt *kbdintctxt;
259 char *name, *instr, **prompts;
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000260 u_int r, i, *echo_on;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000261
262 kbdintctxt = authctxt->kbdintctxt;
263 if (kbdintctxt->device->query(kbdintctxt->ctxt,
Damien Millerfb7fd952002-06-26 23:58:39 +1000264 &name, &instr, &kbdintctxt->nreq, &prompts, &echo_on))
Ben Lindstrom551ea372001-06-05 18:56:16 +0000265 return 0;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000266
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000267 if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_INFO_REQUEST)) != 0 ||
268 (r = sshpkt_put_cstring(ssh, name)) != 0 ||
269 (r = sshpkt_put_cstring(ssh, instr)) != 0 ||
270 (r = sshpkt_put_cstring(ssh, "")) != 0 || /* language not used */
271 (r = sshpkt_put_u32(ssh, kbdintctxt->nreq)) != 0)
272 fatal("%s: %s", __func__, ssh_err(r));
Damien Millerfb7fd952002-06-26 23:58:39 +1000273 for (i = 0; i < kbdintctxt->nreq; i++) {
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000274 if ((r = sshpkt_put_cstring(ssh, prompts[i])) != 0 ||
275 (r = sshpkt_put_u8(ssh, echo_on[i])) != 0)
276 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000277 }
markus@openbsd.org394a8422018-07-11 18:55:11 +0000278 if ((r = sshpkt_send(ssh)) != 0 ||
279 (r = ssh_packet_write_wait(ssh)) != 0)
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000280 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000281
Damien Millerfb7fd952002-06-26 23:58:39 +1000282 for (i = 0; i < kbdintctxt->nreq; i++)
Darren Tuckera627d422013-06-02 07:31:17 +1000283 free(prompts[i]);
284 free(prompts);
285 free(echo_on);
286 free(name);
287 free(instr);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000288 return 1;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000289}
290
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000291static int
markus@openbsd.org2ae666a2017-05-30 14:23:52 +0000292input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000293{
markus@openbsd.org5f4082d2017-05-30 14:18:15 +0000294 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000295 KbdintAuthctxt *kbdintctxt;
Damien Millerc30def92009-01-28 16:13:39 +1100296 int authenticated = 0, res;
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000297 int r;
Damien Millereccb9de2005-06-17 12:59:34 +1000298 u_int i, nresp;
Damien Miller55aca022012-12-03 11:25:30 +1100299 const char *devicename = NULL;
300 char **response = NULL;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000301
302 if (authctxt == NULL)
303 fatal("input_userauth_info_response: no authctxt");
Ben Lindstrom551ea372001-06-05 18:56:16 +0000304 kbdintctxt = authctxt->kbdintctxt;
305 if (kbdintctxt == NULL || kbdintctxt->ctxt == NULL)
306 fatal("input_userauth_info_response: no kbdintctxt");
307 if (kbdintctxt->device == NULL)
308 fatal("input_userauth_info_response: no device");
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000309
310 authctxt->postponed = 0; /* reset */
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000311 if ((r = sshpkt_get_u32(ssh, &nresp)) != 0)
312 fatal("%s: %s", __func__, ssh_err(r));
Damien Millerfb7fd952002-06-26 23:58:39 +1000313 if (nresp != kbdintctxt->nreq)
314 fatal("input_userauth_info_response: wrong number of replies");
315 if (nresp > 100)
316 fatal("input_userauth_info_response: too many replies");
Ben Lindstrom551ea372001-06-05 18:56:16 +0000317 if (nresp > 0) {
Damien Miller07d86be2006-03-26 14:19:21 +1100318 response = xcalloc(nresp, sizeof(char *));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000319 for (i = 0; i < nresp; i++)
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000320 if ((r = sshpkt_get_cstring(ssh, &response[i],
321 NULL)) != 0)
322 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000323 }
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000324 if ((r = sshpkt_get_end(ssh)) != 0)
325 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000326
Darren Tucker611649e2005-01-20 11:05:34 +1100327 res = kbdintctxt->device->respond(kbdintctxt->ctxt, nresp, response);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000328
329 for (i = 0; i < nresp; i++) {
Damien Millera5103f42014-02-04 11:20:14 +1100330 explicit_bzero(response[i], strlen(response[i]));
Darren Tuckera627d422013-06-02 07:31:17 +1000331 free(response[i]);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000332 }
Darren Tuckera627d422013-06-02 07:31:17 +1000333 free(response);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000334
335 switch (res) {
336 case 0:
337 /* Success! */
Darren Tucker611649e2005-01-20 11:05:34 +1100338 authenticated = authctxt->valid ? 1 : 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000339 break;
340 case 1:
341 /* Authentication needs further interaction */
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000342 if (send_userauth_info_request(ssh) == 1)
Damien Milleree116252001-12-21 12:42:34 +1100343 authctxt->postponed = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000344 break;
345 default:
346 /* Failure! */
347 break;
348 }
Damien Miller15b05cf2012-12-03 09:53:20 +1100349 devicename = kbdintctxt->device->name;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000350 if (!authctxt->postponed) {
Ben Lindstrom551ea372001-06-05 18:56:16 +0000351 if (authenticated) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000352 auth2_challenge_stop(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000353 } else {
354 /* start next device */
355 /* may set authctxt->postponed */
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000356 auth2_challenge_start(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000357 }
358 }
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000359 userauth_finish(ssh, authenticated, "keyboard-interactive",
Damien Miller15b05cf2012-12-03 09:53:20 +1100360 devicename);
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000361 return 0;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000362}
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000363
364void
365privsep_challenge_enable(void)
366{
Damien Miller87f08be2018-07-20 13:18:28 +1000367#if defined(BSD_AUTH) || defined(USE_PAM)
Damien Millera6a7c192003-05-26 21:36:13 +1000368 int n = 0;
369#endif
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000370#ifdef BSD_AUTH
371 extern KbdintDevice mm_bsdauth_device;
372#endif
Damien Miller4f9f42a2003-05-10 19:28:02 +1000373#ifdef USE_PAM
374 extern KbdintDevice mm_sshpam_device;
375#endif
Damien Miller4f9f42a2003-05-10 19:28:02 +1000376
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000377#ifdef BSD_AUTH
Damien Miller4f9f42a2003-05-10 19:28:02 +1000378 devices[n++] = &mm_bsdauth_device;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000379#else
Damien Miller4f9f42a2003-05-10 19:28:02 +1000380#ifdef USE_PAM
381 devices[n++] = &mm_sshpam_device;
382#endif
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000383#endif
384}