/*
- *
- * auth-rsa.c
- *
* Author: Tatu Ylonen <ylo@cs.hut.fi>
- *
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
- *
- * Created: Mon Mar 27 01:46:52 1995 ylo
- *
* RSA-based authentication. This code determines whether to admit a login
* based on RSA authentication. This file also contains functions to check
* validity of the host key.
*
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose. Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
*/
#include "includes.h"
-RCSID("$OpenBSD: auth-rsa.c,v 1.26 2000/06/20 01:39:38 markus Exp $");
+RCSID("$OpenBSD: auth-rsa.c,v 1.38 2001/01/21 19:05:42 markus Exp $");
+
+#include <openssl/rsa.h>
+#include <openssl/md5.h>
#include "rsa.h"
#include "packet.h"
#include "xmalloc.h"
-#include "ssh.h"
+#include "ssh1.h"
#include "mpaux.h"
#include "uidswap.h"
#include "match.h"
-#include "servconf.h"
#include "auth-options.h"
+#include "pathnames.h"
+#include "log.h"
+#include "servconf.h"
+#include "auth.h"
-#include <openssl/rsa.h>
-#include <openssl/md5.h>
+/* import */
+extern ServerOptions options;
/*
* Session identifier that is used to bind key exchange and authentication
* responses to a particular session.
*/
-extern unsigned char session_id[16];
+extern u_char session_id[16];
/*
* The .ssh/authorized_keys file contains public keys, one per line, in the
{
BIGNUM *challenge, *encrypted_challenge;
BN_CTX *ctx;
- unsigned char buf[32], mdbuf[16], response[16];
+ u_char buf[32], mdbuf[16], response[16];
MD5_CTX md;
- unsigned int i;
+ u_int i;
int plen, len;
encrypted_challenge = BN_new();
int
auth_rsa(struct passwd *pw, BIGNUM *client_n)
{
- extern ServerOptions options;
- char line[8192], file[1024];
+ char line[8192], file[MAXPATHLEN];
int authenticated;
- unsigned int bits;
+ u_int bits;
FILE *f;
- unsigned long linenum = 0;
+ u_long linenum = 0;
struct stat st;
RSA *pk;
+ /* no user given */
+ if (pw == NULL)
+ return 0;
+
/* Temporarily use the user's uid. */
temporarily_use_uid(pw->pw_uid);
/* The authorized keys. */
snprintf(file, sizeof file, "%.500s/%.100s", pw->pw_dir,
- SSH_USER_PERMITTED_KEYS);
+ _PATH_SSH_USER_PERMITTED_KEYS);
/* Fail quietly if file does not exist */
if (stat(file, &st) < 0) {
"bad ownership or modes for '%s'.", pw->pw_name, file);
fail = 1;
} else {
- /* Check path to SSH_USER_PERMITTED_KEYS */
+ /* Check path to _PATH_SSH_USER_PERMITTED_KEYS */
int i;
static const char *check[] = {
- "", SSH_USER_DIR, NULL
+ "", _PATH_SSH_USER_DIR, NULL
};
for (i = 0; check[i]; i++) {
snprintf(line, sizeof line, "%.500s/%.100s", pw->pw_dir, check[i]);
}
if (fail) {
fclose(f);
- log(buf);
- packet_send_debug(buf);
+ log("%s",buf);
+ packet_send_debug("%s",buf);
restore_uid();
return 0;
}
/* Parse the key from the line. */
if (!auth_rsa_read_key(&cp, &bits, pk->e, pk->n)) {
debug("%.100s, line %lu: bad key syntax",
- SSH_USER_PERMITTED_KEYS, linenum);
+ file, linenum);
packet_send_debug("%.100s, line %lu: bad key syntax",
- SSH_USER_PERMITTED_KEYS, linenum);
+ file, linenum);
continue;
}
/* cp now points to the comment part. */
file, linenum, BN_num_bits(pk->n), bits);
/* We have found the desired key. */
+ /*
+ * If our options do not allow this key to be used,
+ * do not send challenge.
+ */
+ if (!auth_parse_options(pw, options, file, linenum))
+ continue;
/* Perform the challenge-response dialog for this key. */
if (!auth_rsa_challenge_dialog(pk)) {
* Break out of the loop if authentication was successful;
* otherwise continue searching.
*/
- authenticated = auth_parse_options(pw, options, linenum);
- if (authenticated)
- break;
+ authenticated = 1;
+ break;
}
/* Restore the privileged uid. */
if (authenticated)
packet_send_debug("RSA authentication accepted.");
+ else
+ auth_clear_options();
/* Return authentication result. */
return authenticated;