summaryrefslogtreecommitdiff
path: root/auth2-chall.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-01-19 04:26:52 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-01-19 04:26:52 +0000
commitdb65e8fdedadaf79df2d8393a4d43e9094c80649 (patch)
treee5902db5ee2b69f9f3c2fa0dbdeb7f4fc20c68b4 /auth2-chall.c
parent5aa80596f76ce36dee4623a00a55548834c3328d (diff)
Please grep through the source and look for 'ISSUE' comments and verify
that I was able to get all the portable bits in the right location. As for the SKEY comment there is an email out to Markus as to how it should be resolved. Until then I just #ifdef SKEY/#endif out the whole block. - (bal) OpenBSD Resync - markus@cvs.openbsd.org 2001/01/18 16:20:21 [log-client.c log-server.c log.c readconf.c servconf.c ssh.1 ssh.h sshd.8 sshd.c] log() is at pri=LOG_INFO, since LOG_NOTICE goes to /dev/console on many systems - markus@cvs.openbsd.org 2001/01/18 16:59:59 [auth-passwd.c auth.c auth.h auth1.c auth2.c serverloop.c session.c session.h sshconnect1.c] 1) removes fake skey from sshd, since this will be much harder with /usr/libexec/auth/login_XXX 2) share/unify code used in ssh-1 and ssh-2 authentication (server side) 3) make addition of BSD_AUTH and other challenge reponse methods easier. - markus@cvs.openbsd.org 2001/01/18 17:12:43 [auth-chall.c auth2-chall.c] rename *-skey.c *-chall.c since the files are not skey specific
Diffstat (limited to 'auth2-chall.c')
-rw-r--r--auth2-chall.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/auth2-chall.c b/auth2-chall.c
new file mode 100644
index 000000000..77294f4b8
--- /dev/null
+++ b/auth2-chall.c
@@ -0,0 +1,113 @@
1/*
2 * Copyright (c) 2001 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24#include "includes.h"
25RCSID("$OpenBSD: auth2-chall.c,v 1.1 2001/01/18 17:12:43 markus Exp $");
26
27#include "ssh.h"
28#include "ssh2.h"
29#include "auth.h"
30#include "packet.h"
31#include "xmalloc.h"
32#include "dispatch.h"
33
34void send_userauth_into_request(Authctxt *authctxt, char *challenge, int echo);
35void input_userauth_info_response(int type, int plen, void *ctxt);
36
37/*
38 * try challenge-reponse, return -1 (= postponed) if we have to
39 * wait for the response.
40 */
41int
42auth2_challenge(Authctxt *authctxt, char *devs)
43{
44 char *challenge;
45
46 if (!authctxt->valid || authctxt->user == NULL)
47 return 0;
48 if ((challenge = get_challenge(authctxt, devs)) == NULL)
49 return 0;
50 send_userauth_into_request(authctxt, challenge, 0);
51 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE,
52 &input_userauth_info_response);
53 authctxt->postponed = 1;
54 return 0;
55}
56
57void
58send_userauth_into_request(Authctxt *authctxt, char *challenge, int echo)
59{
60 int nprompts = 1;
61
62 packet_start(SSH2_MSG_USERAUTH_INFO_REQUEST);
63 /* name, instruction and language are unused */
64 packet_put_cstring("");
65 packet_put_cstring("");
66 packet_put_cstring("");
67 packet_put_int(nprompts);
68 packet_put_cstring(challenge);
69 packet_put_char(echo);
70 packet_send();
71 packet_write_wait();
72}
73
74void
75input_userauth_info_response(int type, int plen, void *ctxt)
76{
77 Authctxt *authctxt = ctxt;
78 int authenticated = 0;
79 u_int nresp, rlen;
80 char *response, *method = "challenge-reponse";
81
82 if (authctxt == NULL)
83 fatal("input_userauth_info_response: no authctxt");
84
85 authctxt->postponed = 0; /* reset */
86 nresp = packet_get_int();
87 if (nresp == 1) {
88 response = packet_get_string(&rlen);
89 packet_done();
90 if (strlen(response) == 0) {
91 /*
92 * if we received an empty response, resend challenge
93 * with echo enabled
94 */
95 char *challenge = get_challenge(authctxt, NULL);
96 if (challenge != NULL) {
97 send_userauth_into_request(authctxt,
98 challenge, 1);
99 authctxt->postponed = 1;
100 }
101 } else if (authctxt->valid) {
102 authenticated = verify_response(authctxt, response);
103 memset(response, 'r', rlen);
104 }
105 xfree(response);
106 }
107 auth_log(authctxt, authenticated, method, " ssh2");
108 if (!authctxt->postponed) {
109 /* unregister callback and send reply */
110 dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, NULL);
111 userauth_reply(authctxt, authenticated);
112 }
113}