xref: /titanic_41/usr/src/cmd/ssh/sshd/auth-rh-rsa.c (revision 9a8058b57457911fab0e3b4b6f0a97740e7a816d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
37c478bd9Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
47c478bd9Sstevel@tonic-gate  *                    All rights reserved
57c478bd9Sstevel@tonic-gate  * Rhosts or /etc/hosts.equiv authentication combined with RSA host
67c478bd9Sstevel@tonic-gate  * authentication.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
97c478bd9Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
107c478bd9Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
117c478bd9Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
127c478bd9Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include "includes.h"
167c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth-rh-rsa.c,v 1.34 2002/03/25 09:25:06 markus Exp $");
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include "packet.h"
217c478bd9Sstevel@tonic-gate #include "uidswap.h"
227c478bd9Sstevel@tonic-gate #include "log.h"
237c478bd9Sstevel@tonic-gate #include "servconf.h"
247c478bd9Sstevel@tonic-gate #include "key.h"
257c478bd9Sstevel@tonic-gate #include "hostfile.h"
267c478bd9Sstevel@tonic-gate #include "pathnames.h"
277c478bd9Sstevel@tonic-gate #include "auth.h"
287c478bd9Sstevel@tonic-gate #include "canohost.h"
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /* import */
317c478bd9Sstevel@tonic-gate extern ServerOptions options;
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate int
auth_rhosts_rsa_key_allowed(struct passwd * pw,char * cuser,char * chost,Key * client_host_key)347c478bd9Sstevel@tonic-gate auth_rhosts_rsa_key_allowed(struct passwd *pw, char *cuser, char *chost,
357c478bd9Sstevel@tonic-gate     Key *client_host_key)
367c478bd9Sstevel@tonic-gate {
377c478bd9Sstevel@tonic-gate 	HostStatus host_status;
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	/* Check if we would accept it using rhosts authentication. */
407c478bd9Sstevel@tonic-gate 	if (!auth_rhosts(pw, cuser))
417c478bd9Sstevel@tonic-gate 		return 0;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 	host_status = check_key_in_hostfiles(pw, client_host_key,
447c478bd9Sstevel@tonic-gate 	    chost, _PATH_SSH_SYSTEM_HOSTFILE,
457c478bd9Sstevel@tonic-gate 	    options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate 	return (host_status == HOST_OK);
487c478bd9Sstevel@tonic-gate }
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Tries to authenticate the user using the .rhosts file and the host using
527c478bd9Sstevel@tonic-gate  * its host key.  Returns true if authentication succeeds.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate int
auth_rhosts_rsa(struct passwd * pw,char * cuser,Key * client_host_key)557c478bd9Sstevel@tonic-gate auth_rhosts_rsa(struct passwd *pw, char *cuser, Key *client_host_key)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate 	char *chost;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	debug("Trying rhosts with RSA host authentication for client user %.100s",
607c478bd9Sstevel@tonic-gate 	    cuser);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	if (pw == NULL || client_host_key == NULL ||
637c478bd9Sstevel@tonic-gate 	    client_host_key->rsa == NULL)
647c478bd9Sstevel@tonic-gate 		return 0;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	chost = (char *)get_canonical_hostname(options.verify_reverse_mapping);
677c478bd9Sstevel@tonic-gate 	debug("Rhosts RSA authentication: canonical host %.900s", chost);
687c478bd9Sstevel@tonic-gate 
69*9a8058b5Sjp161948 	if (!auth_rhosts_rsa_key_allowed(pw, cuser, chost, client_host_key)) {
707c478bd9Sstevel@tonic-gate 		debug("Rhosts with RSA host authentication denied: unknown or invalid host key");
717c478bd9Sstevel@tonic-gate 		packet_send_debug("Your host key cannot be verified: unknown or invalid host key.");
727c478bd9Sstevel@tonic-gate 		return 0;
737c478bd9Sstevel@tonic-gate 	}
747c478bd9Sstevel@tonic-gate 	/* A matching host key was found and is known. */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/* Perform the challenge-response dialog with the client for the host key. */
777c478bd9Sstevel@tonic-gate 	if (!auth_rsa_challenge_dialog(client_host_key)) {
787c478bd9Sstevel@tonic-gate 		log("Client on %.800s failed to respond correctly to host authentication.",
797c478bd9Sstevel@tonic-gate 		    chost);
807c478bd9Sstevel@tonic-gate 		return 0;
817c478bd9Sstevel@tonic-gate 	}
827c478bd9Sstevel@tonic-gate 	/*
837c478bd9Sstevel@tonic-gate 	 * We have authenticated the user using .rhosts or /etc/hosts.equiv,
847c478bd9Sstevel@tonic-gate 	 * and the host using RSA. We accept the authentication.
857c478bd9Sstevel@tonic-gate 	 */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.",
887c478bd9Sstevel@tonic-gate 	   pw->pw_name, cuser, chost);
897c478bd9Sstevel@tonic-gate 	packet_send_debug("Rhosts with RSA host authentication accepted.");
907c478bd9Sstevel@tonic-gate 	return 1;
917c478bd9Sstevel@tonic-gate }
92