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