|
Lines 29-56
RCSID("$OpenBSD: auth1.c,v 1.59 2004/07/
Link Here
|
| 29 |
/* import */ |
29 |
/* import */ |
| 30 |
extern ServerOptions options; |
30 |
extern ServerOptions options; |
| 31 |
|
31 |
|
| 32 |
/* |
32 |
struct Authmethod1 { |
| 33 |
* convert ssh auth msg type into description |
33 |
int type; |
| 34 |
*/ |
34 |
char *name; |
| 35 |
static char * |
35 |
int *enabled; |
| 36 |
get_authname(int type) |
36 |
}; |
|
|
37 |
|
| 38 |
static struct Authmethod1 auth1_methods[] = { |
| 39 |
{ SSH_CMSG_AUTH_PASSWORD, "password", &options.password_authentication }, |
| 40 |
{ SSH_CMSG_AUTH_RSA, "rsa", &options.rsa_authentication }, |
| 41 |
{ SSH_CMSG_AUTH_RHOSTS_RSA, "rhosts-rsa", &options.rhosts_rsa_authentication }, |
| 42 |
{ SSH_CMSG_AUTH_TIS, "challenge-response", &options.challenge_response_authentication }, |
| 43 |
{ SSH_CMSG_AUTH_TIS_RESPONSE, "challenge-response", &options.challenge_response_authentication }, |
| 44 |
{ -1, NULL } |
| 45 |
}; |
| 46 |
|
| 47 |
static struct Authmethod1 * |
| 48 |
get_authmethod1_by_type(int type) |
| 49 |
{ |
| 50 |
int i; |
| 51 |
|
| 52 |
for (i = 0; auth1_methods[i].name != NULL; i++) |
| 53 |
if (auth1_methods[i].type == type) |
| 54 |
return &auth1_methods[i]; |
| 55 |
|
| 56 |
return NULL; |
| 57 |
} |
| 58 |
|
| 59 |
static struct Authmethod1 * |
| 60 |
get_authmethod1_by_name(const char *name) |
| 61 |
{ |
| 62 |
int i; |
| 63 |
|
| 64 |
for (i = 0; auth1_methods[i].name != NULL; i++) |
| 65 |
if (strcmp(auth1_methods[i].name, name) == 0) |
| 66 |
return &auth1_methods[i]; |
| 67 |
|
| 68 |
return NULL; |
| 69 |
} |
| 70 |
|
| 71 |
#define DELIM "," |
| 72 |
int |
| 73 |
auth1_check_required(const char *list) |
| 37 |
{ |
74 |
{ |
| 38 |
static char buf[1024]; |
75 |
char *orig_methods, *methods, *cp; |
| 39 |
switch (type) { |
76 |
struct Authmethod1 *m; |
| 40 |
case SSH_CMSG_AUTH_PASSWORD: |
77 |
int ret = 0; |
| 41 |
return "password"; |
78 |
|
| 42 |
case SSH_CMSG_AUTH_RSA: |
79 |
orig_methods = methods = xstrdup(list); |
| 43 |
return "rsa"; |
80 |
for(;;) { |
| 44 |
case SSH_CMSG_AUTH_RHOSTS_RSA: |
81 |
if ((cp = strsep(&methods, DELIM)) == NULL) |
| 45 |
return "rhosts-rsa"; |
82 |
break; |
| 46 |
case SSH_CMSG_AUTH_RHOSTS: |
83 |
debug2("auth1_check_required: method \"%s\"", cp); |
| 47 |
return "rhosts"; |
84 |
if (*cp == '\0') { |
| 48 |
case SSH_CMSG_AUTH_TIS: |
85 |
debug("auth1_check_required: empty method"); |
| 49 |
case SSH_CMSG_AUTH_TIS_RESPONSE: |
86 |
ret = -1; |
| 50 |
return "challenge-response"; |
87 |
} |
|
|
88 |
if ((m = get_authmethod1_by_name(cp)) == NULL) { |
| 89 |
debug("auth1_check_required: unknown method " |
| 90 |
"\"%s\"", cp); |
| 91 |
ret = -1; |
| 92 |
} |
| 93 |
if (*(m->enabled) == 0) { |
| 94 |
debug("auth1_check_required: method %s explicitly " |
| 95 |
"disabled", cp); |
| 96 |
ret = -1; |
| 97 |
} |
| 98 |
/* Activate method if it isn't already */ |
| 99 |
if (*(m->enabled) == -1) |
| 100 |
*(m->enabled) = 1; |
| 51 |
} |
101 |
} |
| 52 |
snprintf(buf, sizeof buf, "bad-auth-msg-%d", type); |
102 |
xfree(orig_methods); |
| 53 |
return buf; |
103 |
return (ret); |
| 54 |
} |
104 |
} |
| 55 |
|
105 |
|
| 56 |
/* |
106 |
/* |
|
Lines 64-85
do_authloop(Authctxt *authctxt)
Link Here
|
| 64 |
u_int bits; |
114 |
u_int bits; |
| 65 |
Key *client_host_key; |
115 |
Key *client_host_key; |
| 66 |
BIGNUM *n; |
116 |
BIGNUM *n; |
| 67 |
char *client_user, *password; |
117 |
char *client_user, *password, *challenge, *response, meth_name[64]; |
| 68 |
char info[1024]; |
118 |
char info[1024]; |
| 69 |
u_int dlen; |
119 |
u_int dlen; |
| 70 |
u_int ulen; |
120 |
u_int ulen; |
| 71 |
int type = 0; |
121 |
int type = 0; |
|
|
122 |
struct Authmethod1 *meth; |
| 72 |
|
123 |
|
| 73 |
debug("Attempting authentication for %s%.100s.", |
124 |
debug("Attempting authentication for %s%.100s.", |
| 74 |
authctxt->valid ? "" : "invalid user ", authctxt->user); |
125 |
authctxt->valid ? "" : "invalid user ", authctxt->user); |
| 75 |
|
126 |
|
| 76 |
/* If the user has no password, accept authentication immediately. */ |
127 |
/* If the user has no password, accept authentication immediately. */ |
| 77 |
if (options.password_authentication && |
128 |
if (options.required_auth1 == NULL && options.password_authentication && |
| 78 |
#ifdef KRB5 |
129 |
#ifdef KRB5 |
| 79 |
(!options.kerberos_authentication || options.kerberos_or_local_passwd) && |
130 |
(!options.kerberos_authentication || options.kerberos_or_local_passwd) && |
| 80 |
#endif |
131 |
#endif |
| 81 |
PRIVSEP(auth_password(authctxt, ""))) { |
132 |
PRIVSEP(auth_password(authctxt, ""))) { |
| 82 |
auth_log(authctxt, 1, "without authentication", ""); |
133 |
auth_log(authctxt, 1, "without authentication", NULL, ""); |
| 83 |
return; |
134 |
return; |
| 84 |
} |
135 |
} |
| 85 |
|
136 |
|
|
Lines 97-109
do_authloop(Authctxt *authctxt)
Link Here
|
| 97 |
/* Get a packet from the client. */ |
148 |
/* Get a packet from the client. */ |
| 98 |
type = packet_read(); |
149 |
type = packet_read(); |
| 99 |
|
150 |
|
|
|
151 |
/* |
| 152 |
* Any unknown messages will be ignored (and failure |
| 153 |
* returned) during authentication. |
| 154 |
*/ |
| 155 |
if ((meth = get_authmethod1_by_type(type)) == NULL) { |
| 156 |
logit("Unknown message during authentication: type %d", |
| 157 |
type); |
| 158 |
snprintf(meth_name, sizeof meth_name, |
| 159 |
"bad-auth-msg-%d", type); |
| 160 |
goto skip_method; |
| 161 |
} |
| 162 |
strlcpy(meth_name, meth->name, sizeof meth_name); |
| 163 |
|
| 164 |
/* Skip disabled methods */ |
| 165 |
if (!*(meth->enabled)) { |
| 166 |
verbose("%s authentication disabled", meth_name); |
| 167 |
goto skip_method; |
| 168 |
} |
| 169 |
|
| 170 |
/* |
| 171 |
* Skip methods not in required list, until all the required |
| 172 |
* ones are done |
| 173 |
*/ |
| 174 |
if (options.required_auth1 != NULL && |
| 175 |
!auth_method_in_list(options.required_auth1, meth_name)) { |
| 176 |
debug("Skipping method \"%s\" until required " |
| 177 |
"authentication completed", meth_name); |
| 178 |
goto skip_method; |
| 179 |
} |
| 180 |
|
| 100 |
/* Process the packet. */ |
181 |
/* Process the packet. */ |
| 101 |
switch (type) { |
182 |
switch (type) { |
| 102 |
case SSH_CMSG_AUTH_RHOSTS_RSA: |
183 |
case SSH_CMSG_AUTH_RHOSTS_RSA: |
| 103 |
if (!options.rhosts_rsa_authentication) { |
|
|
| 104 |
verbose("Rhosts with RSA authentication disabled."); |
| 105 |
break; |
| 106 |
} |
| 107 |
/* |
184 |
/* |
| 108 |
* Get client user name. Note that we just have to |
185 |
* Get client user name. Note that we just have to |
| 109 |
* trust the client; root on the client machine can |
186 |
* trust the client; root on the client machine can |
|
Lines 132-141
do_authloop(Authctxt *authctxt)
Link Here
|
| 132 |
break; |
209 |
break; |
| 133 |
|
210 |
|
| 134 |
case SSH_CMSG_AUTH_RSA: |
211 |
case SSH_CMSG_AUTH_RSA: |
| 135 |
if (!options.rsa_authentication) { |
|
|
| 136 |
verbose("RSA authentication disabled."); |
| 137 |
break; |
| 138 |
} |
| 139 |
/* RSA authentication requested. */ |
212 |
/* RSA authentication requested. */ |
| 140 |
if ((n = BN_new()) == NULL) |
213 |
if ((n = BN_new()) == NULL) |
| 141 |
fatal("do_authloop: BN_new failed"); |
214 |
fatal("do_authloop: BN_new failed"); |
|
Lines 146-155
do_authloop(Authctxt *authctxt)
Link Here
|
| 146 |
break; |
219 |
break; |
| 147 |
|
220 |
|
| 148 |
case SSH_CMSG_AUTH_PASSWORD: |
221 |
case SSH_CMSG_AUTH_PASSWORD: |
| 149 |
if (!options.password_authentication) { |
|
|
| 150 |
verbose("Password authentication disabled."); |
| 151 |
break; |
| 152 |
} |
| 153 |
/* |
222 |
/* |
| 154 |
* Read user password. It is in plain text, but was |
223 |
* Read user password. It is in plain text, but was |
| 155 |
* transmitted over the encrypted channel so it is |
224 |
* transmitted over the encrypted channel so it is |
|
Lines 167-204
do_authloop(Authctxt *authctxt)
Link Here
|
| 167 |
|
236 |
|
| 168 |
case SSH_CMSG_AUTH_TIS: |
237 |
case SSH_CMSG_AUTH_TIS: |
| 169 |
debug("rcvd SSH_CMSG_AUTH_TIS"); |
238 |
debug("rcvd SSH_CMSG_AUTH_TIS"); |
| 170 |
if (options.challenge_response_authentication == 1) { |
239 |
challenge = get_challenge(authctxt); |
| 171 |
char *challenge = get_challenge(authctxt); |
240 |
if (challenge != NULL) { |
| 172 |
if (challenge != NULL) { |
241 |
debug("sending challenge '%s'", challenge); |
| 173 |
debug("sending challenge '%s'", challenge); |
242 |
packet_start(SSH_SMSG_AUTH_TIS_CHALLENGE); |
| 174 |
packet_start(SSH_SMSG_AUTH_TIS_CHALLENGE); |
243 |
packet_put_cstring(challenge); |
| 175 |
packet_put_cstring(challenge); |
244 |
xfree(challenge); |
| 176 |
xfree(challenge); |
245 |
packet_send(); |
| 177 |
packet_send(); |
246 |
packet_write_wait(); |
| 178 |
packet_write_wait(); |
247 |
continue; |
| 179 |
continue; |
|
|
| 180 |
} |
| 181 |
} |
248 |
} |
| 182 |
break; |
249 |
break; |
| 183 |
case SSH_CMSG_AUTH_TIS_RESPONSE: |
250 |
case SSH_CMSG_AUTH_TIS_RESPONSE: |
| 184 |
debug("rcvd SSH_CMSG_AUTH_TIS_RESPONSE"); |
251 |
debug("rcvd SSH_CMSG_AUTH_TIS_RESPONSE"); |
| 185 |
if (options.challenge_response_authentication == 1) { |
252 |
response = packet_get_string(&dlen); |
| 186 |
char *response = packet_get_string(&dlen); |
253 |
packet_check_eom(); |
| 187 |
packet_check_eom(); |
254 |
authenticated = verify_response(authctxt, response); |
| 188 |
authenticated = verify_response(authctxt, response); |
255 |
memset(response, 'r', dlen); |
| 189 |
memset(response, 'r', dlen); |
256 |
xfree(response); |
| 190 |
xfree(response); |
|
|
| 191 |
} |
| 192 |
break; |
257 |
break; |
| 193 |
|
258 |
|
| 194 |
default: |
259 |
default: |
| 195 |
/* |
260 |
fatal("INTERNAL ERROR: unrecognised method %d", type); |
| 196 |
* Any unknown messages will be ignored (and failure |
|
|
| 197 |
* returned) during authentication. |
| 198 |
*/ |
| 199 |
logit("Unknown message during authentication: type %d", type); |
| 200 |
break; |
| 201 |
} |
261 |
} |
|
|
262 |
skip_method: |
| 202 |
#ifdef BSD_AUTH |
263 |
#ifdef BSD_AUTH |
| 203 |
if (authctxt->as) { |
264 |
if (authctxt->as) { |
| 204 |
auth_close(authctxt->as); |
265 |
auth_close(authctxt->as); |
|
Lines 211-221
do_authloop(Authctxt *authctxt)
Link Here
|
| 211 |
|
272 |
|
| 212 |
/* Special handling for root */ |
273 |
/* Special handling for root */ |
| 213 |
if (authenticated && authctxt->pw->pw_uid == 0 && |
274 |
if (authenticated && authctxt->pw->pw_uid == 0 && |
| 214 |
!auth_root_allowed(get_authname(type))) |
275 |
!auth_root_allowed(meth_name)) |
| 215 |
authenticated = 0; |
276 |
authenticated = 0; |
| 216 |
|
277 |
|
| 217 |
/* Log before sending the reply */ |
278 |
/* Log before sending the reply */ |
| 218 |
auth_log(authctxt, authenticated, get_authname(type), info); |
279 |
auth_log(authctxt, authenticated, meth_name, NULL, info); |
|
|
280 |
|
| 281 |
/* Loop until the required authmethods are done */ |
| 282 |
if (authenticated && options.required_auth1 != NULL) { |
| 283 |
if (auth_remove_from_list(&options.required_auth1, |
| 284 |
meth_name) != 1) |
| 285 |
fatal("INTERNAL ERROR: authenticated method " |
| 286 |
"\"%s\" not in required list \"%s\"", |
| 287 |
meth_name, options.required_auth1); |
| 288 |
debug2("do_authloop: required list now: %s", |
| 289 |
options.required_auth1 == NULL ? |
| 290 |
"DONE" : options.required_auth1); |
| 291 |
authenticated = 0; |
| 292 |
/* |
| 293 |
* Disable method so client can't authenticate with it |
| 294 |
* after the required authentications are complete. |
| 295 |
*/ |
| 296 |
*(meth->enabled) = 0; |
| 297 |
packet_send_debug("Further authentication required"); |
| 298 |
goto send_fail; |
| 299 |
} |
| 219 |
|
300 |
|
| 220 |
if (authenticated) |
301 |
if (authenticated) |
| 221 |
return; |
302 |
return; |
|
Lines 223-228
do_authloop(Authctxt *authctxt)
Link Here
|
| 223 |
if (authctxt->failures++ > options.max_authtries) |
304 |
if (authctxt->failures++ > options.max_authtries) |
| 224 |
packet_disconnect(AUTH_FAIL_MSG, authctxt->user); |
305 |
packet_disconnect(AUTH_FAIL_MSG, authctxt->user); |
| 225 |
|
306 |
|
|
|
307 |
send_fail: |
| 226 |
packet_start(SSH_SMSG_FAILURE); |
308 |
packet_start(SSH_SMSG_FAILURE); |
| 227 |
packet_send(); |
309 |
packet_send(); |
| 228 |
packet_write_wait(); |
310 |
packet_write_wait(); |