10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Author: Tatu Ylonen <ylo@cs.hut.fi>
30Sstevel@tonic-gate * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
40Sstevel@tonic-gate * All rights reserved
50Sstevel@tonic-gate * Rhosts or /etc/hosts.equiv authentication combined with RSA host
60Sstevel@tonic-gate * authentication.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * As far as I am concerned, the code I have written for this software
90Sstevel@tonic-gate * can be used freely for any purpose. Any derived versions of this
100Sstevel@tonic-gate * software must be clearly marked as such, and if the derived work is
110Sstevel@tonic-gate * incompatible with the protocol description in the RFC file, it must be
120Sstevel@tonic-gate * called by a name other than "ssh" or "Secure Shell".
130Sstevel@tonic-gate */
140Sstevel@tonic-gate
150Sstevel@tonic-gate #include "includes.h"
160Sstevel@tonic-gate RCSID("$OpenBSD: auth-rh-rsa.c,v 1.34 2002/03/25 09:25:06 markus Exp $");
170Sstevel@tonic-gate
180Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
190Sstevel@tonic-gate
200Sstevel@tonic-gate #include "packet.h"
210Sstevel@tonic-gate #include "uidswap.h"
220Sstevel@tonic-gate #include "log.h"
230Sstevel@tonic-gate #include "servconf.h"
240Sstevel@tonic-gate #include "key.h"
250Sstevel@tonic-gate #include "hostfile.h"
260Sstevel@tonic-gate #include "pathnames.h"
270Sstevel@tonic-gate #include "auth.h"
280Sstevel@tonic-gate #include "canohost.h"
290Sstevel@tonic-gate
300Sstevel@tonic-gate /* import */
310Sstevel@tonic-gate extern ServerOptions options;
320Sstevel@tonic-gate
330Sstevel@tonic-gate int
auth_rhosts_rsa_key_allowed(struct passwd * pw,char * cuser,char * chost,Key * client_host_key)340Sstevel@tonic-gate auth_rhosts_rsa_key_allowed(struct passwd *pw, char *cuser, char *chost,
350Sstevel@tonic-gate Key *client_host_key)
360Sstevel@tonic-gate {
370Sstevel@tonic-gate HostStatus host_status;
380Sstevel@tonic-gate
390Sstevel@tonic-gate /* Check if we would accept it using rhosts authentication. */
400Sstevel@tonic-gate if (!auth_rhosts(pw, cuser))
410Sstevel@tonic-gate return 0;
420Sstevel@tonic-gate
430Sstevel@tonic-gate host_status = check_key_in_hostfiles(pw, client_host_key,
440Sstevel@tonic-gate chost, _PATH_SSH_SYSTEM_HOSTFILE,
450Sstevel@tonic-gate options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE);
460Sstevel@tonic-gate
470Sstevel@tonic-gate return (host_status == HOST_OK);
480Sstevel@tonic-gate }
490Sstevel@tonic-gate
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate * Tries to authenticate the user using the .rhosts file and the host using
520Sstevel@tonic-gate * its host key. Returns true if authentication succeeds.
530Sstevel@tonic-gate */
540Sstevel@tonic-gate int
auth_rhosts_rsa(struct passwd * pw,char * cuser,Key * client_host_key)550Sstevel@tonic-gate auth_rhosts_rsa(struct passwd *pw, char *cuser, Key *client_host_key)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate char *chost;
580Sstevel@tonic-gate
590Sstevel@tonic-gate debug("Trying rhosts with RSA host authentication for client user %.100s",
600Sstevel@tonic-gate cuser);
610Sstevel@tonic-gate
620Sstevel@tonic-gate if (pw == NULL || client_host_key == NULL ||
630Sstevel@tonic-gate client_host_key->rsa == NULL)
640Sstevel@tonic-gate return 0;
650Sstevel@tonic-gate
660Sstevel@tonic-gate chost = (char *)get_canonical_hostname(options.verify_reverse_mapping);
670Sstevel@tonic-gate debug("Rhosts RSA authentication: canonical host %.900s", chost);
680Sstevel@tonic-gate
69*5562Sjp161948 if (!auth_rhosts_rsa_key_allowed(pw, cuser, chost, client_host_key)) {
700Sstevel@tonic-gate debug("Rhosts with RSA host authentication denied: unknown or invalid host key");
710Sstevel@tonic-gate packet_send_debug("Your host key cannot be verified: unknown or invalid host key.");
720Sstevel@tonic-gate return 0;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate /* A matching host key was found and is known. */
750Sstevel@tonic-gate
760Sstevel@tonic-gate /* Perform the challenge-response dialog with the client for the host key. */
770Sstevel@tonic-gate if (!auth_rsa_challenge_dialog(client_host_key)) {
780Sstevel@tonic-gate log("Client on %.800s failed to respond correctly to host authentication.",
790Sstevel@tonic-gate chost);
800Sstevel@tonic-gate return 0;
810Sstevel@tonic-gate }
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * We have authenticated the user using .rhosts or /etc/hosts.equiv,
840Sstevel@tonic-gate * and the host using RSA. We accept the authentication.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate
870Sstevel@tonic-gate verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.",
880Sstevel@tonic-gate pw->pw_name, cuser, chost);
890Sstevel@tonic-gate packet_send_debug("Rhosts with RSA host authentication accepted.");
900Sstevel@tonic-gate return 1;
910Sstevel@tonic-gate }
92