5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10 * Created: Sun May 7 03:08:06 1995 ylo
12 * Rhosts or /etc/hosts.equiv authentication combined with RSA host
21 #include <openssl/bn.h>
22 #include <openssl/rsa.h>
23 #include <openssl/dsa.h>
41 * Tries to authenticate the user using the .rhosts file and the host using
42 * its host key. Returns true if authentication succeeds.
46 auth_rhosts_rsa(struct passwd *pw, const char *client_user, RSA *client_host_key)
48 extern ServerOptions options;
49 const char *canonical_hostname;
50 HostStatus host_status;
51 Key *client_key, *found;
53 debug("Trying rhosts with RSA host authentication for %.100s", client_user);
55 if (client_host_key == NULL)
58 /* Check if we would accept it using rhosts authentication. */
59 if (!auth_rhosts(pw, client_user))
62 canonical_hostname = get_canonical_hostname();
64 debug("Rhosts RSA authentication: canonical host %.900s", canonical_hostname);
66 /* wrap the RSA key into a 'generic' key */
67 client_key = key_new(KEY_RSA);
68 BN_copy(client_key->rsa->e, client_host_key->e);
69 BN_copy(client_key->rsa->n, client_host_key->n);
70 found = key_new(KEY_RSA);
72 /* Check if we know the host and its host key. */
73 host_status = check_host_in_hostfile(SSH_SYSTEM_HOSTFILE, canonical_hostname,
76 /* Check user host file unless ignored. */
77 if (host_status != HOST_OK && !options.ignore_user_known_hosts) {
79 char *user_hostfile = tilde_expand_filename(SSH_USER_HOSTFILE, pw->pw_uid);
81 * Check file permissions of SSH_USER_HOSTFILE, auth_rsa()
82 * did already check pw->pw_dir, but there is a race XXX
84 if (options.strict_modes &&
85 (stat(user_hostfile, &st) == 0) &&
86 ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
87 (st.st_mode & 022) != 0)) {
88 log("Rhosts RSA authentication refused for %.100s: bad owner or modes for %.200s",
89 pw->pw_name, user_hostfile);
91 /* XXX race between stat and the following open() */
92 temporarily_use_uid(pw->pw_uid);
93 host_status = check_host_in_hostfile(user_hostfile, canonical_hostname,
102 if (host_status != HOST_OK) {
103 debug("Rhosts with RSA host authentication denied: unknown or invalid host key");
104 packet_send_debug("Your host key cannot be verified: unknown or invalid host key.");
107 /* A matching host key was found and is known. */
109 /* Perform the challenge-response dialog with the client for the host key. */
110 if (!auth_rsa_challenge_dialog(client_host_key)) {
111 log("Client on %.800s failed to respond correctly to host authentication.",
116 * We have authenticated the user using .rhosts or /etc/hosts.equiv,
117 * and the host using RSA. We accept the authentication.
120 verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.",
121 pw->pw_name, client_user, canonical_hostname);
122 packet_send_debug("Rhosts with RSA host authentication accepted.");