]> andersk Git - openssh.git/blob - auth-rh-rsa.c
- OpenBSD CVS updates.
[openssh.git] / auth-rh-rsa.c
1 /*
2  *
3  * auth-rh-rsa.c
4  *
5  * Author: Tatu Ylonen <ylo@cs.hut.fi>
6  *
7  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8  *                    All rights reserved
9  *
10  * Created: Sun May  7 03:08:06 1995 ylo
11  *
12  * Rhosts or /etc/hosts.equiv authentication combined with RSA host
13  * authentication.
14  *
15  */
16
17 #include "includes.h"
18 RCSID("$Id$");
19
20 #ifdef HAVE_OPENSSL
21 #include <openssl/bn.h>
22 #include <openssl/rsa.h>
23 #include <openssl/dsa.h>
24 #endif
25 #ifdef HAVE_SSL
26 #include <ssl/bn.h>
27 #include <ssl/rsa.h>
28 #include <ssl/dsa.h>
29 #endif
30
31 #include "packet.h"
32 #include "ssh.h"
33 #include "xmalloc.h"
34 #include "uidswap.h"
35 #include "servconf.h"
36
37 #include "key.h"
38 #include "hostfile.h"
39
40 /*
41  * Tries to authenticate the user using the .rhosts file and the host using
42  * its host key.  Returns true if authentication succeeds.
43  */
44
45 int
46 auth_rhosts_rsa(struct passwd *pw, const char *client_user, RSA *client_host_key)
47 {
48         extern ServerOptions options;
49         const char *canonical_hostname;
50         HostStatus host_status;
51         Key *client_key, *found;
52
53         debug("Trying rhosts with RSA host authentication for %.100s", client_user);
54
55         if (client_host_key == NULL)
56                 return 0;
57
58         /* Check if we would accept it using rhosts authentication. */
59         if (!auth_rhosts(pw, client_user))
60                 return 0;
61
62         canonical_hostname = get_canonical_hostname();
63
64         debug("Rhosts RSA authentication: canonical host %.900s", canonical_hostname);
65
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);
71
72         /* Check if we know the host and its host key. */
73         host_status = check_host_in_hostfile(SSH_SYSTEM_HOSTFILE, canonical_hostname,
74             client_key, found);
75
76         /* Check user host file unless ignored. */
77         if (host_status != HOST_OK && !options.ignore_user_known_hosts) {
78                 struct stat st;
79                 char *user_hostfile = tilde_expand_filename(SSH_USER_HOSTFILE, pw->pw_uid);
80                 /*
81                  * Check file permissions of SSH_USER_HOSTFILE, auth_rsa()
82                  * did already check pw->pw_dir, but there is a race XXX
83                  */
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);
90                 } else {
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,
94                             client_key, found);
95                         restore_uid();
96                 }
97                 xfree(user_hostfile);
98         }
99         key_free(client_key);
100         key_free(found);
101
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.");
105                 return 0;
106         }
107         /* A matching host key was found and is known. */
108
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.",
112                     canonical_hostname);
113                 return 0;
114         }
115         /*
116          * We have authenticated the user using .rhosts or /etc/hosts.equiv,
117          * and the host using RSA. We accept the authentication.
118          */
119
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.");
123         return 1;
124 }
This page took 0.109315 seconds and 5 git commands to generate.