xref: /titanic_50/usr/src/cmd/ssh/sshd/auth-rh-rsa.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
3*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4*7c478bd9Sstevel@tonic-gate  *                    All rights reserved
5*7c478bd9Sstevel@tonic-gate  * Rhosts or /etc/hosts.equiv authentication combined with RSA host
6*7c478bd9Sstevel@tonic-gate  * authentication.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
9*7c478bd9Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
10*7c478bd9Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
11*7c478bd9Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
12*7c478bd9Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #include "includes.h"
16*7c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth-rh-rsa.c,v 1.34 2002/03/25 09:25:06 markus Exp $");
17*7c478bd9Sstevel@tonic-gate 
18*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
19*7c478bd9Sstevel@tonic-gate 
20*7c478bd9Sstevel@tonic-gate #include "packet.h"
21*7c478bd9Sstevel@tonic-gate #include "uidswap.h"
22*7c478bd9Sstevel@tonic-gate #include "log.h"
23*7c478bd9Sstevel@tonic-gate #include "servconf.h"
24*7c478bd9Sstevel@tonic-gate #include "key.h"
25*7c478bd9Sstevel@tonic-gate #include "hostfile.h"
26*7c478bd9Sstevel@tonic-gate #include "pathnames.h"
27*7c478bd9Sstevel@tonic-gate #include "auth.h"
28*7c478bd9Sstevel@tonic-gate #include "canohost.h"
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include "monitor_wrap.h"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /* import */
33*7c478bd9Sstevel@tonic-gate extern ServerOptions options;
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate int
36*7c478bd9Sstevel@tonic-gate auth_rhosts_rsa_key_allowed(struct passwd *pw, char *cuser, char *chost,
37*7c478bd9Sstevel@tonic-gate     Key *client_host_key)
38*7c478bd9Sstevel@tonic-gate {
39*7c478bd9Sstevel@tonic-gate 	HostStatus host_status;
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate 	/* Check if we would accept it using rhosts authentication. */
42*7c478bd9Sstevel@tonic-gate 	if (!auth_rhosts(pw, cuser))
43*7c478bd9Sstevel@tonic-gate 		return 0;
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 	host_status = check_key_in_hostfiles(pw, client_host_key,
46*7c478bd9Sstevel@tonic-gate 	    chost, _PATH_SSH_SYSTEM_HOSTFILE,
47*7c478bd9Sstevel@tonic-gate 	    options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE);
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 	return (host_status == HOST_OK);
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /*
53*7c478bd9Sstevel@tonic-gate  * Tries to authenticate the user using the .rhosts file and the host using
54*7c478bd9Sstevel@tonic-gate  * its host key.  Returns true if authentication succeeds.
55*7c478bd9Sstevel@tonic-gate  */
56*7c478bd9Sstevel@tonic-gate int
57*7c478bd9Sstevel@tonic-gate auth_rhosts_rsa(struct passwd *pw, char *cuser, Key *client_host_key)
58*7c478bd9Sstevel@tonic-gate {
59*7c478bd9Sstevel@tonic-gate 	char *chost;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	debug("Trying rhosts with RSA host authentication for client user %.100s",
62*7c478bd9Sstevel@tonic-gate 	    cuser);
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 	if (pw == NULL || client_host_key == NULL ||
65*7c478bd9Sstevel@tonic-gate 	    client_host_key->rsa == NULL)
66*7c478bd9Sstevel@tonic-gate 		return 0;
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	chost = (char *)get_canonical_hostname(options.verify_reverse_mapping);
69*7c478bd9Sstevel@tonic-gate 	debug("Rhosts RSA authentication: canonical host %.900s", chost);
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	if (!PRIVSEP(auth_rhosts_rsa_key_allowed(pw, cuser, chost, client_host_key))) {
72*7c478bd9Sstevel@tonic-gate 		debug("Rhosts with RSA host authentication denied: unknown or invalid host key");
73*7c478bd9Sstevel@tonic-gate 		packet_send_debug("Your host key cannot be verified: unknown or invalid host key.");
74*7c478bd9Sstevel@tonic-gate 		return 0;
75*7c478bd9Sstevel@tonic-gate 	}
76*7c478bd9Sstevel@tonic-gate 	/* A matching host key was found and is known. */
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	/* Perform the challenge-response dialog with the client for the host key. */
79*7c478bd9Sstevel@tonic-gate 	if (!auth_rsa_challenge_dialog(client_host_key)) {
80*7c478bd9Sstevel@tonic-gate 		log("Client on %.800s failed to respond correctly to host authentication.",
81*7c478bd9Sstevel@tonic-gate 		    chost);
82*7c478bd9Sstevel@tonic-gate 		return 0;
83*7c478bd9Sstevel@tonic-gate 	}
84*7c478bd9Sstevel@tonic-gate 	/*
85*7c478bd9Sstevel@tonic-gate 	 * We have authenticated the user using .rhosts or /etc/hosts.equiv,
86*7c478bd9Sstevel@tonic-gate 	 * and the host using RSA. We accept the authentication.
87*7c478bd9Sstevel@tonic-gate 	 */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.",
90*7c478bd9Sstevel@tonic-gate 	   pw->pw_name, cuser, chost);
91*7c478bd9Sstevel@tonic-gate 	packet_send_debug("Rhosts with RSA host authentication accepted.");
92*7c478bd9Sstevel@tonic-gate 	return 1;
93*7c478bd9Sstevel@tonic-gate }
94