auth-skey.c revision 98684
1254885Sdumbbell/*
2254885Sdumbbell * Copyright (c) 2001 Markus Friedl.  All rights reserved.
3254885Sdumbbell *
4254885Sdumbbell * Redistribution and use in source and binary forms, with or without
5254885Sdumbbell * modification, are permitted provided that the following conditions
6254885Sdumbbell * are met:
7254885Sdumbbell * 1. Redistributions of source code must retain the above copyright
8254885Sdumbbell *    notice, this list of conditions and the following disclaimer.
9254885Sdumbbell * 2. Redistributions in binary form must reproduce the above copyright
10254885Sdumbbell *    notice, this list of conditions and the following disclaimer in the
11254885Sdumbbell *    documentation and/or other materials provided with the distribution.
12254885Sdumbbell *
13254885Sdumbbell * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14254885Sdumbbell * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15254885Sdumbbell * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16254885Sdumbbell * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17254885Sdumbbell * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18254885Sdumbbell * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19254885Sdumbbell * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20254885Sdumbbell * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21254885Sdumbbell * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22254885Sdumbbell * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23254885Sdumbbell */
24254885Sdumbbell#include "includes.h"
25254885SdumbbellRCSID("$OpenBSD: auth-skey.c,v 1.19 2002/06/19 00:27:55 deraadt Exp $");
26254885SdumbbellRCSID("$FreeBSD: head/crypto/openssh/auth-skey.c 98684 2002-06-23 16:09:08Z des $");
27254885Sdumbbell
28254885Sdumbbell#ifdef SKEY
29254885Sdumbbell
30254885Sdumbbell#include <opie.h>
31254885Sdumbbell
32254885Sdumbbell#include "xmalloc.h"
33254885Sdumbbell#include "auth.h"
34267430Sdumbbell#include "monitor_wrap.h"
35254885Sdumbbell
36267430Sdumbbellstatic void *
37267430Sdumbbellskey_init_ctx(Authctxt *authctxt)
38267430Sdumbbell{
39267430Sdumbbell	return authctxt;
40267430Sdumbbell}
41254885Sdumbbell
42254885Sdumbbellint
43254885Sdumbbellskey_query(void *ctx, char **name, char **infotxt,
44254885Sdumbbell    u_int* numprompts, char ***prompts, u_int **echo_on)
45254885Sdumbbell{
46254885Sdumbbell	Authctxt *authctxt = ctx;
47254885Sdumbbell	char challenge[1024], *p;
48254885Sdumbbell	int len;
49254885Sdumbbell	struct opie opie;
50254885Sdumbbell
51254885Sdumbbell	if (opie_haskey(authctxt->user) != 0)
52254885Sdumbbell		return -1;
53254885Sdumbbell	if (opiechallenge(&opie, authctxt->user, challenge) == -1)
54254885Sdumbbell		return -1;
55254885Sdumbbell
56254885Sdumbbell	*name  = xstrdup("");
57254885Sdumbbell	*infotxt  = xstrdup("");
58254885Sdumbbell	*numprompts = 1;
59254885Sdumbbell	*prompts = xmalloc(*numprompts * sizeof(char*));
60254885Sdumbbell	*echo_on = xmalloc(*numprompts * sizeof(u_int));
61254885Sdumbbell	(*echo_on)[0] = 0;
62254885Sdumbbell
63254885Sdumbbell	len = strlen(challenge) + strlen(SKEY_PROMPT) + 1;
64254885Sdumbbell	p = xmalloc(len);
65254885Sdumbbell	strlcpy(p, challenge, len);
66267430Sdumbbell	strlcat(p, SKEY_PROMPT, len);
67267430Sdumbbell	(*prompts)[0] = p;
68254885Sdumbbell
69267430Sdumbbell	return 0;
70267430Sdumbbell}
71254885Sdumbbell
72267430Sdumbbellint
73254885Sdumbbellskey_respond(void *ctx, u_int numresponses, char **responses)
74267430Sdumbbell{
75267430Sdumbbell	Authctxt *authctxt = ctx;
76267430Sdumbbell
77267430Sdumbbell	if (authctxt->valid &&
78267430Sdumbbell	    numresponses == 1 &&
79267430Sdumbbell	    opie_haskey(authctxt->pw->pw_name) == 0 &&
80267430Sdumbbell	    opie_passverify(authctxt->pw->pw_name, responses[0]) != -1)
81267430Sdumbbell	    return 0;
82267430Sdumbbell	return -1;
83267430Sdumbbell}
84267430Sdumbbell
85267430Sdumbbellstatic void
86267430Sdumbbellskey_free_ctx(void *ctx)
87267430Sdumbbell{
88267430Sdumbbell	/* we don't have a special context */
89267430Sdumbbell}
90267430Sdumbbell
91267430SdumbbellKbdintDevice skey_device = {
92267430Sdumbbell	"skey",
93267430Sdumbbell	skey_init_ctx,
94267430Sdumbbell	skey_query,
95254885Sdumbbell	skey_respond,
96267430Sdumbbell	skey_free_ctx
97254885Sdumbbell};
98254885Sdumbbell
99254885SdumbbellKbdintDevice mm_skey_device = {
100254885Sdumbbell	"skey",
101254885Sdumbbell	skey_init_ctx,
102254885Sdumbbell	mm_skey_query,
103254885Sdumbbell	mm_skey_respond,
104254885Sdumbbell	skey_free_ctx
105254885Sdumbbell};
106254885Sdumbbell#endif /* SKEY */
107254885Sdumbbell