2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * Code to connect to a remote host, and to perform the client side of the
6 * login (authentication) dialog.
8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
16 RCSID("$OpenBSD: sshconnect1.c,v 1.55 2003/08/13 08:46:31 markus Exp $");
18 #include <openssl/bn.h>
19 #include <openssl/md5.h>
37 #include "sshconnect.h"
44 /* Session id for the current session. */
45 u_char session_id[16];
46 u_int supported_authentications = 0;
48 extern Options options;
49 extern char *__progname;
52 * Checks if the user has an authentication agent, and if so, tries to
53 * authenticate using the agent.
56 try_agent_authentication(void)
60 AuthenticationConnection *auth;
66 /* Get connection to the agent. */
67 auth = ssh_get_authentication_connection();
71 if ((challenge = BN_new()) == NULL)
72 fatal("try_agent_authentication: BN_new failed");
73 /* Loop through identities served by the agent. */
74 for (key = ssh_get_first_identity(auth, &comment, 1);
76 key = ssh_get_next_identity(auth, &comment, 1)) {
78 /* Try this identity. */
79 debug("Trying RSA authentication via agent with '%.100s'", comment);
82 /* Tell the server that we are willing to authenticate using this key. */
83 packet_start(SSH_CMSG_AUTH_RSA);
84 packet_put_bignum(key->rsa->n);
88 /* Wait for server's response. */
91 /* The server sends failure if it doesn\'t like our key or
92 does not support RSA authentication. */
93 if (type == SSH_SMSG_FAILURE) {
94 debug("Server refused our key.");
98 /* Otherwise it should have sent a challenge. */
99 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
100 packet_disconnect("Protocol error during RSA authentication: %d",
103 packet_get_bignum(challenge);
106 debug("Received RSA challenge from server.");
108 /* Ask the agent to decrypt the challenge. */
109 if (!ssh_decrypt_challenge(auth, key, challenge, session_id, 1, response)) {
111 * The agent failed to authenticate this identifier
112 * although it advertised it supports this. Just
113 * return a wrong value.
115 logit("Authentication agent failed to decrypt challenge.");
116 memset(response, 0, sizeof(response));
119 debug("Sending response to RSA challenge.");
121 /* Send the decrypted challenge back to the server. */
122 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
123 for (i = 0; i < 16; i++)
124 packet_put_char(response[i]);
128 /* Wait for response from the server. */
129 type = packet_read();
131 /* The server returns success if it accepted the authentication. */
132 if (type == SSH_SMSG_SUCCESS) {
133 ssh_close_authentication_connection(auth);
134 BN_clear_free(challenge);
135 debug("RSA authentication accepted by server.");
138 /* Otherwise it should return failure. */
139 if (type != SSH_SMSG_FAILURE)
140 packet_disconnect("Protocol error waiting RSA auth response: %d",
143 ssh_close_authentication_connection(auth);
144 BN_clear_free(challenge);
145 debug("RSA authentication using agent refused.");
150 * Computes the proper response to a RSA challenge, and sends the response to
154 respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv)
156 u_char buf[32], response[16];
160 /* Decrypt the challenge using the private key. */
161 /* XXX think about Bleichenbacher, too */
162 if (rsa_private_decrypt(challenge, challenge, prv) <= 0)
164 "respond_to_rsa_challenge: rsa_private_decrypt failed");
166 /* Compute the response. */
167 /* The response is MD5 of decrypted challenge plus session id. */
168 len = BN_num_bytes(challenge);
169 if (len <= 0 || len > sizeof(buf))
171 "respond_to_rsa_challenge: bad challenge length %d", len);
173 memset(buf, 0, sizeof(buf));
174 BN_bn2bin(challenge, buf + sizeof(buf) - len);
176 MD5_Update(&md, buf, 32);
177 MD5_Update(&md, session_id, 16);
178 MD5_Final(response, &md);
180 debug("Sending response to host key RSA challenge.");
182 /* Send the response back to the server. */
183 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
184 for (i = 0; i < 16; i++)
185 packet_put_char(response[i]);
189 memset(buf, 0, sizeof(buf));
190 memset(response, 0, sizeof(response));
191 memset(&md, 0, sizeof(md));
195 * Checks if the user has authentication file, and if so, tries to authenticate
199 try_rsa_authentication(int idx)
202 Key *public, *private;
203 char buf[300], *passphrase, *comment, *authfile;
206 public = options.identity_keys[idx];
207 authfile = options.identity_files[idx];
208 comment = xstrdup(authfile);
210 debug("Trying RSA authentication with key '%.100s'", comment);
212 /* Tell the server that we are willing to authenticate using this key. */
213 packet_start(SSH_CMSG_AUTH_RSA);
214 packet_put_bignum(public->rsa->n);
218 /* Wait for server's response. */
219 type = packet_read();
222 * The server responds with failure if it doesn\'t like our key or
223 * doesn\'t support RSA authentication.
225 if (type == SSH_SMSG_FAILURE) {
226 debug("Server refused our key.");
230 /* Otherwise, the server should respond with a challenge. */
231 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
232 packet_disconnect("Protocol error during RSA authentication: %d", type);
234 /* Get the challenge from the packet. */
235 if ((challenge = BN_new()) == NULL)
236 fatal("try_rsa_authentication: BN_new failed");
237 packet_get_bignum(challenge);
240 debug("Received RSA challenge from server.");
243 * If the key is not stored in external hardware, we have to
244 * load the private key. Try first with empty passphrase; if it
245 * fails, ask for a passphrase.
247 if (public->flags & KEY_FLAG_EXT)
250 private = key_load_private_type(KEY_RSA1, authfile, "", NULL);
251 if (private == NULL && !options.batch_mode) {
252 snprintf(buf, sizeof(buf),
253 "Enter passphrase for RSA key '%.100s': ", comment);
254 for (i = 0; i < options.number_of_password_prompts; i++) {
255 passphrase = read_passphrase(buf, 0);
256 if (strcmp(passphrase, "") != 0) {
257 private = key_load_private_type(KEY_RSA1,
258 authfile, passphrase, NULL);
261 debug2("no passphrase given, try next key");
264 memset(passphrase, 0, strlen(passphrase));
266 if (private != NULL || quit)
268 debug2("bad passphrase given, try again...");
271 /* We no longer need the comment. */
274 if (private == NULL) {
275 if (!options.batch_mode)
276 error("Bad passphrase.");
278 /* Send a dummy response packet to avoid protocol error. */
279 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
280 for (i = 0; i < 16; i++)
285 /* Expect the server to reject it... */
286 packet_read_expect(SSH_SMSG_FAILURE);
287 BN_clear_free(challenge);
291 /* Compute and send a response to the challenge. */
292 respond_to_rsa_challenge(challenge, private->rsa);
294 /* Destroy the private key unless it in external hardware. */
295 if (!(private->flags & KEY_FLAG_EXT))
298 /* We no longer need the challenge. */
299 BN_clear_free(challenge);
301 /* Wait for response from the server. */
302 type = packet_read();
303 if (type == SSH_SMSG_SUCCESS) {
304 debug("RSA authentication accepted by server.");
307 if (type != SSH_SMSG_FAILURE)
308 packet_disconnect("Protocol error waiting RSA auth response: %d", type);
309 debug("RSA authentication refused.");
314 * Tries to authenticate the user using combined rhosts or /etc/hosts.equiv
315 * authentication and RSA host authentication.
318 try_rhosts_rsa_authentication(const char *local_user, Key * host_key)
323 debug("Trying rhosts or /etc/hosts.equiv with RSA host authentication.");
325 /* Tell the server that we are willing to authenticate using this key. */
326 packet_start(SSH_CMSG_AUTH_RHOSTS_RSA);
327 packet_put_cstring(local_user);
328 packet_put_int(BN_num_bits(host_key->rsa->n));
329 packet_put_bignum(host_key->rsa->e);
330 packet_put_bignum(host_key->rsa->n);
334 /* Wait for server's response. */
335 type = packet_read();
337 /* The server responds with failure if it doesn't admit our
338 .rhosts authentication or doesn't know our host key. */
339 if (type == SSH_SMSG_FAILURE) {
340 debug("Server refused our rhosts authentication or host key.");
343 /* Otherwise, the server should respond with a challenge. */
344 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
345 packet_disconnect("Protocol error during RSA authentication: %d", type);
347 /* Get the challenge from the packet. */
348 if ((challenge = BN_new()) == NULL)
349 fatal("try_rhosts_rsa_authentication: BN_new failed");
350 packet_get_bignum(challenge);
353 debug("Received RSA challenge for host key from server.");
355 /* Compute a response to the challenge. */
356 respond_to_rsa_challenge(challenge, host_key->rsa);
358 /* We no longer need the challenge. */
359 BN_clear_free(challenge);
361 /* Wait for response from the server. */
362 type = packet_read();
363 if (type == SSH_SMSG_SUCCESS) {
364 debug("Rhosts or /etc/hosts.equiv with RSA host authentication accepted by server.");
367 if (type != SSH_SMSG_FAILURE)
368 packet_disconnect("Protocol error waiting RSA auth response: %d", type);
369 debug("Rhosts or /etc/hosts.equiv with RSA host authentication refused.");
375 try_krb5_authentication(krb5_context *context, krb5_auth_context *auth_context)
377 krb5_error_code problem;
380 krb5_ccache ccache = NULL;
381 const char *remotehost;
384 krb5_ap_rep_enc_part *reply = NULL;
387 memset(&ap, 0, sizeof(ap));
389 problem = krb5_init_context(context);
391 debug("Kerberos v5: krb5_init_context failed");
396 problem = krb5_auth_con_init(*context, auth_context);
398 debug("Kerberos v5: krb5_auth_con_init failed");
404 problem = krb5_auth_con_setflags(*context, *auth_context,
405 KRB5_AUTH_CONTEXT_RET_TIME);
407 debug("Keberos v5: krb5_auth_con_setflags failed");
413 tkfile = krb5_cc_default_name(*context);
414 if (strncmp(tkfile, "FILE:", 5) == 0)
417 if (stat(tkfile, &buf) == 0 && getuid() != buf.st_uid) {
418 debug("Kerberos v5: could not get default ccache (permission denied).");
423 problem = krb5_cc_default(*context, &ccache);
425 debug("Kerberos v5: krb5_cc_default failed: %s",
426 krb5_get_err_text(*context, problem));
431 remotehost = get_canonical_hostname(1);
433 problem = krb5_mk_req(*context, auth_context, AP_OPTS_MUTUAL_REQUIRED,
434 "host", remotehost, NULL, ccache, &ap);
436 debug("Kerberos v5: krb5_mk_req failed: %s",
437 krb5_get_err_text(*context, problem));
442 packet_start(SSH_CMSG_AUTH_KERBEROS);
443 packet_put_string((char *) ap.data, ap.length);
450 type = packet_read();
452 case SSH_SMSG_FAILURE:
453 /* Should really be SSH_SMSG_AUTH_KERBEROS_FAILURE */
454 debug("Kerberos v5 authentication failed.");
458 case SSH_SMSG_AUTH_KERBEROS_RESPONSE:
459 /* SSH_SMSG_AUTH_KERBEROS_SUCCESS */
460 debug("Kerberos v5 authentication accepted.");
462 /* Get server's response. */
463 ap.data = packet_get_string((unsigned int *) &ap.length);
465 /* XXX je to dobre? */
467 problem = krb5_rd_rep(*context, *auth_context, &ap, &reply);
475 packet_disconnect("Protocol error on Kerberos v5 response: %d",
484 krb5_cc_close(*context, ccache);
486 krb5_free_ap_rep_enc_part(*context, reply);
491 krb5_free_data_contents(*context, &ap);
498 send_krb5_tgt(krb5_context context, krb5_auth_context auth_context)
501 krb5_error_code problem;
503 krb5_ccache ccache = NULL;
506 krb5_kdc_flags flags;
510 const char *remotehost;
512 memset(&creds, 0, sizeof(creds));
513 memset(&outbuf, 0, sizeof(outbuf));
515 fd = packet_get_connection_in();
518 problem = krb5_auth_con_setaddrs_from_fd(context, auth_context, &fd);
520 problem = krb5_auth_con_genaddrs(context, auth_context, fd,
521 KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR |
522 KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR);
527 problem = krb5_cc_default(context, &ccache);
531 problem = krb5_cc_get_principal(context, ccache, &creds.client);
535 remotehost = get_canonical_hostname(1);
538 problem = krb5_build_principal(context, &creds.server,
539 strlen(creds.client->realm), creds.client->realm,
540 "krbtgt", creds.client->realm, NULL);
542 problem = krb5_build_principal(context, &creds.server,
543 creds.client->realm.length, creds.client->realm.data,
544 "host", remotehost, NULL);
549 creds.times.endtime = 0;
553 flags.b.forwarded = 1;
554 flags.b.forwardable = krb5_config_get_bool(context, NULL,
555 "libdefaults", "forwardable", NULL);
556 problem = krb5_get_forwarded_creds(context, auth_context,
557 ccache, flags.i, remotehost, &creds, &outbuf);
560 problem = krb5_fwd_tgt_creds(context, auth_context, remotehost,
561 creds.client, creds.server, ccache, forwardable, &outbuf);
567 packet_start(SSH_CMSG_HAVE_KERBEROS_TGT);
568 packet_put_string((char *)outbuf.data, outbuf.length);
572 type = packet_read();
574 if (type == SSH_SMSG_SUCCESS) {
577 krb5_unparse_name(context, creds.client, &pname);
578 debug("Kerberos v5 TGT forwarded (%s).", pname);
581 debug("Kerberos v5 TGT forwarding failed.");
587 debug("Kerberos v5 TGT forwarding failed: %s",
588 krb5_get_err_text(context, problem));
590 krb5_free_principal(context, creds.client);
592 krb5_free_principal(context, creds.server);
594 krb5_cc_close(context, ccache);
601 * Tries to authenticate with any string-based challenge/response system.
602 * Note that the client code is not tied to s/key or TIS.
605 try_challenge_response_authentication(void)
610 char *challenge, *response;
612 debug("Doing challenge response authentication.");
614 for (i = 0; i < options.number_of_password_prompts; i++) {
615 /* request a challenge */
616 packet_start(SSH_CMSG_AUTH_TIS);
620 type = packet_read();
621 if (type != SSH_SMSG_FAILURE &&
622 type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
623 packet_disconnect("Protocol error: got %d in response "
624 "to SSH_CMSG_AUTH_TIS", type);
626 if (type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
627 debug("No challenge.");
630 challenge = packet_get_string(&clen);
632 snprintf(prompt, sizeof prompt, "%s%s", challenge,
633 strchr(challenge, '\n') ? "" : "\nResponse: ");
636 error("Permission denied, please try again.");
637 if (options.cipher == SSH_CIPHER_NONE)
638 logit("WARNING: Encryption is disabled! "
639 "Response will be transmitted in clear text.");
640 response = read_passphrase(prompt, 0);
641 if (strcmp(response, "") == 0) {
645 packet_start(SSH_CMSG_AUTH_TIS_RESPONSE);
646 ssh_put_password(response);
647 memset(response, 0, strlen(response));
651 type = packet_read();
652 if (type == SSH_SMSG_SUCCESS)
654 if (type != SSH_SMSG_FAILURE)
655 packet_disconnect("Protocol error: got %d in response "
656 "to SSH_CMSG_AUTH_TIS_RESPONSE", type);
663 * Tries to authenticate with plain passwd authentication.
666 try_password_authentication(char *prompt)
671 debug("Doing password authentication.");
672 if (options.cipher == SSH_CIPHER_NONE)
673 logit("WARNING: Encryption is disabled! Password will be transmitted in clear text.");
674 for (i = 0; i < options.number_of_password_prompts; i++) {
676 error("Permission denied, please try again.");
677 password = read_passphrase(prompt, 0);
678 packet_start(SSH_CMSG_AUTH_PASSWORD);
679 ssh_put_password(password);
680 memset(password, 0, strlen(password));
685 type = packet_read();
686 if (type == SSH_SMSG_SUCCESS)
688 if (type != SSH_SMSG_FAILURE)
689 packet_disconnect("Protocol error: got %d in response to passwd auth", type);
699 ssh_kex(char *host, struct sockaddr *hostaddr)
703 Key *host_key, *server_key;
705 int ssh_cipher_default = SSH_CIPHER_3DES;
706 u_char session_key[SSH_SESSION_KEY_LENGTH];
708 u_int supported_ciphers;
709 u_int server_flags, client_flags;
712 debug("Waiting for server public key.");
714 /* Wait for a public key packet from the server. */
715 packet_read_expect(SSH_SMSG_PUBLIC_KEY);
717 /* Get cookie from the packet. */
718 for (i = 0; i < 8; i++)
719 cookie[i] = packet_get_char();
721 /* Get the public key. */
722 server_key = key_new(KEY_RSA1);
723 bits = packet_get_int();
724 packet_get_bignum(server_key->rsa->e);
725 packet_get_bignum(server_key->rsa->n);
727 rbits = BN_num_bits(server_key->rsa->n);
729 logit("Warning: Server lies about size of server public key: "
730 "actual size is %d bits vs. announced %d.", rbits, bits);
731 logit("Warning: This may be due to an old implementation of ssh.");
733 /* Get the host key. */
734 host_key = key_new(KEY_RSA1);
735 bits = packet_get_int();
736 packet_get_bignum(host_key->rsa->e);
737 packet_get_bignum(host_key->rsa->n);
739 rbits = BN_num_bits(host_key->rsa->n);
741 logit("Warning: Server lies about size of server host key: "
742 "actual size is %d bits vs. announced %d.", rbits, bits);
743 logit("Warning: This may be due to an old implementation of ssh.");
746 /* Get protocol flags. */
747 server_flags = packet_get_int();
748 packet_set_protocol_flags(server_flags);
750 supported_ciphers = packet_get_int();
751 supported_authentications = packet_get_int();
754 debug("Received server public key (%d bits) and host key (%d bits).",
755 BN_num_bits(server_key->rsa->n), BN_num_bits(host_key->rsa->n));
757 if (verify_host_key(host, hostaddr, host_key) == -1)
758 fatal("Host key verification failed.");
760 client_flags = SSH_PROTOFLAG_SCREEN_NUMBER | SSH_PROTOFLAG_HOST_IN_FWD_OPEN;
762 compute_session_id(session_id, cookie, host_key->rsa->n, server_key->rsa->n);
764 /* Generate a session key. */
768 * Generate an encryption key for the session. The key is a 256 bit
769 * random number, interpreted as a 32-byte key, with the least
770 * significant 8 bits being the first byte of the key.
772 for (i = 0; i < 32; i++) {
775 session_key[i] = rand & 0xff;
780 * According to the protocol spec, the first byte of the session key
781 * is the highest byte of the integer. The session key is xored with
782 * the first 16 bytes of the session id.
784 if ((key = BN_new()) == NULL)
785 fatal("respond_to_rsa_challenge: BN_new failed");
787 for (i = 0; i < SSH_SESSION_KEY_LENGTH; i++) {
788 BN_lshift(key, key, 8);
790 BN_add_word(key, session_key[i] ^ session_id[i]);
792 BN_add_word(key, session_key[i]);
796 * Encrypt the integer using the public key and host key of the
797 * server (key with smaller modulus first).
799 if (BN_cmp(server_key->rsa->n, host_key->rsa->n) < 0) {
800 /* Public key has smaller modulus. */
801 if (BN_num_bits(host_key->rsa->n) <
802 BN_num_bits(server_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
803 fatal("respond_to_rsa_challenge: host_key %d < server_key %d + "
804 "SSH_KEY_BITS_RESERVED %d",
805 BN_num_bits(host_key->rsa->n),
806 BN_num_bits(server_key->rsa->n),
807 SSH_KEY_BITS_RESERVED);
809 rsa_public_encrypt(key, key, server_key->rsa);
810 rsa_public_encrypt(key, key, host_key->rsa);
812 /* Host key has smaller modulus (or they are equal). */
813 if (BN_num_bits(server_key->rsa->n) <
814 BN_num_bits(host_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
815 fatal("respond_to_rsa_challenge: server_key %d < host_key %d + "
816 "SSH_KEY_BITS_RESERVED %d",
817 BN_num_bits(server_key->rsa->n),
818 BN_num_bits(host_key->rsa->n),
819 SSH_KEY_BITS_RESERVED);
821 rsa_public_encrypt(key, key, host_key->rsa);
822 rsa_public_encrypt(key, key, server_key->rsa);
825 /* Destroy the public keys since we no longer need them. */
826 key_free(server_key);
829 if (options.cipher == SSH_CIPHER_NOT_SET) {
830 if (cipher_mask_ssh1(1) & supported_ciphers & (1 << ssh_cipher_default))
831 options.cipher = ssh_cipher_default;
832 } else if (options.cipher == SSH_CIPHER_ILLEGAL ||
833 !(cipher_mask_ssh1(1) & (1 << options.cipher))) {
834 logit("No valid SSH1 cipher, using %.100s instead.",
835 cipher_name(ssh_cipher_default));
836 options.cipher = ssh_cipher_default;
838 /* Check that the selected cipher is supported. */
839 if (!(supported_ciphers & (1 << options.cipher)))
840 fatal("Selected cipher type %.100s not supported by server.",
841 cipher_name(options.cipher));
843 debug("Encryption type: %.100s", cipher_name(options.cipher));
845 /* Send the encrypted session key to the server. */
846 packet_start(SSH_CMSG_SESSION_KEY);
847 packet_put_char(options.cipher);
849 /* Send the cookie back to the server. */
850 for (i = 0; i < 8; i++)
851 packet_put_char(cookie[i]);
853 /* Send and destroy the encrypted encryption key integer. */
854 packet_put_bignum(key);
857 /* Send protocol flags. */
858 packet_put_int(client_flags);
860 /* Send the packet now. */
864 debug("Sent encrypted session key.");
866 /* Set the encryption key. */
867 packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, options.cipher);
869 /* We will no longer need the session key here. Destroy any extra copies. */
870 memset(session_key, 0, sizeof(session_key));
873 * Expect a success message from the server. Note that this message
874 * will be received in encrypted form.
876 packet_read_expect(SSH_SMSG_SUCCESS);
878 debug("Received encrypted confirmation.");
885 ssh_userauth1(const char *local_user, const char *server_user, char *host,
886 Sensitive *sensitive)
889 krb5_context context = NULL;
890 krb5_auth_context auth_context = NULL;
894 if (supported_authentications == 0)
895 fatal("ssh_userauth1: server supports no auth methods");
897 /* Send the name of the user to log in as on the server. */
898 packet_start(SSH_CMSG_USER);
899 packet_put_cstring(server_user);
904 * The server should respond with success if no authentication is
905 * needed (the user has no password). Otherwise the server responds
908 type = packet_read();
910 /* check whether the connection was accepted without authentication. */
911 if (type == SSH_SMSG_SUCCESS)
913 if (type != SSH_SMSG_FAILURE)
914 packet_disconnect("Protocol error: got %d in response to SSH_CMSG_USER", type);
917 if ((supported_authentications & (1 << SSH_AUTH_KERBEROS)) &&
918 options.kerberos_authentication) {
919 debug("Trying Kerberos v5 authentication.");
921 if (try_krb5_authentication(&context, &auth_context)) {
922 type = packet_read();
923 if (type == SSH_SMSG_SUCCESS)
925 if (type != SSH_SMSG_FAILURE)
926 packet_disconnect("Protocol error: got %d in response to Kerberos v5 auth", type);
932 * Try .rhosts or /etc/hosts.equiv authentication with RSA host
935 if ((supported_authentications & (1 << SSH_AUTH_RHOSTS_RSA)) &&
936 options.rhosts_rsa_authentication) {
937 for (i = 0; i < sensitive->nkeys; i++) {
938 if (sensitive->keys[i] != NULL &&
939 sensitive->keys[i]->type == KEY_RSA1 &&
940 try_rhosts_rsa_authentication(local_user,
945 /* Try RSA authentication if the server supports it. */
946 if ((supported_authentications & (1 << SSH_AUTH_RSA)) &&
947 options.rsa_authentication) {
949 * Try RSA authentication using the authentication agent. The
950 * agent is tried first because no passphrase is needed for
951 * it, whereas identity files may require passphrases.
953 if (try_agent_authentication())
956 /* Try RSA authentication for each identity. */
957 for (i = 0; i < options.num_identity_files; i++)
958 if (options.identity_keys[i] != NULL &&
959 options.identity_keys[i]->type == KEY_RSA1 &&
960 try_rsa_authentication(i))
963 /* Try challenge response authentication if the server supports it. */
964 if ((supported_authentications & (1 << SSH_AUTH_TIS)) &&
965 options.challenge_response_authentication && !options.batch_mode) {
966 if (try_challenge_response_authentication())
969 /* Try password authentication if the server supports it. */
970 if ((supported_authentications & (1 << SSH_AUTH_PASSWORD)) &&
971 options.password_authentication && !options.batch_mode) {
974 snprintf(prompt, sizeof(prompt), "%.30s@%.128s's password: ",
976 if (try_password_authentication(prompt))
979 /* All authentication methods have failed. Exit with an error message. */
980 fatal("Permission denied.");
985 /* Try Kerberos v5 TGT passing. */
986 if ((supported_authentications & (1 << SSH_PASS_KERBEROS_TGT)) &&
987 options.kerberos_tgt_passing && context && auth_context) {
988 if (options.cipher == SSH_CIPHER_NONE)
989 logit("WARNING: Encryption is disabled! Ticket will be transmitted in the clear!");
990 send_krb5_tgt(context, auth_context);
993 krb5_auth_con_free(context, auth_context);
995 krb5_free_context(context);
997 return; /* need statement after label */