summaryrefslogtreecommitdiff
path: root/auth2-chall.c
diff options
context:
space:
mode:
Diffstat (limited to 'auth2-chall.c')
-rw-r--r--auth2-chall.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/auth2-chall.c b/auth2-chall.c
index 11c8d31b3..2d5cff448 100644
--- a/auth2-chall.c
+++ b/auth2-chall.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth2-chall.c,v 1.48 2017/05/30 14:29:59 markus Exp $ */ 1/* $OpenBSD: auth2-chall.c,v 1.50 2018/07/11 18:55:11 markus Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2001 Per Allansson. All rights reserved. 4 * Copyright (c) 2001 Per Allansson. All rights reserved.
@@ -34,12 +34,13 @@
34 34
35#include "xmalloc.h" 35#include "xmalloc.h"
36#include "ssh2.h" 36#include "ssh2.h"
37#include "key.h" 37#include "sshkey.h"
38#include "hostfile.h" 38#include "hostfile.h"
39#include "auth.h" 39#include "auth.h"
40#include "buffer.h" 40#include "sshbuf.h"
41#include "packet.h" 41#include "packet.h"
42#include "dispatch.h" 42#include "dispatch.h"
43#include "ssherr.h"
43#include "log.h" 44#include "log.h"
44#include "misc.h" 45#include "misc.h"
45#include "servconf.h" 46#include "servconf.h"
@@ -48,7 +49,7 @@
48extern ServerOptions options; 49extern ServerOptions options;
49 50
50static int auth2_challenge_start(struct ssh *); 51static int auth2_challenge_start(struct ssh *);
51static int send_userauth_info_request(Authctxt *); 52static int send_userauth_info_request(struct ssh *);
52static int input_userauth_info_response(int, u_int32_t, struct ssh *); 53static int input_userauth_info_response(int, u_int32_t, struct ssh *);
53 54
54#ifdef BSD_AUTH 55#ifdef BSD_AUTH
@@ -57,9 +58,6 @@ extern KbdintDevice bsdauth_device;
57#ifdef USE_PAM 58#ifdef USE_PAM
58extern KbdintDevice sshpam_device; 59extern KbdintDevice sshpam_device;
59#endif 60#endif
60#ifdef SKEY
61extern KbdintDevice skey_device;
62#endif
63#endif 61#endif
64 62
65KbdintDevice *devices[] = { 63KbdintDevice *devices[] = {
@@ -69,9 +67,6 @@ KbdintDevice *devices[] = {
69#ifdef USE_PAM 67#ifdef USE_PAM
70 &sshpam_device, 68 &sshpam_device,
71#endif 69#endif
72#ifdef SKEY
73 &skey_device,
74#endif
75#endif 70#endif
76 NULL 71 NULL
77}; 72};
@@ -105,8 +100,8 @@ static KbdintAuthctxt *
105kbdint_alloc(const char *devs) 100kbdint_alloc(const char *devs)
106{ 101{
107 KbdintAuthctxt *kbdintctxt; 102 KbdintAuthctxt *kbdintctxt;
108 Buffer b; 103 struct sshbuf *b;
109 int i; 104 int i, r;
110 105
111#ifdef USE_PAM 106#ifdef USE_PAM
112 if (!options.use_pam) 107 if (!options.use_pam)
@@ -115,16 +110,17 @@ kbdint_alloc(const char *devs)
115 110
116 kbdintctxt = xcalloc(1, sizeof(KbdintAuthctxt)); 111 kbdintctxt = xcalloc(1, sizeof(KbdintAuthctxt));
117 if (strcmp(devs, "") == 0) { 112 if (strcmp(devs, "") == 0) {
118 buffer_init(&b); 113 if ((b = sshbuf_new()) == NULL)
114 fatal("%s: sshbuf_new failed", __func__);
119 for (i = 0; devices[i]; i++) { 115 for (i = 0; devices[i]; i++) {
120 if (buffer_len(&b) > 0) 116 if ((r = sshbuf_putf(b, "%s%s",
121 buffer_append(&b, ",", 1); 117 sshbuf_len(b) ? "," : "", devices[i]->name)) != 0)
122 buffer_append(&b, devices[i]->name, 118 fatal("%s: buffer error: %s",
123 strlen(devices[i]->name)); 119 __func__, ssh_err(r));
124 } 120 }
125 if ((kbdintctxt->devices = sshbuf_dup_string(&b)) == NULL) 121 if ((kbdintctxt->devices = sshbuf_dup_string(b)) == NULL)
126 fatal("%s: sshbuf_dup_string failed", __func__); 122 fatal("%s: sshbuf_dup_string failed", __func__);
127 buffer_free(&b); 123 sshbuf_free(b);
128 } else { 124 } else {
129 kbdintctxt->devices = xstrdup(devs); 125 kbdintctxt->devices = xstrdup(devs);
130 } 126 }
@@ -243,7 +239,7 @@ auth2_challenge_start(struct ssh *ssh)
243 auth2_challenge_stop(ssh); 239 auth2_challenge_stop(ssh);
244 return 0; 240 return 0;
245 } 241 }
246 if (send_userauth_info_request(authctxt) == 0) { 242 if (send_userauth_info_request(ssh) == 0) {
247 auth2_challenge_stop(ssh); 243 auth2_challenge_stop(ssh);
248 return 0; 244 return 0;
249 } 245 }
@@ -255,28 +251,32 @@ auth2_challenge_start(struct ssh *ssh)
255} 251}
256 252
257static int 253static int
258send_userauth_info_request(Authctxt *authctxt) 254send_userauth_info_request(struct ssh *ssh)
259{ 255{
256 Authctxt *authctxt = ssh->authctxt;
260 KbdintAuthctxt *kbdintctxt; 257 KbdintAuthctxt *kbdintctxt;
261 char *name, *instr, **prompts; 258 char *name, *instr, **prompts;
262 u_int i, *echo_on; 259 u_int r, i, *echo_on;
263 260
264 kbdintctxt = authctxt->kbdintctxt; 261 kbdintctxt = authctxt->kbdintctxt;
265 if (kbdintctxt->device->query(kbdintctxt->ctxt, 262 if (kbdintctxt->device->query(kbdintctxt->ctxt,
266 &name, &instr, &kbdintctxt->nreq, &prompts, &echo_on)) 263 &name, &instr, &kbdintctxt->nreq, &prompts, &echo_on))
267 return 0; 264 return 0;
268 265
269 packet_start(SSH2_MSG_USERAUTH_INFO_REQUEST); 266 if ((r = sshpkt_start(ssh, SSH2_MSG_USERAUTH_INFO_REQUEST)) != 0 ||
270 packet_put_cstring(name); 267 (r = sshpkt_put_cstring(ssh, name)) != 0 ||
271 packet_put_cstring(instr); 268 (r = sshpkt_put_cstring(ssh, instr)) != 0 ||
272 packet_put_cstring(""); /* language not used */ 269 (r = sshpkt_put_cstring(ssh, "")) != 0 || /* language not used */
273 packet_put_int(kbdintctxt->nreq); 270 (r = sshpkt_put_u32(ssh, kbdintctxt->nreq)) != 0)
271 fatal("%s: %s", __func__, ssh_err(r));
274 for (i = 0; i < kbdintctxt->nreq; i++) { 272 for (i = 0; i < kbdintctxt->nreq; i++) {
275 packet_put_cstring(prompts[i]); 273 if ((r = sshpkt_put_cstring(ssh, prompts[i])) != 0 ||
276 packet_put_char(echo_on[i]); 274 (r = sshpkt_put_u8(ssh, echo_on[i])) != 0)
275 fatal("%s: %s", __func__, ssh_err(r));
277 } 276 }
278 packet_send(); 277 if ((r = sshpkt_send(ssh)) != 0 ||
279 packet_write_wait(); 278 (r = ssh_packet_write_wait(ssh)) != 0)
279 fatal("%s: %s", __func__, ssh_err(r));
280 280
281 for (i = 0; i < kbdintctxt->nreq; i++) 281 for (i = 0; i < kbdintctxt->nreq; i++)
282 free(prompts[i]); 282 free(prompts[i]);
@@ -293,6 +293,7 @@ input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
293 Authctxt *authctxt = ssh->authctxt; 293 Authctxt *authctxt = ssh->authctxt;
294 KbdintAuthctxt *kbdintctxt; 294 KbdintAuthctxt *kbdintctxt;
295 int authenticated = 0, res; 295 int authenticated = 0, res;
296 int r;
296 u_int i, nresp; 297 u_int i, nresp;
297 const char *devicename = NULL; 298 const char *devicename = NULL;
298 char **response = NULL; 299 char **response = NULL;
@@ -306,7 +307,8 @@ input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
306 fatal("input_userauth_info_response: no device"); 307 fatal("input_userauth_info_response: no device");
307 308
308 authctxt->postponed = 0; /* reset */ 309 authctxt->postponed = 0; /* reset */
309 nresp = packet_get_int(); 310 if ((r = sshpkt_get_u32(ssh, &nresp)) != 0)
311 fatal("%s: %s", __func__, ssh_err(r));
310 if (nresp != kbdintctxt->nreq) 312 if (nresp != kbdintctxt->nreq)
311 fatal("input_userauth_info_response: wrong number of replies"); 313 fatal("input_userauth_info_response: wrong number of replies");
312 if (nresp > 100) 314 if (nresp > 100)
@@ -314,9 +316,12 @@ input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
314 if (nresp > 0) { 316 if (nresp > 0) {
315 response = xcalloc(nresp, sizeof(char *)); 317 response = xcalloc(nresp, sizeof(char *));
316 for (i = 0; i < nresp; i++) 318 for (i = 0; i < nresp; i++)
317 response[i] = packet_get_string(NULL); 319 if ((r = sshpkt_get_cstring(ssh, &response[i],
320 NULL)) != 0)
321 fatal("%s: %s", __func__, ssh_err(r));
318 } 322 }
319 packet_check_eom(); 323 if ((r = sshpkt_get_end(ssh)) != 0)
324 fatal("%s: %s", __func__, ssh_err(r));
320 325
321 res = kbdintctxt->device->respond(kbdintctxt->ctxt, nresp, response); 326 res = kbdintctxt->device->respond(kbdintctxt->ctxt, nresp, response);
322 327
@@ -333,7 +338,7 @@ input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
333 break; 338 break;
334 case 1: 339 case 1:
335 /* Authentication needs further interaction */ 340 /* Authentication needs further interaction */
336 if (send_userauth_info_request(authctxt) == 1) 341 if (send_userauth_info_request(ssh) == 1)
337 authctxt->postponed = 1; 342 authctxt->postponed = 1;
338 break; 343 break;
339 default: 344 default:
@@ -358,7 +363,7 @@ input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
358void 363void
359privsep_challenge_enable(void) 364privsep_challenge_enable(void)
360{ 365{
361#if defined(BSD_AUTH) || defined(USE_PAM) || defined(SKEY) 366#if defined(BSD_AUTH) || defined(USE_PAM)
362 int n = 0; 367 int n = 0;
363#endif 368#endif
364#ifdef BSD_AUTH 369#ifdef BSD_AUTH
@@ -367,9 +372,6 @@ privsep_challenge_enable(void)
367#ifdef USE_PAM 372#ifdef USE_PAM
368 extern KbdintDevice mm_sshpam_device; 373 extern KbdintDevice mm_sshpam_device;
369#endif 374#endif
370#ifdef SKEY
371 extern KbdintDevice mm_skey_device;
372#endif
373 375
374#ifdef BSD_AUTH 376#ifdef BSD_AUTH
375 devices[n++] = &mm_bsdauth_device; 377 devices[n++] = &mm_bsdauth_device;
@@ -377,8 +379,5 @@ privsep_challenge_enable(void)
377#ifdef USE_PAM 379#ifdef USE_PAM
378 devices[n++] = &mm_sshpam_device; 380 devices[n++] = &mm_sshpam_device;
379#endif 381#endif
380#ifdef SKEY
381 devices[n++] = &mm_skey_device;
382#endif
383#endif 382#endif
384} 383}