auth-rsa.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
* 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.56 2002/06/10 16:53:06 stevesk Exp $");
#pragma ident "%Z%%M% %I% %E% SMI"
#include "rsa.h"
#include "packet.h"
#include "xmalloc.h"
#include "ssh1.h"
#include "mpaux.h"
#include "uidswap.h"
#include "match.h"
#include "auth-options.h"
#include "pathnames.h"
#include "log.h"
#include "servconf.h"
#include "auth.h"
#include "hostfile.h"
#include "monitor_wrap.h"
#include "ssh.h"
/* import */
extern ServerOptions options;
/*
* Session identifier that is used to bind key exchange and authentication
* responses to a particular session.
*/
/*
* The .ssh/authorized_keys file contains public keys, one per line, in the
* following format:
* options bits e n comment
* where bits, e and n are decimal numbers,
* and comment is any string of characters up to newline. The maximum
* length of a line is 8000 characters. See the documentation for a
* description of the options.
*/
BIGNUM *
{
fatal("auth_rsa_generate_challenge: BN_new() failed");
/* Generate a random challenge. */
fatal("auth_rsa_generate_challenge: BN_CTX_new() failed");
return challenge;
}
int
{
int len;
/* don't allow short keys */
error("auth_rsa_verify_response: RSA modulus too small: %d < minimum %d bits",
return (0);
}
/* The response is MD5 of decrypted challenge plus session id. */
/* Verify that the response is the original challenge. */
/* Wrong answer. */
return (0);
}
/* Correct answer. */
return (1);
}
/*
* Performs the RSA authentication challenge-response dialog with the client,
* and returns true (non-zero) if the client gave the correct answer to
* our challenge; returns zero if the client gives a wrong answer.
*/
int
{
int i, success;
fatal("auth_rsa_challenge_dialog: BN_new() failed");
/* Encrypt the challenge with the public key. */
/* Send the encrypted challenge to the client. */
packet_send();
/* Wait for a response. */
for (i = 0; i < 16; i++)
response[i] = packet_get_char();
return (success);
}
/*
* check if there's user key matching client_n,
* return key if login is allowed, NULL otherwise
*/
int
{
int allowed = 0;
FILE *f;
/* Temporarily use the user's uid. */
/* The authorized keys. */
/* Fail quietly if file does not exist */
/* Restore the privileged uid. */
restore_uid();
return (0);
}
/* Open the file containing the authorized keys. */
if (!f) {
/* Restore the privileged uid. */
restore_uid();
return (0);
}
if (options.strict_modes &&
fclose(f);
restore_uid();
return (0);
}
/* Flag indicating whether the key is allowed. */
allowed = 0;
/*
* Go though the accepted keys, looking for the current key. If
* found, perform a challenge-response dialog to verify that the
* user really has the corresponding private key.
*/
char *cp;
char *options;
linenum++;
/* Skip leading whitespace, empty and comment lines. */
;
continue;
/*
* Check if there are options for this key, and if so,
* save their starting address and skip the option part
* for now. If there are no options, set the starting
* address to NULL.
*/
int quoted = 0;
cp++; /* Skip both */
else if (*cp == '"')
}
} else
/* Parse the key from the line. */
debug("%.100s, line %lu: non ssh1 key syntax",
continue;
}
/* cp now points to the comment part. */
/* Check if the we have found the desired key (identified by its modulus). */
continue;
/* check the real bits */
log("Warning: %s, line %lu: keysize mismatch: "
"actual %d vs. announced %d.",
/* We have found the desired key. */
/*
* If our options do not allow this key to be used,
* do not send challenge.
*/
continue;
/* break out, this key is allowed */
allowed = 1;
break;
}
/* Restore the privileged uid. */
restore_uid();
/* Close the file. */
fclose(f);
/* return key if allowed */
else
return (allowed);
}
/*
* Performs the RSA authentication dialog with the client. This returns
* 0 if the client could not be authenticated, and 1 if authentication was
* successful. This may exit if there is a serious protocol violation.
*/
int
{
char *fp;
/* no user given */
return 0;
return (0);
}
/* Perform the challenge-response dialog for this key. */
if (!auth_rsa_challenge_dialog(key)) {
/* Wrong response. */
verbose("Wrong response to RSA authentication challenge.");
packet_send_debug("Wrong response to RSA authentication challenge.");
/*
* Break out of the loop. Otherwise we might send
* another challenge and break the protocol.
*/
return (0);
}
/*
* Correct response. The client has been successfully
* authenticated. Note that we have not yet processed the
* options; this will be reset if the options cause the
* authentication to be rejected.
*/
verbose("Found matching %s key: %s",
packet_send_debug("RSA authentication accepted.");
return (1);
}