xref: /titanic_50/usr/src/cmd/ssh/sshd/auth-rsa.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
3*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4*7c478bd9Sstevel@tonic-gate  *                    All rights reserved
5*7c478bd9Sstevel@tonic-gate  * RSA-based authentication.  This code determines whether to admit a login
6*7c478bd9Sstevel@tonic-gate  * based on RSA authentication.  This file also contains functions to check
7*7c478bd9Sstevel@tonic-gate  * validity of the host key.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
10*7c478bd9Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
11*7c478bd9Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
12*7c478bd9Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
13*7c478bd9Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
14*7c478bd9Sstevel@tonic-gate  */
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #include "includes.h"
17*7c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth-rsa.c,v 1.56 2002/06/10 16:53:06 stevesk Exp $");
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate #include <openssl/rsa.h>
22*7c478bd9Sstevel@tonic-gate #include <openssl/md5.h>
23*7c478bd9Sstevel@tonic-gate 
24*7c478bd9Sstevel@tonic-gate #include "rsa.h"
25*7c478bd9Sstevel@tonic-gate #include "packet.h"
26*7c478bd9Sstevel@tonic-gate #include "xmalloc.h"
27*7c478bd9Sstevel@tonic-gate #include "ssh1.h"
28*7c478bd9Sstevel@tonic-gate #include "mpaux.h"
29*7c478bd9Sstevel@tonic-gate #include "uidswap.h"
30*7c478bd9Sstevel@tonic-gate #include "match.h"
31*7c478bd9Sstevel@tonic-gate #include "auth-options.h"
32*7c478bd9Sstevel@tonic-gate #include "pathnames.h"
33*7c478bd9Sstevel@tonic-gate #include "log.h"
34*7c478bd9Sstevel@tonic-gate #include "servconf.h"
35*7c478bd9Sstevel@tonic-gate #include "auth.h"
36*7c478bd9Sstevel@tonic-gate #include "hostfile.h"
37*7c478bd9Sstevel@tonic-gate #include "monitor_wrap.h"
38*7c478bd9Sstevel@tonic-gate #include "ssh.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /* import */
41*7c478bd9Sstevel@tonic-gate extern ServerOptions options;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * Session identifier that is used to bind key exchange and authentication
45*7c478bd9Sstevel@tonic-gate  * responses to a particular session.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate extern u_char session_id[16];
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * The .ssh/authorized_keys file contains public keys, one per line, in the
51*7c478bd9Sstevel@tonic-gate  * following format:
52*7c478bd9Sstevel@tonic-gate  *   options bits e n comment
53*7c478bd9Sstevel@tonic-gate  * where bits, e and n are decimal numbers,
54*7c478bd9Sstevel@tonic-gate  * and comment is any string of characters up to newline.  The maximum
55*7c478bd9Sstevel@tonic-gate  * length of a line is 8000 characters.  See the documentation for a
56*7c478bd9Sstevel@tonic-gate  * description of the options.
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate BIGNUM *
60*7c478bd9Sstevel@tonic-gate auth_rsa_generate_challenge(Key *key)
61*7c478bd9Sstevel@tonic-gate {
62*7c478bd9Sstevel@tonic-gate 	BIGNUM *challenge;
63*7c478bd9Sstevel@tonic-gate 	BN_CTX *ctx;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	if ((challenge = BN_new()) == NULL)
66*7c478bd9Sstevel@tonic-gate 		fatal("auth_rsa_generate_challenge: BN_new() failed");
67*7c478bd9Sstevel@tonic-gate 	/* Generate a random challenge. */
68*7c478bd9Sstevel@tonic-gate 	BN_rand(challenge, 256, 0, 0);
69*7c478bd9Sstevel@tonic-gate 	if ((ctx = BN_CTX_new()) == NULL)
70*7c478bd9Sstevel@tonic-gate 		fatal("auth_rsa_generate_challenge: BN_CTX_new() failed");
71*7c478bd9Sstevel@tonic-gate 	BN_mod(challenge, challenge, key->rsa->n, ctx);
72*7c478bd9Sstevel@tonic-gate 	BN_CTX_free(ctx);
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	return challenge;
75*7c478bd9Sstevel@tonic-gate }
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate int
78*7c478bd9Sstevel@tonic-gate auth_rsa_verify_response(Key *key, BIGNUM *challenge, u_char response[16])
79*7c478bd9Sstevel@tonic-gate {
80*7c478bd9Sstevel@tonic-gate 	u_char buf[32], mdbuf[16];
81*7c478bd9Sstevel@tonic-gate 	MD5_CTX md;
82*7c478bd9Sstevel@tonic-gate 	int len;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	/* don't allow short keys */
85*7c478bd9Sstevel@tonic-gate 	if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
86*7c478bd9Sstevel@tonic-gate 		error("auth_rsa_verify_response: RSA modulus too small: %d < minimum %d bits",
87*7c478bd9Sstevel@tonic-gate 		    BN_num_bits(key->rsa->n), SSH_RSA_MINIMUM_MODULUS_SIZE);
88*7c478bd9Sstevel@tonic-gate 		return (0);
89*7c478bd9Sstevel@tonic-gate 	}
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 	/* The response is MD5 of decrypted challenge plus session id. */
92*7c478bd9Sstevel@tonic-gate 	len = BN_num_bytes(challenge);
93*7c478bd9Sstevel@tonic-gate 	if (len <= 0 || len > 32)
94*7c478bd9Sstevel@tonic-gate 		fatal("auth_rsa_verify_response: bad challenge length %d", len);
95*7c478bd9Sstevel@tonic-gate 	memset(buf, 0, 32);
96*7c478bd9Sstevel@tonic-gate 	BN_bn2bin(challenge, buf + 32 - len);
97*7c478bd9Sstevel@tonic-gate 	MD5_Init(&md);
98*7c478bd9Sstevel@tonic-gate 	MD5_Update(&md, buf, 32);
99*7c478bd9Sstevel@tonic-gate 	MD5_Update(&md, session_id, 16);
100*7c478bd9Sstevel@tonic-gate 	MD5_Final(mdbuf, &md);
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/* Verify that the response is the original challenge. */
103*7c478bd9Sstevel@tonic-gate 	if (memcmp(response, mdbuf, 16) != 0) {
104*7c478bd9Sstevel@tonic-gate 		/* Wrong answer. */
105*7c478bd9Sstevel@tonic-gate 		return (0);
106*7c478bd9Sstevel@tonic-gate 	}
107*7c478bd9Sstevel@tonic-gate 	/* Correct answer. */
108*7c478bd9Sstevel@tonic-gate 	return (1);
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate /*
112*7c478bd9Sstevel@tonic-gate  * Performs the RSA authentication challenge-response dialog with the client,
113*7c478bd9Sstevel@tonic-gate  * and returns true (non-zero) if the client gave the correct answer to
114*7c478bd9Sstevel@tonic-gate  * our challenge; returns zero if the client gives a wrong answer.
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate int
118*7c478bd9Sstevel@tonic-gate auth_rsa_challenge_dialog(Key *key)
119*7c478bd9Sstevel@tonic-gate {
120*7c478bd9Sstevel@tonic-gate 	BIGNUM *challenge, *encrypted_challenge;
121*7c478bd9Sstevel@tonic-gate 	u_char response[16];
122*7c478bd9Sstevel@tonic-gate 	int i, success;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	if ((encrypted_challenge = BN_new()) == NULL)
125*7c478bd9Sstevel@tonic-gate 		fatal("auth_rsa_challenge_dialog: BN_new() failed");
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	challenge = PRIVSEP(auth_rsa_generate_challenge(key));
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	/* Encrypt the challenge with the public key. */
130*7c478bd9Sstevel@tonic-gate 	rsa_public_encrypt(encrypted_challenge, challenge, key->rsa);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	/* Send the encrypted challenge to the client. */
133*7c478bd9Sstevel@tonic-gate 	packet_start(SSH_SMSG_AUTH_RSA_CHALLENGE);
134*7c478bd9Sstevel@tonic-gate 	packet_put_bignum(encrypted_challenge);
135*7c478bd9Sstevel@tonic-gate 	packet_send();
136*7c478bd9Sstevel@tonic-gate 	BN_clear_free(encrypted_challenge);
137*7c478bd9Sstevel@tonic-gate 	packet_write_wait();
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	/* Wait for a response. */
140*7c478bd9Sstevel@tonic-gate 	packet_read_expect(SSH_CMSG_AUTH_RSA_RESPONSE);
141*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 16; i++)
142*7c478bd9Sstevel@tonic-gate 		response[i] = packet_get_char();
143*7c478bd9Sstevel@tonic-gate 	packet_check_eom();
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	success = PRIVSEP(auth_rsa_verify_response(key, challenge, response));
146*7c478bd9Sstevel@tonic-gate 	BN_clear_free(challenge);
147*7c478bd9Sstevel@tonic-gate 	return (success);
148*7c478bd9Sstevel@tonic-gate }
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate /*
151*7c478bd9Sstevel@tonic-gate  * check if there's user key matching client_n,
152*7c478bd9Sstevel@tonic-gate  * return key if login is allowed, NULL otherwise
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate int
156*7c478bd9Sstevel@tonic-gate auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey)
157*7c478bd9Sstevel@tonic-gate {
158*7c478bd9Sstevel@tonic-gate 	char line[8192], *file;
159*7c478bd9Sstevel@tonic-gate 	int allowed = 0;
160*7c478bd9Sstevel@tonic-gate 	u_int bits;
161*7c478bd9Sstevel@tonic-gate 	FILE *f;
162*7c478bd9Sstevel@tonic-gate 	u_long linenum = 0;
163*7c478bd9Sstevel@tonic-gate 	struct stat st;
164*7c478bd9Sstevel@tonic-gate 	Key *key;
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	/* Temporarily use the user's uid. */
167*7c478bd9Sstevel@tonic-gate 	temporarily_use_uid(pw);
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 	/* The authorized keys. */
170*7c478bd9Sstevel@tonic-gate 	file = authorized_keys_file(pw);
171*7c478bd9Sstevel@tonic-gate 	debug("trying public RSA key file %s", file);
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 	/* Fail quietly if file does not exist */
174*7c478bd9Sstevel@tonic-gate 	if (stat(file, &st) < 0) {
175*7c478bd9Sstevel@tonic-gate 		/* Restore the privileged uid. */
176*7c478bd9Sstevel@tonic-gate 		restore_uid();
177*7c478bd9Sstevel@tonic-gate 		xfree(file);
178*7c478bd9Sstevel@tonic-gate 		return (0);
179*7c478bd9Sstevel@tonic-gate 	}
180*7c478bd9Sstevel@tonic-gate 	/* Open the file containing the authorized keys. */
181*7c478bd9Sstevel@tonic-gate 	f = fopen(file, "r");
182*7c478bd9Sstevel@tonic-gate 	if (!f) {
183*7c478bd9Sstevel@tonic-gate 		/* Restore the privileged uid. */
184*7c478bd9Sstevel@tonic-gate 		restore_uid();
185*7c478bd9Sstevel@tonic-gate 		xfree(file);
186*7c478bd9Sstevel@tonic-gate 		return (0);
187*7c478bd9Sstevel@tonic-gate 	}
188*7c478bd9Sstevel@tonic-gate 	if (options.strict_modes &&
189*7c478bd9Sstevel@tonic-gate 	    secure_filename(f, file, pw, line, sizeof(line)) != 0) {
190*7c478bd9Sstevel@tonic-gate 		xfree(file);
191*7c478bd9Sstevel@tonic-gate 		fclose(f);
192*7c478bd9Sstevel@tonic-gate 		log("Authentication refused: %s", line);
193*7c478bd9Sstevel@tonic-gate 		restore_uid();
194*7c478bd9Sstevel@tonic-gate 		return (0);
195*7c478bd9Sstevel@tonic-gate 	}
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	/* Flag indicating whether the key is allowed. */
198*7c478bd9Sstevel@tonic-gate 	allowed = 0;
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 	key = key_new(KEY_RSA1);
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 	/*
203*7c478bd9Sstevel@tonic-gate 	 * Go though the accepted keys, looking for the current key.  If
204*7c478bd9Sstevel@tonic-gate 	 * found, perform a challenge-response dialog to verify that the
205*7c478bd9Sstevel@tonic-gate 	 * user really has the corresponding private key.
206*7c478bd9Sstevel@tonic-gate 	 */
207*7c478bd9Sstevel@tonic-gate 	while (fgets(line, sizeof(line), f)) {
208*7c478bd9Sstevel@tonic-gate 		char *cp;
209*7c478bd9Sstevel@tonic-gate 		char *options;
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 		linenum++;
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate 		/* Skip leading whitespace, empty and comment lines. */
214*7c478bd9Sstevel@tonic-gate 		for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
215*7c478bd9Sstevel@tonic-gate 			;
216*7c478bd9Sstevel@tonic-gate 		if (!*cp || *cp == '\n' || *cp == '#')
217*7c478bd9Sstevel@tonic-gate 			continue;
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 		/*
220*7c478bd9Sstevel@tonic-gate 		 * Check if there are options for this key, and if so,
221*7c478bd9Sstevel@tonic-gate 		 * save their starting address and skip the option part
222*7c478bd9Sstevel@tonic-gate 		 * for now.  If there are no options, set the starting
223*7c478bd9Sstevel@tonic-gate 		 * address to NULL.
224*7c478bd9Sstevel@tonic-gate 		 */
225*7c478bd9Sstevel@tonic-gate 		if (*cp < '0' || *cp > '9') {
226*7c478bd9Sstevel@tonic-gate 			int quoted = 0;
227*7c478bd9Sstevel@tonic-gate 			options = cp;
228*7c478bd9Sstevel@tonic-gate 			for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
229*7c478bd9Sstevel@tonic-gate 				if (*cp == '\\' && cp[1] == '"')
230*7c478bd9Sstevel@tonic-gate 					cp++;	/* Skip both */
231*7c478bd9Sstevel@tonic-gate 				else if (*cp == '"')
232*7c478bd9Sstevel@tonic-gate 					quoted = !quoted;
233*7c478bd9Sstevel@tonic-gate 			}
234*7c478bd9Sstevel@tonic-gate 		} else
235*7c478bd9Sstevel@tonic-gate 			options = NULL;
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 		/* Parse the key from the line. */
238*7c478bd9Sstevel@tonic-gate 		if (hostfile_read_key(&cp, &bits, key) == 0) {
239*7c478bd9Sstevel@tonic-gate 			debug("%.100s, line %lu: non ssh1 key syntax",
240*7c478bd9Sstevel@tonic-gate 			    file, linenum);
241*7c478bd9Sstevel@tonic-gate 			continue;
242*7c478bd9Sstevel@tonic-gate 		}
243*7c478bd9Sstevel@tonic-gate 		/* cp now points to the comment part. */
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 		/* Check if the we have found the desired key (identified by its modulus). */
246*7c478bd9Sstevel@tonic-gate 		if (BN_cmp(key->rsa->n, client_n) != 0)
247*7c478bd9Sstevel@tonic-gate 			continue;
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate 		/* check the real bits  */
250*7c478bd9Sstevel@tonic-gate 		if (bits != BN_num_bits(key->rsa->n))
251*7c478bd9Sstevel@tonic-gate 			log("Warning: %s, line %lu: keysize mismatch: "
252*7c478bd9Sstevel@tonic-gate 			    "actual %d vs. announced %d.",
253*7c478bd9Sstevel@tonic-gate 			    file, linenum, BN_num_bits(key->rsa->n), bits);
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 		/* We have found the desired key. */
256*7c478bd9Sstevel@tonic-gate 		/*
257*7c478bd9Sstevel@tonic-gate 		 * If our options do not allow this key to be used,
258*7c478bd9Sstevel@tonic-gate 		 * do not send challenge.
259*7c478bd9Sstevel@tonic-gate 		 */
260*7c478bd9Sstevel@tonic-gate 		if (!auth_parse_options(pw, options, file, linenum))
261*7c478bd9Sstevel@tonic-gate 			continue;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 		/* break out, this key is allowed */
264*7c478bd9Sstevel@tonic-gate 		allowed = 1;
265*7c478bd9Sstevel@tonic-gate 		break;
266*7c478bd9Sstevel@tonic-gate 	}
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	/* Restore the privileged uid. */
269*7c478bd9Sstevel@tonic-gate 	restore_uid();
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 	/* Close the file. */
272*7c478bd9Sstevel@tonic-gate 	xfree(file);
273*7c478bd9Sstevel@tonic-gate 	fclose(f);
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 	/* return key if allowed */
276*7c478bd9Sstevel@tonic-gate 	if (allowed && rkey != NULL)
277*7c478bd9Sstevel@tonic-gate 		*rkey = key;
278*7c478bd9Sstevel@tonic-gate 	else
279*7c478bd9Sstevel@tonic-gate 		key_free(key);
280*7c478bd9Sstevel@tonic-gate 	return (allowed);
281*7c478bd9Sstevel@tonic-gate }
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate /*
284*7c478bd9Sstevel@tonic-gate  * Performs the RSA authentication dialog with the client.  This returns
285*7c478bd9Sstevel@tonic-gate  * 0 if the client could not be authenticated, and 1 if authentication was
286*7c478bd9Sstevel@tonic-gate  * successful.  This may exit if there is a serious protocol violation.
287*7c478bd9Sstevel@tonic-gate  */
288*7c478bd9Sstevel@tonic-gate int
289*7c478bd9Sstevel@tonic-gate auth_rsa(struct passwd *pw, BIGNUM *client_n)
290*7c478bd9Sstevel@tonic-gate {
291*7c478bd9Sstevel@tonic-gate 	Key *key;
292*7c478bd9Sstevel@tonic-gate 	char *fp;
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate 	/* no user given */
295*7c478bd9Sstevel@tonic-gate 	if (pw == NULL)
296*7c478bd9Sstevel@tonic-gate 		return 0;
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 	if (!PRIVSEP(auth_rsa_key_allowed(pw, client_n, &key))) {
299*7c478bd9Sstevel@tonic-gate 		auth_clear_options();
300*7c478bd9Sstevel@tonic-gate 		return (0);
301*7c478bd9Sstevel@tonic-gate 	}
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	/* Perform the challenge-response dialog for this key. */
304*7c478bd9Sstevel@tonic-gate 	if (!auth_rsa_challenge_dialog(key)) {
305*7c478bd9Sstevel@tonic-gate 		/* Wrong response. */
306*7c478bd9Sstevel@tonic-gate 		verbose("Wrong response to RSA authentication challenge.");
307*7c478bd9Sstevel@tonic-gate 		packet_send_debug("Wrong response to RSA authentication challenge.");
308*7c478bd9Sstevel@tonic-gate 		/*
309*7c478bd9Sstevel@tonic-gate 		 * Break out of the loop. Otherwise we might send
310*7c478bd9Sstevel@tonic-gate 		 * another challenge and break the protocol.
311*7c478bd9Sstevel@tonic-gate 		 */
312*7c478bd9Sstevel@tonic-gate 		key_free(key);
313*7c478bd9Sstevel@tonic-gate 		return (0);
314*7c478bd9Sstevel@tonic-gate 	}
315*7c478bd9Sstevel@tonic-gate 	/*
316*7c478bd9Sstevel@tonic-gate 	 * Correct response.  The client has been successfully
317*7c478bd9Sstevel@tonic-gate 	 * authenticated. Note that we have not yet processed the
318*7c478bd9Sstevel@tonic-gate 	 * options; this will be reset if the options cause the
319*7c478bd9Sstevel@tonic-gate 	 * authentication to be rejected.
320*7c478bd9Sstevel@tonic-gate 	 */
321*7c478bd9Sstevel@tonic-gate 	fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
322*7c478bd9Sstevel@tonic-gate 	verbose("Found matching %s key: %s",
323*7c478bd9Sstevel@tonic-gate 	    key_type(key), fp);
324*7c478bd9Sstevel@tonic-gate 	xfree(fp);
325*7c478bd9Sstevel@tonic-gate 	key_free(key);
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 	packet_send_debug("RSA authentication accepted.");
328*7c478bd9Sstevel@tonic-gate 	return (1);
329*7c478bd9Sstevel@tonic-gate }
330