]>
Commit | Line | Data |
---|---|---|
8efc0c15 | 1 | /* |
6ae2364d | 2 | * |
5260325f | 3 | * auth-rh-rsa.c |
6ae2364d | 4 | * |
5260325f | 5 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
6ae2364d | 6 | * |
5260325f | 7 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
8 | * All rights reserved | |
6ae2364d | 9 | * |
5260325f | 10 | * Created: Sun May 7 03:08:06 1995 ylo |
6ae2364d | 11 | * |
5260325f | 12 | * Rhosts or /etc/hosts.equiv authentication combined with RSA host |
13 | * authentication. | |
14 | * | |
15 | */ | |
8efc0c15 | 16 | |
17 | #include "includes.h" | |
18 | RCSID("$Id$"); | |
19 | ||
4fe2af09 | 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 | ||
8efc0c15 | 31 | #include "packet.h" |
32 | #include "ssh.h" | |
33 | #include "xmalloc.h" | |
34 | #include "uidswap.h" | |
b4748e2f | 35 | #include "servconf.h" |
8efc0c15 | 36 | |
4fe2af09 | 37 | #include "key.h" |
38 | #include "hostfile.h" | |
39 | ||
aa3378df | 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 | */ | |
8efc0c15 | 44 | |
6ae2364d | 45 | int |
4fe2af09 | 46 | auth_rhosts_rsa(struct passwd *pw, const char *client_user, RSA *client_host_key) |
8efc0c15 | 47 | { |
5260325f | 48 | extern ServerOptions options; |
49 | const char *canonical_hostname; | |
50 | HostStatus host_status; | |
4fe2af09 | 51 | Key *client_key, *found; |
5260325f | 52 | |
53 | debug("Trying rhosts with RSA host authentication for %.100s", client_user); | |
54 | ||
4fe2af09 | 55 | if (client_host_key == NULL) |
56 | return 0; | |
57 | ||
5260325f | 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 | ||
4fe2af09 | 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); | |
5260325f | 71 | |
72 | /* Check if we know the host and its host key. */ | |
5260325f | 73 | host_status = check_host_in_hostfile(SSH_SYSTEM_HOSTFILE, canonical_hostname, |
4fe2af09 | 74 | client_key, found); |
5260325f | 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); | |
aa3378df | 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 | */ | |
5260325f | 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, | |
4fe2af09 | 94 | client_key, found); |
5260325f | 95 | restore_uid(); |
96 | } | |
97 | xfree(user_hostfile); | |
98 | } | |
4fe2af09 | 99 | key_free(client_key); |
100 | key_free(found); | |
5260325f | 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. */ | |
4fe2af09 | 110 | if (!auth_rsa_challenge_dialog(client_host_key)) { |
5260325f | 111 | log("Client on %.800s failed to respond correctly to host authentication.", |
112 | canonical_hostname); | |
113 | return 0; | |
114 | } | |
aa3378df | 115 | /* |
116 | * We have authenticated the user using .rhosts or /etc/hosts.equiv, | |
117 | * and the host using RSA. We accept the authentication. | |
118 | */ | |
5260325f | 119 | |
120 | verbose("Rhosts with RSA host authentication accepted for %.100s, %.100s on %.700s.", | |
4fe2af09 | 121 | pw->pw_name, client_user, canonical_hostname); |
5260325f | 122 | packet_send_debug("Rhosts with RSA host authentication accepted."); |
123 | return 1; | |
8efc0c15 | 124 | } |