Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame^] | 1 | /* $OpenBSD: auth2-chall.c,v 1.30 2006/08/03 03:34:41 deraadt Exp $ */ |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 2 | /* |
Ben Lindstrom | 92a2e38 | 2001-03-05 06:59:27 +0000 | [diff] [blame] | 3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 4 | * Copyright (c) 2001 Per Allansson. All rights reserved. |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 5 | * |
| 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 Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame^] | 26 | |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 27 | #include "includes.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 28 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame^] | 29 | #include <sys/types.h> |
| 30 | |
Damien Miller | a7a73ee | 2006-08-05 11:37:59 +1000 | [diff] [blame] | 31 | #include <stdio.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 32 | #include <string.h> |
| 33 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame^] | 34 | #include "xmalloc.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 35 | #include "ssh2.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame^] | 36 | #include "key.h" |
| 37 | #include "hostfile.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 38 | #include "auth.h" |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 39 | #include "buffer.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 40 | #include "packet.h" |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 41 | #include "dispatch.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 42 | #include "log.h" |
Darren Tucker | 3c66080 | 2005-01-20 22:20:50 +1100 | [diff] [blame] | 43 | #include "servconf.h" |
| 44 | |
| 45 | /* import */ |
| 46 | extern ServerOptions options; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 47 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 48 | static int auth2_challenge_start(Authctxt *); |
| 49 | static int send_userauth_info_request(Authctxt *); |
Damien Miller | 630d6f4 | 2002-01-22 23:17:30 +1100 | [diff] [blame] | 50 | static void input_userauth_info_response(int, u_int32_t, void *); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 51 | |
| 52 | #ifdef BSD_AUTH |
| 53 | extern KbdintDevice bsdauth_device; |
| 54 | #else |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 55 | #ifdef USE_PAM |
| 56 | extern KbdintDevice sshpam_device; |
| 57 | #endif |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 58 | #ifdef SKEY |
| 59 | extern KbdintDevice skey_device; |
| 60 | #endif |
| 61 | #endif |
| 62 | |
| 63 | KbdintDevice *devices[] = { |
| 64 | #ifdef BSD_AUTH |
| 65 | &bsdauth_device, |
| 66 | #else |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 67 | #ifdef USE_PAM |
| 68 | &sshpam_device, |
| 69 | #endif |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 70 | #ifdef SKEY |
| 71 | &skey_device, |
| 72 | #endif |
| 73 | #endif |
| 74 | NULL |
| 75 | }; |
| 76 | |
| 77 | typedef struct KbdintAuthctxt KbdintAuthctxt; |
| 78 | struct KbdintAuthctxt |
| 79 | { |
| 80 | char *devices; |
| 81 | void *ctxt; |
| 82 | KbdintDevice *device; |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 83 | u_int nreq; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Darren Tucker | 3c66080 | 2005-01-20 22:20:50 +1100 | [diff] [blame] | 86 | #ifdef USE_PAM |
| 87 | void |
| 88 | remove_kbdint_device(const char *devname) |
| 89 | { |
| 90 | int i, j; |
| 91 | |
| 92 | for (i = 0; devices[i] != NULL; i++) |
| 93 | if (strcmp(devices[i]->name, devname) == 0) { |
| 94 | for (j = i; devices[j] != NULL; j++) |
| 95 | devices[j] = devices[j+1]; |
| 96 | i--; |
| 97 | } |
| 98 | } |
| 99 | #endif |
| 100 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 101 | static KbdintAuthctxt * |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 102 | kbdint_alloc(const char *devs) |
| 103 | { |
| 104 | KbdintAuthctxt *kbdintctxt; |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 105 | Buffer b; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 106 | int i; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 107 | |
Darren Tucker | 3c66080 | 2005-01-20 22:20:50 +1100 | [diff] [blame] | 108 | #ifdef USE_PAM |
| 109 | if (!options.use_pam) |
| 110 | remove_kbdint_device("pam"); |
| 111 | #endif |
| 112 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 113 | kbdintctxt = xmalloc(sizeof(KbdintAuthctxt)); |
| 114 | if (strcmp(devs, "") == 0) { |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 115 | buffer_init(&b); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 116 | for (i = 0; devices[i]; i++) { |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 117 | if (buffer_len(&b) > 0) |
| 118 | buffer_append(&b, ",", 1); |
| 119 | buffer_append(&b, devices[i]->name, |
| 120 | strlen(devices[i]->name)); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 121 | } |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 122 | buffer_append(&b, "\0", 1); |
| 123 | kbdintctxt->devices = xstrdup(buffer_ptr(&b)); |
| 124 | buffer_free(&b); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 125 | } else { |
| 126 | kbdintctxt->devices = xstrdup(devs); |
| 127 | } |
Damien Miller | 0e3b872 | 2002-01-22 23:26:38 +1100 | [diff] [blame] | 128 | debug("kbdint_alloc: devices '%s'", kbdintctxt->devices); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 129 | kbdintctxt->ctxt = NULL; |
| 130 | kbdintctxt->device = NULL; |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 131 | kbdintctxt->nreq = 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 132 | |
| 133 | return kbdintctxt; |
| 134 | } |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 135 | static void |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 136 | kbdint_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 Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 144 | static void |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 145 | kbdint_free(KbdintAuthctxt *kbdintctxt) |
| 146 | { |
| 147 | if (kbdintctxt->device) |
| 148 | kbdint_reset_device(kbdintctxt); |
| 149 | if (kbdintctxt->devices) { |
| 150 | xfree(kbdintctxt->devices); |
| 151 | kbdintctxt->devices = NULL; |
| 152 | } |
| 153 | xfree(kbdintctxt); |
| 154 | } |
| 155 | /* get next device */ |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 156 | static int |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 157 | kbdint_next_device(KbdintAuthctxt *kbdintctxt) |
| 158 | { |
| 159 | size_t len; |
| 160 | char *t; |
| 161 | int i; |
| 162 | |
| 163 | if (kbdintctxt->device) |
| 164 | kbdint_reset_device(kbdintctxt); |
| 165 | do { |
| 166 | len = kbdintctxt->devices ? |
| 167 | strcspn(kbdintctxt->devices, ",") : 0; |
| 168 | |
| 169 | if (len == 0) |
| 170 | break; |
| 171 | for (i = 0; devices[i]; i++) |
| 172 | if (strncmp(kbdintctxt->devices, devices[i]->name, len) == 0) |
| 173 | kbdintctxt->device = devices[i]; |
| 174 | t = kbdintctxt->devices; |
| 175 | kbdintctxt->devices = t[len] ? xstrdup(t+len+1) : NULL; |
| 176 | xfree(t); |
| 177 | debug2("kbdint_next_device: devices %s", kbdintctxt->devices ? |
Damien Miller | 0dc1bef | 2005-07-17 17:22:45 +1000 | [diff] [blame] | 178 | kbdintctxt->devices : "<empty>"); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 179 | } while (kbdintctxt->devices && !kbdintctxt->device); |
| 180 | |
| 181 | return kbdintctxt->device ? 1 : 0; |
| 182 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 183 | |
| 184 | /* |
Ben Lindstrom | bdfb4df | 2001-10-03 17:12:43 +0000 | [diff] [blame] | 185 | * try challenge-response, set authctxt->postponed if we have to |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 186 | * wait for the response. |
| 187 | */ |
| 188 | int |
| 189 | auth2_challenge(Authctxt *authctxt, char *devs) |
| 190 | { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 191 | debug("auth2_challenge: user=%s devs=%s", |
| 192 | authctxt->user ? authctxt->user : "<nouser>", |
| 193 | devs ? devs : "<no devs>"); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 194 | |
Ben Lindstrom | 742e89e | 2001-06-09 01:17:23 +0000 | [diff] [blame] | 195 | if (authctxt->user == NULL || !devs) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 196 | return 0; |
Damien Miller | 9f0f5c6 | 2001-12-21 14:45:46 +1100 | [diff] [blame] | 197 | if (authctxt->kbdintctxt == NULL) |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 198 | authctxt->kbdintctxt = kbdint_alloc(devs); |
| 199 | return auth2_challenge_start(authctxt); |
| 200 | } |
| 201 | |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 202 | /* unregister kbd-int callbacks and context */ |
| 203 | void |
| 204 | auth2_challenge_stop(Authctxt *authctxt) |
| 205 | { |
| 206 | /* unregister callback */ |
| 207 | dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL); |
| 208 | if (authctxt->kbdintctxt != NULL) { |
| 209 | kbdint_free(authctxt->kbdintctxt); |
| 210 | authctxt->kbdintctxt = NULL; |
| 211 | } |
| 212 | } |
| 213 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 214 | /* side effect: sets authctxt->postponed if a reply was sent*/ |
| 215 | static int |
| 216 | auth2_challenge_start(Authctxt *authctxt) |
| 217 | { |
| 218 | KbdintAuthctxt *kbdintctxt = authctxt->kbdintctxt; |
| 219 | |
| 220 | debug2("auth2_challenge_start: devices %s", |
| 221 | kbdintctxt->devices ? kbdintctxt->devices : "<empty>"); |
| 222 | |
| 223 | if (kbdint_next_device(kbdintctxt) == 0) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 224 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 225 | return 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 226 | } |
| 227 | debug("auth2_challenge_start: trying authentication method '%s'", |
| 228 | kbdintctxt->device->name); |
| 229 | |
| 230 | if ((kbdintctxt->ctxt = kbdintctxt->device->init_ctx(authctxt)) == NULL) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 231 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | if (send_userauth_info_request(authctxt) == 0) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 235 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 236 | return 0; |
| 237 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 238 | dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, |
| 239 | &input_userauth_info_response); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 240 | |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 241 | authctxt->postponed = 1; |
| 242 | return 0; |
| 243 | } |
| 244 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 245 | static int |
| 246 | send_userauth_info_request(Authctxt *authctxt) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 247 | { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 248 | KbdintAuthctxt *kbdintctxt; |
| 249 | char *name, *instr, **prompts; |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 250 | u_int i, *echo_on; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 251 | |
| 252 | kbdintctxt = authctxt->kbdintctxt; |
| 253 | if (kbdintctxt->device->query(kbdintctxt->ctxt, |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 254 | &name, &instr, &kbdintctxt->nreq, &prompts, &echo_on)) |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 255 | return 0; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 256 | |
| 257 | packet_start(SSH2_MSG_USERAUTH_INFO_REQUEST); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 258 | packet_put_cstring(name); |
| 259 | packet_put_cstring(instr); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 260 | packet_put_cstring(""); /* language not used */ |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 261 | packet_put_int(kbdintctxt->nreq); |
| 262 | for (i = 0; i < kbdintctxt->nreq; i++) { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 263 | packet_put_cstring(prompts[i]); |
| 264 | packet_put_char(echo_on[i]); |
| 265 | } |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 266 | packet_send(); |
| 267 | packet_write_wait(); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 268 | |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 269 | for (i = 0; i < kbdintctxt->nreq; i++) |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 270 | xfree(prompts[i]); |
| 271 | xfree(prompts); |
| 272 | xfree(echo_on); |
| 273 | xfree(name); |
| 274 | xfree(instr); |
| 275 | return 1; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 278 | static void |
Damien Miller | 630d6f4 | 2002-01-22 23:17:30 +1100 | [diff] [blame] | 279 | input_userauth_info_response(int type, u_int32_t seq, void *ctxt) |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 280 | { |
| 281 | Authctxt *authctxt = ctxt; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 282 | KbdintAuthctxt *kbdintctxt; |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 283 | int authenticated = 0, res, len; |
| 284 | u_int i, nresp; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 285 | char **response = NULL, *method; |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 286 | |
| 287 | if (authctxt == NULL) |
| 288 | fatal("input_userauth_info_response: no authctxt"); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 289 | kbdintctxt = authctxt->kbdintctxt; |
| 290 | if (kbdintctxt == NULL || kbdintctxt->ctxt == NULL) |
| 291 | fatal("input_userauth_info_response: no kbdintctxt"); |
| 292 | if (kbdintctxt->device == NULL) |
| 293 | fatal("input_userauth_info_response: no device"); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 294 | |
| 295 | authctxt->postponed = 0; /* reset */ |
| 296 | nresp = packet_get_int(); |
Damien Miller | fb7fd95 | 2002-06-26 23:58:39 +1000 | [diff] [blame] | 297 | if (nresp != kbdintctxt->nreq) |
| 298 | fatal("input_userauth_info_response: wrong number of replies"); |
| 299 | if (nresp > 100) |
| 300 | fatal("input_userauth_info_response: too many replies"); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 301 | if (nresp > 0) { |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 302 | response = xcalloc(nresp, sizeof(char *)); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 303 | for (i = 0; i < nresp; i++) |
| 304 | response[i] = packet_get_string(NULL); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 305 | } |
Damien Miller | 48b03fc | 2002-01-22 23:11:40 +1100 | [diff] [blame] | 306 | packet_check_eom(); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 307 | |
Darren Tucker | 611649e | 2005-01-20 11:05:34 +1100 | [diff] [blame] | 308 | res = kbdintctxt->device->respond(kbdintctxt->ctxt, nresp, response); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 309 | |
| 310 | for (i = 0; i < nresp; i++) { |
| 311 | memset(response[i], 'r', strlen(response[i])); |
| 312 | xfree(response[i]); |
| 313 | } |
| 314 | if (response) |
| 315 | xfree(response); |
| 316 | |
| 317 | switch (res) { |
| 318 | case 0: |
| 319 | /* Success! */ |
Darren Tucker | 611649e | 2005-01-20 11:05:34 +1100 | [diff] [blame] | 320 | authenticated = authctxt->valid ? 1 : 0; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 321 | break; |
| 322 | case 1: |
| 323 | /* Authentication needs further interaction */ |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 324 | if (send_userauth_info_request(authctxt) == 1) |
| 325 | authctxt->postponed = 1; |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 326 | break; |
| 327 | default: |
| 328 | /* Failure! */ |
| 329 | break; |
| 330 | } |
| 331 | |
| 332 | len = strlen("keyboard-interactive") + 2 + |
| 333 | strlen(kbdintctxt->device->name); |
| 334 | method = xmalloc(len); |
Damien Miller | 209ee4e | 2002-01-22 23:25:08 +1100 | [diff] [blame] | 335 | snprintf(method, len, "keyboard-interactive/%s", |
| 336 | kbdintctxt->device->name); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 337 | |
| 338 | if (!authctxt->postponed) { |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 339 | if (authenticated) { |
Damien Miller | ee11625 | 2001-12-21 12:42:34 +1100 | [diff] [blame] | 340 | auth2_challenge_stop(authctxt); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 341 | } else { |
| 342 | /* start next device */ |
| 343 | /* may set authctxt->postponed */ |
| 344 | auth2_challenge_start(authctxt); |
| 345 | } |
| 346 | } |
Damien Miller | 5d57e50 | 2001-03-30 10:48:31 +1000 | [diff] [blame] | 347 | userauth_finish(authctxt, authenticated, method); |
Ben Lindstrom | 551ea37 | 2001-06-05 18:56:16 +0000 | [diff] [blame] | 348 | xfree(method); |
Ben Lindstrom | db65e8f | 2001-01-19 04:26:52 +0000 | [diff] [blame] | 349 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 350 | |
| 351 | void |
| 352 | privsep_challenge_enable(void) |
| 353 | { |
Damien Miller | a6a7c19 | 2003-05-26 21:36:13 +1000 | [diff] [blame] | 354 | #if defined(BSD_AUTH) || defined(USE_PAM) || defined(SKEY) |
| 355 | int n = 0; |
| 356 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 357 | #ifdef BSD_AUTH |
| 358 | extern KbdintDevice mm_bsdauth_device; |
| 359 | #endif |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 360 | #ifdef USE_PAM |
| 361 | extern KbdintDevice mm_sshpam_device; |
| 362 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 363 | #ifdef SKEY |
| 364 | extern KbdintDevice mm_skey_device; |
| 365 | #endif |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 366 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 367 | #ifdef BSD_AUTH |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 368 | devices[n++] = &mm_bsdauth_device; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 369 | #else |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 370 | #ifdef USE_PAM |
| 371 | devices[n++] = &mm_sshpam_device; |
| 372 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 373 | #ifdef SKEY |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 374 | devices[n++] = &mm_skey_device; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 375 | #endif |
| 376 | #endif |
| 377 | } |