auth-rh-rsa.c revision 98684
137Srgrimes/* 247783Sandreas * Author: Tatu Ylonen <ylo@cs.hut.fi> 337Srgrimes * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 450472Speter * All rights reserved 5705Swollman * Rhosts or /etc/hosts.equiv authentication combined with RSA host 637Srgrimes * authentication. 784772Sarchie * 8705Swollman * As far as I am concerned, the code I have written for this software 937Srgrimes * can be used freely for any purpose. Any derived versions of this 10169786Sgrog * software must be clearly marked as such, and if the derived work is 1137Srgrimes * incompatible with the protocol description in the RFC file, it must be 1247783Sandreas * called by a name other than "ssh" or "Secure Shell". 1337Srgrimes */ 14169786Sgrog 15169786Sgrog#include "includes.h" 1637SrgrimesRCSID("$OpenBSD: auth-rh-rsa.c,v 1.34 2002/03/25 09:25:06 markus Exp $"); 1747783SandreasRCSID("$FreeBSD: head/crypto/openssh/auth-rh-rsa.c 98684 2002-06-23 16:09:08Z des $"); 1837Srgrimes 1947783Sandreas#include "packet.h" 20169786Sgrog#include "uidswap.h" 2147783Sandreas#include "log.h" 2237Srgrimes#include "servconf.h" 2347783Sandreas#include "key.h" 2447783Sandreas#include "hostfile.h" 2547783Sandreas#include "pathnames.h" 2647783Sandreas#include "auth.h" 2737Srgrimes#include "canohost.h" 2847783Sandreas 2947783Sandreas#include "monitor_wrap.h" 3037Srgrimes 3147783Sandreas/* import */ 32169786Sgrogextern ServerOptions options; 33169786Sgrog 34169786Sgrogint 3547783Sandreasauth_rhosts_rsa_key_allowed(struct passwd *pw, char *cuser, char *chost, 3647783Sandreas Key *client_host_key) 3737Srgrimes{ 3847783Sandreas HostStatus host_status; 39169786Sgrog 4047783Sandreas /* Check if we would accept it using rhosts authentication. */ 41169786Sgrog if (!auth_rhosts(pw, cuser)) 4247783Sandreas return 0; 43169786Sgrog 4447783Sandreas host_status = check_key_in_hostfiles(pw, client_host_key, 4547783Sandreas chost, _PATH_SSH_SYSTEM_HOSTFILE, 46705Swollman options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE); 4747783Sandreas 4847783Sandreas return (host_status == HOST_OK); 4947783Sandreas} 5047783Sandreas 5130672Sitojun/* 5247783Sandreas * Tries to authenticate the user using the .rhosts file and the host using 5330672Sitojun * its host key. Returns true if authentication succeeds. 5430672Sitojun */ 5547783Sandreasint 5610422Swollmanauth_rhosts_rsa(struct passwd *pw, char *cuser, Key *client_host_key) 5747783Sandreas{ 58169786Sgrog char *chost; 5947783Sandreas 6030672Sitojun debug("Trying rhosts with RSA host authentication for client user %.100s", 6130672Sitojun cuser); 6247783Sandreas 6347783Sandreas if (pw == NULL || client_host_key == NULL || 6447783Sandreas client_host_key->rsa == NULL) 6547783Sandreas return 0; 6647783Sandreas 6747783Sandreas chost = (char *)get_canonical_hostname(options.verify_reverse_mapping); 68126756Smlaier debug("Rhosts RSA authentication: canonical host %.900s", chost); 6930672Sitojun 7030672Sitojun if (!PRIVSEP(auth_rhosts_rsa_key_allowed(pw, cuser, chost, client_host_key))) { 7147783Sandreas debug("Rhosts with RSA host authentication denied: unknown or invalid host key"); 7247783Sandreas packet_send_debug("Your host key cannot be verified: unknown or invalid host key."); 7347783Sandreas return 0; 7447783Sandreas } 7547783Sandreas /* A matching host key was found and is known. */ 7647783Sandreas 7747783Sandreas /* Perform the challenge-response dialog with the client for the host key. */ 7896703Strhodes if (!auth_rsa_challenge_dialog(client_host_key)) { 79169786Sgrog log("Client on %.800s failed to respond correctly to host authentication.", 8047783Sandreas chost); 8147783Sandreas return 0; 8247783Sandreas } 8347783Sandreas /* 8447783Sandreas * We have authenticated the user using .rhosts or /etc/hosts.equiv, 8547783Sandreas * and the host using RSA. We accept the authentication. 8647783Sandreas */ 8747783Sandreas 8847783Sandreas verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.", 8947783Sandreas pw->pw_name, cuser, chost); 9047783Sandreas packet_send_debug("Rhosts with RSA host authentication accepted."); 91705Swollman return 1; 9247783Sandreas} 9347783Sandreas