Home | History | Annotate | Line # | Download | only in dist
auth-skey.c revision 1.4.2.1
      1  1.4.2.1    bouyer /*	$NetBSD: auth-skey.c,v 1.4.2.1 2017/04/21 16:50:56 bouyer Exp $	*/
      2      1.1  christos /* $OpenBSD: auth-skey.c,v 1.27 2007/01/21 01:41:54 stevesk Exp $ */
      3      1.1  christos /*
      4      1.1  christos  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
      5      1.1  christos  *
      6      1.1  christos  * Redistribution and use in source and binary forms, with or without
      7      1.1  christos  * modification, are permitted provided that the following conditions
      8      1.1  christos  * are met:
      9      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10      1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11      1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  christos  *    documentation and/or other materials provided with the distribution.
     14      1.1  christos  *
     15      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16      1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17      1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18      1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19      1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20      1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21      1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22      1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23      1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24      1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25      1.1  christos  */
     26      1.1  christos #include "includes.h"
     27  1.4.2.1    bouyer __RCSID("$NetBSD: auth-skey.c,v 1.4.2.1 2017/04/21 16:50:56 bouyer Exp $");
     28      1.1  christos 
     29      1.1  christos #ifdef SKEY
     30      1.1  christos 
     31      1.1  christos #include <sys/types.h>
     32      1.1  christos 
     33      1.1  christos #include <pwd.h>
     34      1.1  christos #include <stdio.h>
     35      1.1  christos 
     36      1.1  christos #include <skey.h>
     37      1.1  christos 
     38      1.1  christos #include "xmalloc.h"
     39      1.1  christos #include "key.h"
     40      1.1  christos #include "hostfile.h"
     41      1.1  christos #include "auth.h"
     42      1.1  christos 
     43      1.1  christos #ifdef GSSAPI
     44      1.1  christos #include "buffer.h"
     45      1.1  christos #include "ssh-gss.h"
     46      1.1  christos #endif
     47      1.1  christos 
     48      1.1  christos #include "monitor_wrap.h"
     49      1.1  christos 
     50      1.1  christos static void *
     51      1.1  christos skey_init_ctx(Authctxt *authctxt)
     52      1.1  christos {
     53      1.1  christos 	return authctxt;
     54      1.1  christos }
     55      1.1  christos 
     56      1.1  christos int
     57      1.1  christos skey_query(void *ctx, char **name, char **infotxt,
     58      1.1  christos     u_int* numprompts, char ***prompts, u_int **echo_on)
     59      1.1  christos {
     60      1.1  christos 	Authctxt *authctxt = ctx;
     61      1.1  christos 	char challenge[1024];
     62      1.1  christos 	struct skey skey;
     63      1.1  christos 
     64      1.1  christos 	if (skeychallenge(&skey, authctxt->user, challenge, sizeof(challenge)) == -1)
     65      1.1  christos 		return -1;
     66      1.1  christos 
     67      1.1  christos 	*name = xstrdup("");
     68      1.1  christos 	*infotxt = xstrdup("");
     69      1.1  christos 	*numprompts = 1;
     70      1.1  christos 	*prompts = xcalloc(*numprompts, sizeof(char *));
     71      1.1  christos 	*echo_on = xcalloc(*numprompts, sizeof(u_int));
     72      1.1  christos 
     73      1.1  christos 	xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT);
     74      1.1  christos 
     75      1.1  christos 	return 0;
     76      1.1  christos }
     77      1.1  christos 
     78      1.1  christos int
     79      1.1  christos skey_respond(void *ctx, u_int numresponses, char **responses)
     80      1.1  christos {
     81      1.1  christos 	Authctxt *authctxt = ctx;
     82      1.1  christos 
     83      1.1  christos 	if (authctxt->valid &&
     84      1.1  christos 	    numresponses == 1 &&
     85      1.1  christos 	    skey_haskey(authctxt->pw->pw_name) == 0 &&
     86      1.1  christos 	    skey_passcheck(authctxt->pw->pw_name, responses[0]) != -1)
     87      1.1  christos 	    return 0;
     88      1.1  christos 	return -1;
     89      1.1  christos }
     90      1.1  christos 
     91      1.1  christos static void
     92      1.1  christos skey_free_ctx(void *ctx)
     93      1.1  christos {
     94      1.1  christos 	/* we don't have a special context */
     95      1.1  christos }
     96      1.1  christos 
     97      1.1  christos KbdintDevice skey_device = {
     98      1.1  christos 	"skey",
     99      1.1  christos 	skey_init_ctx,
    100      1.1  christos 	skey_query,
    101      1.1  christos 	skey_respond,
    102      1.1  christos 	skey_free_ctx
    103      1.1  christos };
    104      1.1  christos 
    105      1.1  christos KbdintDevice mm_skey_device = {
    106      1.1  christos 	"skey",
    107      1.1  christos 	skey_init_ctx,
    108      1.1  christos 	mm_skey_query,
    109      1.1  christos 	mm_skey_respond,
    110      1.1  christos 	skey_free_ctx
    111      1.1  christos };
    112      1.1  christos #endif /* SKEY */
    113