blob: aced659c0c6b78c1b200fe56033153f109fafd87 [file] [log] [blame]
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00001/*
Ben Lindstrom92a2e382001-03-05 06:59:27 +00002 * Copyright (c) 2001 Markus Friedl. All rights reserved.
Ben Lindstromdb65e8f2001-01-19 04:26:52 +00003 *
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
25#include "includes.h"
Ben Lindstrom92a2e382001-03-05 06:59:27 +000026RCSID("$OpenBSD: auth-chall.c,v 1.5 2001/03/02 18:54:30 deraadt Exp $");
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000027
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000028#include "auth.h"
Damien Miller60396b02001-02-18 17:01:00 +110029#include "log.h"
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000030
Damien Miller60396b02001-02-18 17:01:00 +110031#ifdef BSD_AUTH
32char *
33get_challenge(Authctxt *authctxt, char *devs)
34{
35 char *challenge;
36
37 if (authctxt->as != NULL) {
38 debug2("try reuse session");
39 challenge = auth_getitem(authctxt->as, AUTHV_CHALLENGE);
40 if (challenge != NULL) {
41 debug2("reuse bsd auth session");
42 return challenge;
43 }
44 auth_close(authctxt->as);
45 authctxt->as = NULL;
46 }
47 debug2("new bsd auth session");
48 if (devs == NULL || strlen(devs) == 0)
49 devs = authctxt->style;
50 debug3("bsd auth: devs %s", devs ? devs : "<default>");
51 authctxt->as = auth_userchallenge(authctxt->user, devs, "auth-ssh",
52 &challenge);
53 if (authctxt->as == NULL)
54 return NULL;
55 debug2("get_challenge: <%s>", challenge ? challenge : "EMPTY");
56 return challenge;
57}
58int
59verify_response(Authctxt *authctxt, char *response)
60{
61 int authok;
62
63 if (authctxt->as == 0)
64 error("verify_response: no bsd auth session");
65 authok = auth_userresponse(authctxt->as, response, 0);
66 authctxt->as = NULL;
67 debug("verify_response: <%s> = <%d>", response, authok);
68 return authok != 0;
69}
70#else
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000071#ifdef SKEY
Ben Lindstromcf0809d2001-01-19 15:44:10 +000072#include <skey.h>
73
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000074char *
75get_challenge(Authctxt *authctxt, char *devs)
76{
77 static char challenge[1024];
Kevin Stevesef4eea92001-02-05 12:42:17 +000078 struct skey skey;
Ben Lindstromdb65e8f2001-01-19 04:26:52 +000079 if (skeychallenge(&skey, authctxt->user, challenge) == -1)
80 return NULL;
81 strlcat(challenge, "\nS/Key Password: ", sizeof challenge);
82 return challenge;
83}
84int
85verify_response(Authctxt *authctxt, char *response)
86{
87 return (authctxt->valid &&
88 skey_haskey(authctxt->pw->pw_name) == 0 &&
89 skey_passcheck(authctxt->pw->pw_name, response) != -1);
90}
91#else
92/* not available */
93char *
94get_challenge(Authctxt *authctxt, char *devs)
95{
96 return NULL;
97}
98int
99verify_response(Authctxt *authctxt, char *response)
100{
101 return 0;
102}
103#endif
Damien Miller60396b02001-02-18 17:01:00 +1100104#endif