blob: 4fd18f467068f660275ec2bd12cf6dbadbc94799 [file] [log] [blame]
markus@openbsd.org394a8422018-07-11 18:55:11 +00001/* $OpenBSD: auth2-chall.c,v 1.50 2018/07/11 18:55:11 markus 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
Damien Millerded319c2006-09-01 15:38:36 +100031#include <stdarg.h>
Damien Millera7a73ee2006-08-05 11:37:59 +100032#include <stdio.h>
Damien Millere3476ed2006-07-24 14:13:33 +100033#include <string.h>
34
Damien Millerd7834352006-08-05 12:39:39 +100035#include "xmalloc.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000036#include "ssh2.h"
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000037#include "sshkey.h"
Damien Millerd7834352006-08-05 12:39:39 +100038#include "hostfile.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000039#include "auth.h"
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000040#include "sshbuf.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000041#include "packet.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000042#include "dispatch.h"
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000043#include "ssherr.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000044#include "log.h"
Damien Miller7acefbb2014-07-18 14:11:24 +100045#include "misc.h"
Darren Tucker3c660802005-01-20 22:20:50 +110046#include "servconf.h"
47
48/* import */
49extern ServerOptions options;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000050
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +000051static int auth2_challenge_start(struct ssh *);
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +000052static int send_userauth_info_request(struct ssh *);
markus@openbsd.org2ae666a2017-05-30 14:23:52 +000053static int input_userauth_info_response(int, u_int32_t, struct ssh *);
Ben Lindstrom551ea372001-06-05 18:56:16 +000054
55#ifdef BSD_AUTH
56extern KbdintDevice bsdauth_device;
57#else
Damien Miller4f9f42a2003-05-10 19:28:02 +100058#ifdef USE_PAM
59extern KbdintDevice sshpam_device;
60#endif
Ben Lindstrom551ea372001-06-05 18:56:16 +000061#ifdef SKEY
62extern KbdintDevice skey_device;
63#endif
64#endif
65
66KbdintDevice *devices[] = {
67#ifdef BSD_AUTH
68 &bsdauth_device,
69#else
Damien Miller4f9f42a2003-05-10 19:28:02 +100070#ifdef USE_PAM
71 &sshpam_device,
72#endif
Ben Lindstrom551ea372001-06-05 18:56:16 +000073#ifdef SKEY
74 &skey_device,
75#endif
76#endif
77 NULL
78};
79
80typedef struct KbdintAuthctxt KbdintAuthctxt;
81struct KbdintAuthctxt
82{
83 char *devices;
84 void *ctxt;
85 KbdintDevice *device;
Damien Millerfb7fd952002-06-26 23:58:39 +100086 u_int nreq;
djm@openbsd.org5b64f852015-07-18 07:57:14 +000087 u_int devices_done;
Ben Lindstrom551ea372001-06-05 18:56:16 +000088};
89
Darren Tucker3c660802005-01-20 22:20:50 +110090#ifdef USE_PAM
91void
92remove_kbdint_device(const char *devname)
93{
94 int i, j;
95
96 for (i = 0; devices[i] != NULL; i++)
97 if (strcmp(devices[i]->name, devname) == 0) {
98 for (j = i; devices[j] != NULL; j++)
99 devices[j] = devices[j+1];
100 i--;
101 }
102}
103#endif
104
Ben Lindstrombba81212001-06-25 05:01:22 +0000105static KbdintAuthctxt *
Ben Lindstrom551ea372001-06-05 18:56:16 +0000106kbdint_alloc(const char *devs)
107{
108 KbdintAuthctxt *kbdintctxt;
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000109 struct sshbuf *b;
110 int i, r;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000111
Darren Tucker3c660802005-01-20 22:20:50 +1100112#ifdef USE_PAM
113 if (!options.use_pam)
114 remove_kbdint_device("pam");
115#endif
116
Damien Miller6c81fee2013-11-08 12:19:55 +1100117 kbdintctxt = xcalloc(1, sizeof(KbdintAuthctxt));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000118 if (strcmp(devs, "") == 0) {
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000119 if ((b = sshbuf_new()) == NULL)
120 fatal("%s: sshbuf_new failed", __func__);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000121 for (i = 0; devices[i]; i++) {
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000122 if ((r = sshbuf_putf(b, "%s%s",
123 sshbuf_len(b) ? "," : "", devices[i]->name)) != 0)
124 fatal("%s: buffer error: %s",
125 __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000126 }
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000127 if ((kbdintctxt->devices = sshbuf_dup_string(b)) == NULL)
djm@openbsd.org1a31d022016-05-02 08:49:03 +0000128 fatal("%s: sshbuf_dup_string failed", __func__);
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000129 sshbuf_free(b);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000130 } else {
131 kbdintctxt->devices = xstrdup(devs);
132 }
Damien Miller0e3b8722002-01-22 23:26:38 +1100133 debug("kbdint_alloc: devices '%s'", kbdintctxt->devices);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000134 kbdintctxt->ctxt = NULL;
135 kbdintctxt->device = NULL;
Damien Millerfb7fd952002-06-26 23:58:39 +1000136 kbdintctxt->nreq = 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000137
138 return kbdintctxt;
139}
Ben Lindstrombba81212001-06-25 05:01:22 +0000140static void
Ben Lindstrom551ea372001-06-05 18:56:16 +0000141kbdint_reset_device(KbdintAuthctxt *kbdintctxt)
142{
143 if (kbdintctxt->ctxt) {
144 kbdintctxt->device->free_ctx(kbdintctxt->ctxt);
145 kbdintctxt->ctxt = NULL;
146 }
147 kbdintctxt->device = NULL;
148}
Ben Lindstrombba81212001-06-25 05:01:22 +0000149static void
Ben Lindstrom551ea372001-06-05 18:56:16 +0000150kbdint_free(KbdintAuthctxt *kbdintctxt)
151{
152 if (kbdintctxt->device)
153 kbdint_reset_device(kbdintctxt);
Darren Tuckera627d422013-06-02 07:31:17 +1000154 free(kbdintctxt->devices);
Damien Miller1d2c4562014-02-04 11:18:20 +1100155 explicit_bzero(kbdintctxt, sizeof(*kbdintctxt));
Darren Tuckera627d422013-06-02 07:31:17 +1000156 free(kbdintctxt);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000157}
158/* get next device */
Ben Lindstrombba81212001-06-25 05:01:22 +0000159static int
Damien Miller91a55f22013-04-23 15:18:10 +1000160kbdint_next_device(Authctxt *authctxt, KbdintAuthctxt *kbdintctxt)
Ben Lindstrom551ea372001-06-05 18:56:16 +0000161{
162 size_t len;
163 char *t;
164 int i;
165
166 if (kbdintctxt->device)
167 kbdint_reset_device(kbdintctxt);
168 do {
169 len = kbdintctxt->devices ?
170 strcspn(kbdintctxt->devices, ",") : 0;
171
172 if (len == 0)
173 break;
Damien Miller91a55f22013-04-23 15:18:10 +1000174 for (i = 0; devices[i]; i++) {
djm@openbsd.org5b64f852015-07-18 07:57:14 +0000175 if ((kbdintctxt->devices_done & (1 << i)) != 0 ||
176 !auth2_method_allowed(authctxt,
Damien Miller91a55f22013-04-23 15:18:10 +1000177 "keyboard-interactive", devices[i]->name))
178 continue;
djm@openbsd.org5b64f852015-07-18 07:57:14 +0000179 if (strncmp(kbdintctxt->devices, devices[i]->name,
180 len) == 0) {
Ben Lindstrom551ea372001-06-05 18:56:16 +0000181 kbdintctxt->device = devices[i];
djm@openbsd.org5b64f852015-07-18 07:57:14 +0000182 kbdintctxt->devices_done |= 1 << i;
183 }
Damien Miller91a55f22013-04-23 15:18:10 +1000184 }
Ben Lindstrom551ea372001-06-05 18:56:16 +0000185 t = kbdintctxt->devices;
186 kbdintctxt->devices = t[len] ? xstrdup(t+len+1) : NULL;
Darren Tuckera627d422013-06-02 07:31:17 +1000187 free(t);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000188 debug2("kbdint_next_device: devices %s", kbdintctxt->devices ?
Damien Miller0dc1bef2005-07-17 17:22:45 +1000189 kbdintctxt->devices : "<empty>");
Ben Lindstrom551ea372001-06-05 18:56:16 +0000190 } while (kbdintctxt->devices && !kbdintctxt->device);
191
192 return kbdintctxt->device ? 1 : 0;
193}
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000194
195/*
Ben Lindstrombdfb4df2001-10-03 17:12:43 +0000196 * try challenge-response, set authctxt->postponed if we have to
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000197 * wait for the response.
198 */
199int
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000200auth2_challenge(struct ssh *ssh, char *devs)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000201{
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000202 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000203 debug("auth2_challenge: user=%s devs=%s",
204 authctxt->user ? authctxt->user : "<nouser>",
205 devs ? devs : "<no devs>");
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000206
Ben Lindstrom742e89e2001-06-09 01:17:23 +0000207 if (authctxt->user == NULL || !devs)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000208 return 0;
Damien Miller9f0f5c62001-12-21 14:45:46 +1100209 if (authctxt->kbdintctxt == NULL)
Ben Lindstrom551ea372001-06-05 18:56:16 +0000210 authctxt->kbdintctxt = kbdint_alloc(devs);
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000211 return auth2_challenge_start(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000212}
213
Damien Milleree116252001-12-21 12:42:34 +1100214/* unregister kbd-int callbacks and context */
215void
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000216auth2_challenge_stop(struct ssh *ssh)
Damien Milleree116252001-12-21 12:42:34 +1100217{
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000218 Authctxt *authctxt = ssh->authctxt;
Damien Milleree116252001-12-21 12:42:34 +1100219 /* unregister callback */
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000220 ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL);
Damien Miller80163902007-01-05 16:30:16 +1100221 if (authctxt->kbdintctxt != NULL) {
Damien Milleree116252001-12-21 12:42:34 +1100222 kbdint_free(authctxt->kbdintctxt);
223 authctxt->kbdintctxt = NULL;
224 }
225}
226
Ben Lindstrom551ea372001-06-05 18:56:16 +0000227/* side effect: sets authctxt->postponed if a reply was sent*/
228static int
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000229auth2_challenge_start(struct ssh *ssh)
Ben Lindstrom551ea372001-06-05 18:56:16 +0000230{
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000231 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000232 KbdintAuthctxt *kbdintctxt = authctxt->kbdintctxt;
233
234 debug2("auth2_challenge_start: devices %s",
235 kbdintctxt->devices ? kbdintctxt->devices : "<empty>");
236
Damien Miller91a55f22013-04-23 15:18:10 +1000237 if (kbdint_next_device(authctxt, kbdintctxt) == 0) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000238 auth2_challenge_stop(ssh);
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000239 return 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000240 }
241 debug("auth2_challenge_start: trying authentication method '%s'",
242 kbdintctxt->device->name);
243
244 if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000245 auth2_challenge_stop(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000246 return 0;
247 }
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000248 if (send_userauth_info_request(ssh) == 0) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000249 auth2_challenge_stop(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000250 return 0;
251 }
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000252 ssh_dispatch_set(ssh, SSH2_MSG_USERAUTH_INFO_RESPONSE,
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000253 &input_userauth_info_response);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000254
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000255 authctxt->postponed = 1;
256 return 0;
257}
258
Ben Lindstrom551ea372001-06-05 18:56:16 +0000259static int
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000260send_userauth_info_request(struct ssh *ssh)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000261{
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000262 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000263 KbdintAuthctxt *kbdintctxt;
264 char *name, *instr, **prompts;
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000265 u_int r, i, *echo_on;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000266
267 kbdintctxt = authctxt->kbdintctxt;
268 if (kbdintctxt->device->query(kbdintctxt->ctxt,
Damien Millerfb7fd952002-06-26 23:58:39 +1000269 &name, &instr, &kbdintctxt->nreq, &prompts, &echo_on))
Ben Lindstrom551ea372001-06-05 18:56:16 +0000270 return 0;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000271
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000272 if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_INFO_REQUEST)) != 0 ||
273 (r = sshpkt_put_cstring(ssh, name)) != 0 ||
274 (r = sshpkt_put_cstring(ssh, instr)) != 0 ||
275 (r = sshpkt_put_cstring(ssh, "")) != 0 || /* language not used */
276 (r = sshpkt_put_u32(ssh, kbdintctxt->nreq)) != 0)
277 fatal("%s: %s", __func__, ssh_err(r));
Damien Millerfb7fd952002-06-26 23:58:39 +1000278 for (i = 0; i < kbdintctxt->nreq; i++) {
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000279 if ((r = sshpkt_put_cstring(ssh, prompts[i])) != 0 ||
280 (r = sshpkt_put_u8(ssh, echo_on[i])) != 0)
281 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000282 }
markus@openbsd.org394a8422018-07-11 18:55:11 +0000283 if ((r = sshpkt_send(ssh)) != 0 ||
284 (r = ssh_packet_write_wait(ssh)) != 0)
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000285 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000286
Damien Millerfb7fd952002-06-26 23:58:39 +1000287 for (i = 0; i < kbdintctxt->nreq; i++)
Darren Tuckera627d422013-06-02 07:31:17 +1000288 free(prompts[i]);
289 free(prompts);
290 free(echo_on);
291 free(name);
292 free(instr);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000293 return 1;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000294}
295
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000296static int
markus@openbsd.org2ae666a2017-05-30 14:23:52 +0000297input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000298{
markus@openbsd.org5f4082d2017-05-30 14:18:15 +0000299 Authctxt *authctxt = ssh->authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000300 KbdintAuthctxt *kbdintctxt;
Damien Millerc30def92009-01-28 16:13:39 +1100301 int authenticated = 0, res;
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000302 int r;
Damien Millereccb9de2005-06-17 12:59:34 +1000303 u_int i, nresp;
Damien Miller55aca022012-12-03 11:25:30 +1100304 const char *devicename = NULL;
305 char **response = NULL;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000306
307 if (authctxt == NULL)
308 fatal("input_userauth_info_response: no authctxt");
Ben Lindstrom551ea372001-06-05 18:56:16 +0000309 kbdintctxt = authctxt->kbdintctxt;
310 if (kbdintctxt == NULL || kbdintctxt->ctxt == NULL)
311 fatal("input_userauth_info_response: no kbdintctxt");
312 if (kbdintctxt->device == NULL)
313 fatal("input_userauth_info_response: no device");
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000314
315 authctxt->postponed = 0; /* reset */
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000316 if ((r = sshpkt_get_u32(ssh, &nresp)) != 0)
317 fatal("%s: %s", __func__, ssh_err(r));
Damien Millerfb7fd952002-06-26 23:58:39 +1000318 if (nresp != kbdintctxt->nreq)
319 fatal("input_userauth_info_response: wrong number of replies");
320 if (nresp > 100)
321 fatal("input_userauth_info_response: too many replies");
Ben Lindstrom551ea372001-06-05 18:56:16 +0000322 if (nresp > 0) {
Damien Miller07d86be2006-03-26 14:19:21 +1100323 response = xcalloc(nresp, sizeof(char *));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000324 for (i = 0; i < nresp; i++)
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000325 if ((r = sshpkt_get_cstring(ssh, &response[i],
326 NULL)) != 0)
327 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000328 }
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000329 if ((r = sshpkt_get_end(ssh)) != 0)
330 fatal("%s: %s", __func__, ssh_err(r));
Ben Lindstrom551ea372001-06-05 18:56:16 +0000331
Darren Tucker611649e2005-01-20 11:05:34 +1100332 res = kbdintctxt->device->respond(kbdintctxt->ctxt, nresp, response);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000333
334 for (i = 0; i < nresp; i++) {
Damien Millera5103f42014-02-04 11:20:14 +1100335 explicit_bzero(response[i], strlen(response[i]));
Darren Tuckera627d422013-06-02 07:31:17 +1000336 free(response[i]);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000337 }
Darren Tuckera627d422013-06-02 07:31:17 +1000338 free(response);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000339
340 switch (res) {
341 case 0:
342 /* Success! */
Darren Tucker611649e2005-01-20 11:05:34 +1100343 authenticated = authctxt->valid ? 1 : 0;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000344 break;
345 case 1:
346 /* Authentication needs further interaction */
markus@openbsd.orgc7d39ac2018-07-09 21:35:50 +0000347 if (send_userauth_info_request(ssh) == 1)
Damien Milleree116252001-12-21 12:42:34 +1100348 authctxt->postponed = 1;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000349 break;
350 default:
351 /* Failure! */
352 break;
353 }
Damien Miller15b05cf2012-12-03 09:53:20 +1100354 devicename = kbdintctxt->device->name;
Ben Lindstrom551ea372001-06-05 18:56:16 +0000355 if (!authctxt->postponed) {
Ben Lindstrom551ea372001-06-05 18:56:16 +0000356 if (authenticated) {
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000357 auth2_challenge_stop(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000358 } else {
359 /* start next device */
360 /* may set authctxt->postponed */
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000361 auth2_challenge_start(ssh);
Ben Lindstrom551ea372001-06-05 18:56:16 +0000362 }
363 }
markus@openbsd.orgeb272ea2017-05-30 14:29:59 +0000364 userauth_finish(ssh, authenticated, "keyboard-interactive",
Damien Miller15b05cf2012-12-03 09:53:20 +1100365 devicename);
markus@openbsd.org3fdc88a2015-01-19 20:07:45 +0000366 return 0;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000367}
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000368
369void
370privsep_challenge_enable(void)
371{
Damien Millera6a7c192003-05-26 21:36:13 +1000372#if defined(BSD_AUTH) || defined(USE_PAM) || defined(SKEY)
373 int n = 0;
374#endif
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000375#ifdef BSD_AUTH
376 extern KbdintDevice mm_bsdauth_device;
377#endif
Damien Miller4f9f42a2003-05-10 19:28:02 +1000378#ifdef USE_PAM
379 extern KbdintDevice mm_sshpam_device;
380#endif
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000381#ifdef SKEY
382 extern KbdintDevice mm_skey_device;
383#endif
Damien Miller4f9f42a2003-05-10 19:28:02 +1000384
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000385#ifdef BSD_AUTH
Damien Miller4f9f42a2003-05-10 19:28:02 +1000386 devices[n++] = &mm_bsdauth_device;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000387#else
Damien Miller4f9f42a2003-05-10 19:28:02 +1000388#ifdef USE_PAM
389 devices[n++] = &mm_sshpam_device;
390#endif
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000391#ifdef SKEY
Damien Miller4f9f42a2003-05-10 19:28:02 +1000392 devices[n++] = &mm_skey_device;
Ben Lindstrom7a2073c2002-03-22 02:30:41 +0000393#endif
394#endif
395}