Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

auth-rh-rsa.c

Go to the documentation of this file.
00001 /*
00002  * Author: Tatu Ylonen <ylo@cs.hut.fi>
00003  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
00004  *                    All rights reserved
00005  * Rhosts or /etc/hosts.equiv authentication combined with RSA host
00006  * authentication.
00007  *
00008  * As far as I am concerned, the code I have written for this software
00009  * can be used freely for any purpose.  Any derived versions of this
00010  * software must be clearly marked as such, and if the derived work is
00011  * incompatible with the protocol description in the RFC file, it must be
00012  * called by a name other than "ssh" or "Secure Shell".
00013  */
00014 
00015 #include "includes.h"
00016 RCSID("$OpenBSD: auth-rh-rsa.c,v 1.38 2005/07/17 07:17:54 djm Exp $");
00017 
00018 #include "packet.h"
00019 #include "uidswap.h"
00020 #include "log.h"
00021 #include "servconf.h"
00022 #include "key.h"
00023 #include "hostfile.h"
00024 #include "pathnames.h"
00025 #include "auth.h"
00026 #include "canohost.h"
00027 
00028 #include "monitor_wrap.h"
00029 
00030 /* import */
00031 extern ServerOptions options;
00032 
00033 int
00034 auth_rhosts_rsa_key_allowed(struct passwd *pw, char *cuser, char *chost,
00035     Key *client_host_key)
00036 {
00037         HostStatus host_status;
00038 
00039         /* Check if we would accept it using rhosts authentication. */
00040         if (!auth_rhosts(pw, cuser))
00041                 return 0;
00042 
00043         host_status = check_key_in_hostfiles(pw, client_host_key,
00044             chost, _PATH_SSH_SYSTEM_HOSTFILE,
00045             options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE);
00046 
00047         return (host_status == HOST_OK);
00048 }
00049 
00050 /*
00051  * Tries to authenticate the user using the .rhosts file and the host using
00052  * its host key.  Returns true if authentication succeeds.
00053  */
00054 int
00055 auth_rhosts_rsa(Authctxt *authctxt, char *cuser, Key *client_host_key)
00056 {
00057         char *chost;
00058         struct passwd *pw = authctxt->pw;
00059 
00060         debug("Trying rhosts with RSA host authentication for client user %.100s",
00061             cuser);
00062 
00063         if (!authctxt->valid || client_host_key == NULL ||
00064             client_host_key->rsa == NULL)
00065                 return 0;
00066 
00067         chost = (char *)get_canonical_hostname(options.use_dns);
00068         debug("Rhosts RSA authentication: canonical host %.900s", chost);
00069 
00070         if (!PRIVSEP(auth_rhosts_rsa_key_allowed(pw, cuser, chost, client_host_key))) {
00071                 debug("Rhosts with RSA host authentication denied: unknown or invalid host key");
00072                 packet_send_debug("Your host key cannot be verified: unknown or invalid host key.");
00073                 return 0;
00074         }
00075         /* A matching host key was found and is known. */
00076 
00077         /* Perform the challenge-response dialog with the client for the host key. */
00078         if (!auth_rsa_challenge_dialog(client_host_key)) {
00079                 logit("Client on %.800s failed to respond correctly to host authentication.",
00080                     chost);
00081                 return 0;
00082         }
00083         /*
00084          * We have authenticated the user using .rhosts or /etc/hosts.equiv,
00085          * and the host using RSA. We accept the authentication.
00086          */
00087 
00088         verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.",
00089             pw->pw_name, cuser, chost);
00090         packet_send_debug("Rhosts with RSA host authentication accepted.");
00091         return 1;
00092 }

© sourcejam.com 2005-2008