xref: /netbsd-src/crypto/external/bsd/openssh/dist/auth-skey.c (revision 41768fc151975edf5da042dafee95bcbf07f4525)
1*41768fc1Schristos /*	$NetBSD: auth-skey.c,v 1.5 2017/04/18 18:41:46 christos Exp $	*/
2313c6c94Schristos /* $OpenBSD: auth-skey.c,v 1.27 2007/01/21 01:41:54 stevesk Exp $ */
3313c6c94Schristos /*
4313c6c94Schristos  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
5313c6c94Schristos  *
6313c6c94Schristos  * Redistribution and use in source and binary forms, with or without
7313c6c94Schristos  * modification, are permitted provided that the following conditions
8313c6c94Schristos  * are met:
9313c6c94Schristos  * 1. Redistributions of source code must retain the above copyright
10313c6c94Schristos  *    notice, this list of conditions and the following disclaimer.
11313c6c94Schristos  * 2. Redistributions in binary form must reproduce the above copyright
12313c6c94Schristos  *    notice, this list of conditions and the following disclaimer in the
13313c6c94Schristos  *    documentation and/or other materials provided with the distribution.
14313c6c94Schristos  *
15313c6c94Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16313c6c94Schristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17313c6c94Schristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18313c6c94Schristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19313c6c94Schristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20313c6c94Schristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21313c6c94Schristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22313c6c94Schristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23313c6c94Schristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24313c6c94Schristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25313c6c94Schristos  */
26313c6c94Schristos #include "includes.h"
27*41768fc1Schristos __RCSID("$NetBSD: auth-skey.c,v 1.5 2017/04/18 18:41:46 christos Exp $");
28313c6c94Schristos 
29313c6c94Schristos #ifdef SKEY
30313c6c94Schristos 
31313c6c94Schristos #include <sys/types.h>
32313c6c94Schristos 
33313c6c94Schristos #include <pwd.h>
34313c6c94Schristos #include <stdio.h>
35313c6c94Schristos 
36313c6c94Schristos #include <skey.h>
37313c6c94Schristos 
38313c6c94Schristos #include "xmalloc.h"
39313c6c94Schristos #include "key.h"
40313c6c94Schristos #include "hostfile.h"
41313c6c94Schristos #include "auth.h"
42313c6c94Schristos 
43313c6c94Schristos #ifdef GSSAPI
44313c6c94Schristos #include "buffer.h"
45313c6c94Schristos #include "ssh-gss.h"
46313c6c94Schristos #endif
47313c6c94Schristos 
48313c6c94Schristos #include "monitor_wrap.h"
49313c6c94Schristos 
50313c6c94Schristos static void *
skey_init_ctx(Authctxt * authctxt)51313c6c94Schristos skey_init_ctx(Authctxt *authctxt)
52313c6c94Schristos {
53313c6c94Schristos 	return authctxt;
54313c6c94Schristos }
55313c6c94Schristos 
56313c6c94Schristos int
skey_query(void * ctx,char ** name,char ** infotxt,u_int * numprompts,char *** prompts,u_int ** echo_on)57313c6c94Schristos skey_query(void *ctx, char **name, char **infotxt,
58313c6c94Schristos     u_int* numprompts, char ***prompts, u_int **echo_on)
59313c6c94Schristos {
60313c6c94Schristos 	Authctxt *authctxt = ctx;
61313c6c94Schristos 	char challenge[1024];
62313c6c94Schristos 	struct skey skey;
63313c6c94Schristos 
64313c6c94Schristos 	if (skeychallenge(&skey, authctxt->user, challenge, sizeof(challenge)) == -1)
65313c6c94Schristos 		return -1;
66313c6c94Schristos 
67313c6c94Schristos 	*name = xstrdup("");
68313c6c94Schristos 	*infotxt = xstrdup("");
69313c6c94Schristos 	*numprompts = 1;
70313c6c94Schristos 	*prompts = xcalloc(*numprompts, sizeof(char *));
71313c6c94Schristos 	*echo_on = xcalloc(*numprompts, sizeof(u_int));
72313c6c94Schristos 
73313c6c94Schristos 	xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT);
74313c6c94Schristos 
75313c6c94Schristos 	return 0;
76313c6c94Schristos }
77313c6c94Schristos 
78313c6c94Schristos int
skey_respond(void * ctx,u_int numresponses,char ** responses)79313c6c94Schristos skey_respond(void *ctx, u_int numresponses, char **responses)
80313c6c94Schristos {
81313c6c94Schristos 	Authctxt *authctxt = ctx;
82313c6c94Schristos 
83313c6c94Schristos 	if (authctxt->valid &&
84313c6c94Schristos 	    numresponses == 1 &&
85313c6c94Schristos 	    skey_haskey(authctxt->pw->pw_name) == 0 &&
86313c6c94Schristos 	    skey_passcheck(authctxt->pw->pw_name, responses[0]) != -1)
87313c6c94Schristos 	    return 0;
88313c6c94Schristos 	return -1;
89313c6c94Schristos }
90313c6c94Schristos 
91313c6c94Schristos static void
skey_free_ctx(void * ctx)92313c6c94Schristos skey_free_ctx(void *ctx)
93313c6c94Schristos {
94313c6c94Schristos 	/* we don't have a special context */
95313c6c94Schristos }
96313c6c94Schristos 
97313c6c94Schristos KbdintDevice skey_device = {
98313c6c94Schristos 	"skey",
99313c6c94Schristos 	skey_init_ctx,
100313c6c94Schristos 	skey_query,
101313c6c94Schristos 	skey_respond,
102313c6c94Schristos 	skey_free_ctx
103313c6c94Schristos };
104313c6c94Schristos 
105313c6c94Schristos KbdintDevice mm_skey_device = {
106313c6c94Schristos 	"skey",
107313c6c94Schristos 	skey_init_ctx,
108313c6c94Schristos 	mm_skey_query,
109313c6c94Schristos 	mm_skey_respond,
110313c6c94Schristos 	skey_free_ctx
111313c6c94Schristos };
112313c6c94Schristos #endif /* SKEY */
113