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.52 2002/08/08 13:50:23 aaron Exp $");
18 #include <openssl/bn.h>
19 #include <openssl/md5.h>
27 #define krb5_get_err_text(context,code) error_message(code)
47 #include "sshconnect.h"
59 * MD5 hash of host and session keys for verification. This is filled
60 * in in ssh_login() and then checked in try_gssapi_authentication().
62 unsigned char ssh_key_digest[16];
65 /* Session id for the current session. */
66 u_char session_id[16];
67 u_int supported_authentications = 0;
69 extern Options options;
70 extern char *__progname;
73 * Checks if the user has an authentication agent, and if so, tries to
74 * authenticate using the agent.
77 try_agent_authentication(void)
81 AuthenticationConnection *auth;
87 /* Get connection to the agent. */
88 auth = ssh_get_authentication_connection();
92 if ((challenge = BN_new()) == NULL)
93 fatal("try_agent_authentication: BN_new failed");
94 /* Loop through identities served by the agent. */
95 for (key = ssh_get_first_identity(auth, &comment, 1);
97 key = ssh_get_next_identity(auth, &comment, 1)) {
99 /* Try this identity. */
100 debug("Trying RSA authentication via agent with '%.100s'", comment);
103 /* Tell the server that we are willing to authenticate using this key. */
104 packet_start(SSH_CMSG_AUTH_RSA);
105 packet_put_bignum(key->rsa->n);
109 /* Wait for server's response. */
110 type = packet_read();
112 /* The server sends failure if it doesn\'t like our key or
113 does not support RSA authentication. */
114 if (type == SSH_SMSG_FAILURE) {
115 debug("Server refused our key.");
119 /* Otherwise it should have sent a challenge. */
120 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
121 packet_disconnect("Protocol error during RSA authentication: %d",
124 packet_get_bignum(challenge);
127 debug("Received RSA challenge from server.");
129 /* Ask the agent to decrypt the challenge. */
130 if (!ssh_decrypt_challenge(auth, key, challenge, session_id, 1, response)) {
132 * The agent failed to authenticate this identifier
133 * although it advertised it supports this. Just
134 * return a wrong value.
136 log("Authentication agent failed to decrypt challenge.");
137 memset(response, 0, sizeof(response));
140 debug("Sending response to RSA challenge.");
142 /* Send the decrypted challenge back to the server. */
143 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
144 for (i = 0; i < 16; i++)
145 packet_put_char(response[i]);
149 /* Wait for response from the server. */
150 type = packet_read();
152 /* The server returns success if it accepted the authentication. */
153 if (type == SSH_SMSG_SUCCESS) {
154 ssh_close_authentication_connection(auth);
155 BN_clear_free(challenge);
156 debug("RSA authentication accepted by server.");
159 /* Otherwise it should return failure. */
160 if (type != SSH_SMSG_FAILURE)
161 packet_disconnect("Protocol error waiting RSA auth response: %d",
164 ssh_close_authentication_connection(auth);
165 BN_clear_free(challenge);
166 debug("RSA authentication using agent refused.");
171 * Computes the proper response to a RSA challenge, and sends the response to
175 respond_to_rsa_challenge(BIGNUM * challenge, RSA * prv)
177 u_char buf[32], response[16];
181 /* Decrypt the challenge using the private key. */
182 /* XXX think about Bleichenbacher, too */
183 if (rsa_private_decrypt(challenge, challenge, prv) <= 0)
185 "respond_to_rsa_challenge: rsa_private_decrypt failed");
187 /* Compute the response. */
188 /* The response is MD5 of decrypted challenge plus session id. */
189 len = BN_num_bytes(challenge);
190 if (len <= 0 || len > sizeof(buf))
192 "respond_to_rsa_challenge: bad challenge length %d", len);
194 memset(buf, 0, sizeof(buf));
195 BN_bn2bin(challenge, buf + sizeof(buf) - len);
197 MD5_Update(&md, buf, 32);
198 MD5_Update(&md, session_id, 16);
199 MD5_Final(response, &md);
201 debug("Sending response to host key RSA challenge.");
203 /* Send the response back to the server. */
204 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
205 for (i = 0; i < 16; i++)
206 packet_put_char(response[i]);
210 memset(buf, 0, sizeof(buf));
211 memset(response, 0, sizeof(response));
212 memset(&md, 0, sizeof(md));
216 * Checks if the user has authentication file, and if so, tries to authenticate
220 try_rsa_authentication(int idx)
223 Key *public, *private;
224 char buf[300], *passphrase, *comment, *authfile;
227 public = options.identity_keys[idx];
228 authfile = options.identity_files[idx];
229 comment = xstrdup(authfile);
231 debug("Trying RSA authentication with key '%.100s'", comment);
233 /* Tell the server that we are willing to authenticate using this key. */
234 packet_start(SSH_CMSG_AUTH_RSA);
235 packet_put_bignum(public->rsa->n);
239 /* Wait for server's response. */
240 type = packet_read();
243 * The server responds with failure if it doesn\'t like our key or
244 * doesn\'t support RSA authentication.
246 if (type == SSH_SMSG_FAILURE) {
247 debug("Server refused our key.");
251 /* Otherwise, the server should respond with a challenge. */
252 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
253 packet_disconnect("Protocol error during RSA authentication: %d", type);
255 /* Get the challenge from the packet. */
256 if ((challenge = BN_new()) == NULL)
257 fatal("try_rsa_authentication: BN_new failed");
258 packet_get_bignum(challenge);
261 debug("Received RSA challenge from server.");
264 * If the key is not stored in external hardware, we have to
265 * load the private key. Try first with empty passphrase; if it
266 * fails, ask for a passphrase.
268 if (public->flags & KEY_FLAG_EXT)
271 private = key_load_private_type(KEY_RSA1, authfile, "", NULL);
272 if (private == NULL && !options.batch_mode) {
273 snprintf(buf, sizeof(buf),
274 "Enter passphrase for RSA key '%.100s': ", comment);
275 for (i = 0; i < options.number_of_password_prompts; i++) {
276 passphrase = read_passphrase(buf, 0);
277 if (strcmp(passphrase, "") != 0) {
278 private = key_load_private_type(KEY_RSA1,
279 authfile, passphrase, NULL);
282 debug2("no passphrase given, try next key");
285 memset(passphrase, 0, strlen(passphrase));
287 if (private != NULL || quit)
289 debug2("bad passphrase given, try again...");
292 /* We no longer need the comment. */
295 if (private == NULL) {
296 if (!options.batch_mode)
297 error("Bad passphrase.");
299 /* Send a dummy response packet to avoid protocol error. */
300 packet_start(SSH_CMSG_AUTH_RSA_RESPONSE);
301 for (i = 0; i < 16; i++)
306 /* Expect the server to reject it... */
307 packet_read_expect(SSH_SMSG_FAILURE);
308 BN_clear_free(challenge);
312 /* Compute and send a response to the challenge. */
313 respond_to_rsa_challenge(challenge, private->rsa);
315 /* Destroy the private key unless it in external hardware. */
316 if (!(private->flags & KEY_FLAG_EXT))
319 /* We no longer need the challenge. */
320 BN_clear_free(challenge);
322 /* Wait for response from the server. */
323 type = packet_read();
324 if (type == SSH_SMSG_SUCCESS) {
325 debug("RSA authentication accepted by server.");
328 if (type != SSH_SMSG_FAILURE)
329 packet_disconnect("Protocol error waiting RSA auth response: %d", type);
330 debug("RSA authentication refused.");
335 * Tries to authenticate the user using combined rhosts or /etc/hosts.equiv
336 * authentication and RSA host authentication.
339 try_rhosts_rsa_authentication(const char *local_user, Key * host_key)
344 debug("Trying rhosts or /etc/hosts.equiv with RSA host authentication.");
346 /* Tell the server that we are willing to authenticate using this key. */
347 packet_start(SSH_CMSG_AUTH_RHOSTS_RSA);
348 packet_put_cstring(local_user);
349 packet_put_int(BN_num_bits(host_key->rsa->n));
350 packet_put_bignum(host_key->rsa->e);
351 packet_put_bignum(host_key->rsa->n);
355 /* Wait for server's response. */
356 type = packet_read();
358 /* The server responds with failure if it doesn't admit our
359 .rhosts authentication or doesn't know our host key. */
360 if (type == SSH_SMSG_FAILURE) {
361 debug("Server refused our rhosts authentication or host key.");
364 /* Otherwise, the server should respond with a challenge. */
365 if (type != SSH_SMSG_AUTH_RSA_CHALLENGE)
366 packet_disconnect("Protocol error during RSA authentication: %d", type);
368 /* Get the challenge from the packet. */
369 if ((challenge = BN_new()) == NULL)
370 fatal("try_rhosts_rsa_authentication: BN_new failed");
371 packet_get_bignum(challenge);
374 debug("Received RSA challenge for host key from server.");
376 /* Compute a response to the challenge. */
377 respond_to_rsa_challenge(challenge, host_key->rsa);
379 /* We no longer need the challenge. */
380 BN_clear_free(challenge);
382 /* Wait for response from the server. */
383 type = packet_read();
384 if (type == SSH_SMSG_SUCCESS) {
385 debug("Rhosts or /etc/hosts.equiv with RSA host authentication accepted by server.");
388 if (type != SSH_SMSG_FAILURE)
389 packet_disconnect("Protocol error waiting RSA auth response: %d", type);
390 debug("Rhosts or /etc/hosts.equiv with RSA host authentication refused.");
396 try_krb4_authentication(void)
398 KTEXT_ST auth; /* Kerberos data */
405 Key_schedule schedule;
406 u_long checksum, cksum;
408 struct sockaddr_in local, foreign;
411 /* Don't do anything if we don't have any tickets. */
412 if (stat(tkt_string(), &st) < 0)
415 strlcpy(inst, (char *)krb_get_phost(get_canonical_hostname(1)),
418 realm = (char *)krb_realmofhost(get_canonical_hostname(1));
420 debug("Kerberos v4: no realm for %s", get_canonical_hostname(1));
423 /* This can really be anything. */
424 checksum = (u_long)getpid();
426 r = krb_mk_req(&auth, KRB4_SERVICE_NAME, inst, realm, checksum);
428 debug("Kerberos v4 krb_mk_req failed: %s", krb_err_txt[r]);
431 /* Get session key to decrypt the server's reply with. */
432 r = krb_get_cred(KRB4_SERVICE_NAME, inst, realm, &cred);
434 debug("get_cred failed: %s", krb_err_txt[r]);
437 des_key_sched((des_cblock *) cred.session, schedule);
439 /* Send authentication info to server. */
440 packet_start(SSH_CMSG_AUTH_KERBEROS);
441 packet_put_string((char *) auth.dat, auth.length);
445 /* Zero the buffer. */
446 (void) memset(auth.dat, 0, MAX_KTXT_LEN);
448 slen = sizeof(local);
449 memset(&local, 0, sizeof(local));
450 if (getsockname(packet_get_connection_in(),
451 (struct sockaddr *)&local, &slen) < 0)
452 debug("getsockname failed: %s", strerror(errno));
454 slen = sizeof(foreign);
455 memset(&foreign, 0, sizeof(foreign));
456 if (getpeername(packet_get_connection_in(),
457 (struct sockaddr *)&foreign, &slen) < 0) {
458 debug("getpeername failed: %s", strerror(errno));
461 /* Get server reply. */
462 type = packet_read();
464 case SSH_SMSG_FAILURE:
465 /* Should really be SSH_SMSG_AUTH_KERBEROS_FAILURE */
466 debug("Kerberos v4 authentication failed.");
470 case SSH_SMSG_AUTH_KERBEROS_RESPONSE:
471 /* SSH_SMSG_AUTH_KERBEROS_SUCCESS */
472 debug("Kerberos v4 authentication accepted.");
474 /* Get server's response. */
475 reply = packet_get_string((u_int *) &auth.length);
476 if (auth.length >= MAX_KTXT_LEN)
477 fatal("Kerberos v4: Malformed response from server");
478 memcpy(auth.dat, reply, auth.length);
484 * If his response isn't properly encrypted with the session
485 * key, and the decrypted checksum fails to match, he's
488 r = krb_rd_priv(auth.dat, auth.length, schedule, &cred.session,
489 &foreign, &local, &msg_data);
491 debug("Kerberos v4 krb_rd_priv failed: %s",
493 packet_disconnect("Kerberos v4 challenge failed!");
495 /* Fetch the (incremented) checksum that we supplied in the request. */
496 memcpy((char *)&cksum, (char *)msg_data.app_data,
498 cksum = ntohl(cksum);
500 /* If it matches, we're golden. */
501 if (cksum == checksum + 1) {
502 debug("Kerberos v4 challenge successful.");
505 packet_disconnect("Kerberos v4 challenge failed!");
509 packet_disconnect("Protocol error on Kerberos v4 response: %d", type);
518 try_krb5_authentication(krb5_context *context, krb5_auth_context *auth_context)
520 krb5_error_code problem;
523 krb5_ccache ccache = NULL;
524 const char *remotehost;
527 krb5_ap_rep_enc_part *reply = NULL;
530 memset(&ap, 0, sizeof(ap));
532 problem = krb5_init_context(context);
534 debug("Kerberos v5: krb5_init_context failed");
539 problem = krb5_auth_con_init(*context, auth_context);
541 debug("Kerberos v5: krb5_auth_con_init failed");
547 problem = krb5_auth_con_setflags(*context, *auth_context,
548 KRB5_AUTH_CONTEXT_RET_TIME);
550 debug("Keberos v5: krb5_auth_con_setflags failed");
556 tkfile = krb5_cc_default_name(*context);
557 if (strncmp(tkfile, "FILE:", 5) == 0)
560 if (stat(tkfile, &buf) == 0 && getuid() != buf.st_uid) {
561 debug("Kerberos v5: could not get default ccache (permission denied).");
566 problem = krb5_cc_default(*context, &ccache);
568 debug("Kerberos v5: krb5_cc_default failed: %s",
569 krb5_get_err_text(*context, problem));
574 remotehost = get_canonical_hostname(1);
576 problem = krb5_mk_req(*context, auth_context, AP_OPTS_MUTUAL_REQUIRED,
577 "host", remotehost, NULL, ccache, &ap);
579 debug("Kerberos v5: krb5_mk_req failed: %s",
580 krb5_get_err_text(*context, problem));
585 packet_start(SSH_CMSG_AUTH_KERBEROS);
586 packet_put_string((char *) ap.data, ap.length);
593 type = packet_read();
595 case SSH_SMSG_FAILURE:
596 /* Should really be SSH_SMSG_AUTH_KERBEROS_FAILURE */
597 debug("Kerberos v5 authentication failed.");
601 case SSH_SMSG_AUTH_KERBEROS_RESPONSE:
602 /* SSH_SMSG_AUTH_KERBEROS_SUCCESS */
603 debug("Kerberos v5 authentication accepted.");
605 /* Get server's response. */
606 ap.data = packet_get_string((unsigned int *) &ap.length);
608 /* XXX je to dobre? */
610 problem = krb5_rd_rep(*context, *auth_context, &ap, &reply);
618 packet_disconnect("Protocol error on Kerberos v5 response: %d",
627 krb5_cc_close(*context, ccache);
629 krb5_free_ap_rep_enc_part(*context, reply);
634 krb5_free_data_contents(*context, &ap);
641 send_krb5_tgt(krb5_context context, krb5_auth_context auth_context)
644 krb5_error_code problem;
646 krb5_ccache ccache = NULL;
649 krb5_kdc_flags flags;
653 const char *remotehost;
655 memset(&creds, 0, sizeof(creds));
656 memset(&outbuf, 0, sizeof(outbuf));
658 fd = packet_get_connection_in();
661 problem = krb5_auth_con_setaddrs_from_fd(context, auth_context, &fd);
663 problem = krb5_auth_con_genaddrs(context, auth_context, fd,
664 KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR |
665 KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR);
670 problem = krb5_cc_default(context, &ccache);
674 problem = krb5_cc_get_principal(context, ccache, &creds.client);
678 remotehost = get_canonical_hostname(1);
681 problem = krb5_build_principal(context, &creds.server,
682 strlen(creds.client->realm), creds.client->realm,
683 "krbtgt", creds.client->realm, NULL);
685 problem = krb5_build_principal(context, &creds.server,
686 creds.client->realm.length, creds.client->realm.data,
687 "host", remotehost, NULL);
692 creds.times.endtime = 0;
696 flags.b.forwarded = 1;
697 flags.b.forwardable = krb5_config_get_bool(context, NULL,
698 "libdefaults", "forwardable", NULL);
699 problem = krb5_get_forwarded_creds(context, auth_context,
700 ccache, flags.i, remotehost, &creds, &outbuf);
703 problem = krb5_fwd_tgt_creds(context, auth_context, remotehost,
704 creds.client, creds.server, ccache, forwardable, &outbuf);
710 packet_start(SSH_CMSG_HAVE_KERBEROS_TGT);
711 packet_put_string((char *)outbuf.data, outbuf.length);
715 type = packet_read();
717 if (type == SSH_SMSG_SUCCESS) {
720 krb5_unparse_name(context, creds.client, &pname);
721 debug("Kerberos v5 TGT forwarded (%s).", pname);
724 debug("Kerberos v5 TGT forwarding failed.");
730 debug("Kerberos v5 TGT forwarding failed: %s",
731 krb5_get_err_text(context, problem));
733 krb5_free_principal(context, creds.client);
735 krb5_free_principal(context, creds.server);
737 krb5_cc_close(context, ccache);
749 char buffer[4096], pname[ANAME_SZ], pinst[INST_SZ], prealm[REALM_SZ];
752 /* Don't do anything if we don't have any tickets. */
753 if (stat(tkt_string(), &st) < 0)
756 creds = xmalloc(sizeof(*creds));
758 problem = krb_get_tf_fullname(TKT_FILE, pname, pinst, prealm);
762 problem = krb_get_cred("krbtgt", prealm, prealm, creds);
766 if (time(0) > krb_life_to_time(creds->issue_date, creds->lifetime)) {
770 creds_to_radix(creds, (u_char *)buffer, sizeof(buffer));
772 packet_start(SSH_CMSG_HAVE_KERBEROS_TGT);
773 packet_put_cstring(buffer);
777 type = packet_read();
779 if (type == SSH_SMSG_SUCCESS)
780 debug("Kerberos v4 TGT forwarded (%s%s%s@%s).",
781 creds->pname, creds->pinst[0] ? "." : "",
782 creds->pinst, creds->realm);
784 debug("Kerberos v4 TGT rejected.");
790 debug("Kerberos v4 TGT passing failed: %s", krb_err_txt[problem]);
795 send_afs_tokens(void)
798 struct ViceIoctl parms;
799 struct ClearToken ct;
801 char buf[2048], *p, *server_cell;
804 /* Move over ktc_GetToken, here's something leaner. */
805 for (i = 0; i < 100; i++) { /* just in case */
806 parms.in = (char *) &i;
807 parms.in_size = sizeof(i);
809 parms.out_size = sizeof(buf);
810 if (k_pioctl(0, VIOCGETTOK, &parms, 0) != 0)
814 /* Get secret token. */
815 memcpy(&creds.ticket_st.length, p, sizeof(u_int));
816 if (creds.ticket_st.length > MAX_KTXT_LEN)
819 memcpy(creds.ticket_st.dat, p, creds.ticket_st.length);
820 p += creds.ticket_st.length;
822 /* Get clear token. */
823 memcpy(&len, p, sizeof(len));
824 if (len != sizeof(struct ClearToken))
829 p += sizeof(len); /* primary flag */
832 /* Flesh out our credentials. */
833 strlcpy(creds.service, "afs", sizeof(creds.service));
834 creds.instance[0] = '\0';
835 strlcpy(creds.realm, server_cell, REALM_SZ);
836 memcpy(creds.session, ct.HandShakeKey, DES_KEY_SZ);
837 creds.issue_date = ct.BeginTimestamp;
838 creds.lifetime = krb_time_to_life(creds.issue_date,
840 creds.kvno = ct.AuthHandle;
841 snprintf(creds.pname, sizeof(creds.pname), "AFS ID %d", ct.ViceId);
842 creds.pinst[0] = '\0';
844 /* Encode token, ship it off. */
845 if (creds_to_radix(&creds, (u_char *)buffer,
846 sizeof(buffer)) <= 0)
848 packet_start(SSH_CMSG_HAVE_AFS_TOKEN);
849 packet_put_cstring(buffer);
853 /* Roger, Roger. Clearance, Clarence. What's your vector,
855 type = packet_read();
857 if (type == SSH_SMSG_FAILURE)
858 debug("AFS token for cell %s rejected.", server_cell);
859 else if (type != SSH_SMSG_SUCCESS)
860 packet_disconnect("Protocol error on AFS token response: %d", type);
867 * Tries to authenticate with any string-based challenge/response system.
868 * Note that the client code is not tied to s/key or TIS.
871 try_challenge_response_authentication(void)
876 char *challenge, *response;
878 debug("Doing challenge response authentication.");
880 for (i = 0; i < options.number_of_password_prompts; i++) {
881 /* request a challenge */
882 packet_start(SSH_CMSG_AUTH_TIS);
886 type = packet_read();
887 if (type != SSH_SMSG_FAILURE &&
888 type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
889 packet_disconnect("Protocol error: got %d in response "
890 "to SSH_CMSG_AUTH_TIS", type);
892 if (type != SSH_SMSG_AUTH_TIS_CHALLENGE) {
893 debug("No challenge.");
896 challenge = packet_get_string(&clen);
898 snprintf(prompt, sizeof prompt, "%s%s", challenge,
899 strchr(challenge, '\n') ? "" : "\nResponse: ");
902 error("Permission denied, please try again.");
903 if (options.cipher == SSH_CIPHER_NONE)
904 log("WARNING: Encryption is disabled! "
905 "Response will be transmitted in clear text.");
906 response = read_passphrase(prompt, 0);
907 if (strcmp(response, "") == 0) {
911 packet_start(SSH_CMSG_AUTH_TIS_RESPONSE);
912 ssh_put_password(response);
913 memset(response, 0, strlen(response));
917 type = packet_read();
918 if (type == SSH_SMSG_SUCCESS)
920 if (type != SSH_SMSG_FAILURE)
921 packet_disconnect("Protocol error: got %d in response "
922 "to SSH_CMSG_AUTH_TIS_RESPONSE", type);
929 * Tries to authenticate with plain passwd authentication.
932 try_password_authentication(char *prompt)
937 debug("Doing password authentication.");
938 if (options.cipher == SSH_CIPHER_NONE)
939 log("WARNING: Encryption is disabled! Password will be transmitted in clear text.");
940 for (i = 0; i < options.number_of_password_prompts; i++) {
942 error("Permission denied, please try again.");
943 password = read_passphrase(prompt, 0);
944 packet_start(SSH_CMSG_AUTH_PASSWORD);
945 ssh_put_password(password);
946 memset(password, 0, strlen(password));
951 type = packet_read();
952 if (type == SSH_SMSG_SUCCESS)
954 if (type != SSH_SMSG_FAILURE)
955 packet_disconnect("Protocol error: got %d in response to passwd auth", type);
963 char * get_gsi_name()
967 gss_name_t pname = GSS_C_NO_NAME;
968 gss_buffer_desc tmpname;
969 gss_buffer_t tmpnamed = &tmpname;
972 gss_cred_id_t gss_cred = GSS_C_NO_CREDENTIAL;
974 gss_create_empty_oid_set(&min_stat,&oidset);
975 gss_add_oid_set_member(&min_stat,&supported_mechs[GSS_GSI].oid,&oidset);
976 maj_stat = gss_acquire_cred(&min_stat,
985 if (maj_stat != GSS_S_COMPLETE) {
989 debug("calling gss_inquire_cred");
990 maj_stat = gss_inquire_cred(&min_stat,
996 if (maj_stat != GSS_S_COMPLETE) {
1000 maj_stat = gss_display_name(&min_stat,
1004 if (maj_stat != GSS_S_COMPLETE) {
1007 debug("gss_display_name finsished");
1008 retname = (char *)malloc(tmpname.length + 1);
1012 memcpy(retname, tmpname.value, tmpname.length);
1013 retname[tmpname.length] = '\0';
1015 gss_release_name(&min_stat, &pname);
1016 gss_release_buffer(&min_stat, tmpnamed);
1021 debug("Failed to set GSI username from credentials");
1022 ssh_gssapi_error(&supported_mechs[GSS_GSI].oid, maj_stat, min_stat);
1027 int try_gssapi_authentication(char *host, Options *options)
1029 char *service_name = NULL;
1030 gss_buffer_desc name_tok;
1031 gss_buffer_desc send_tok;
1032 gss_buffer_desc recv_tok;
1033 gss_buffer_desc *token_ptr;
1034 gss_name_t target_name = NULL;
1035 gss_ctx_id_t gss_context;
1036 gss_OID_desc mech_oid;
1038 gss_OID_set gss_mechs, my_mechs;
1039 int my_mech_num, i, present;
1042 int ret_stat = 0; /* 1 == success */
1043 OM_uint32 req_flags = 0;
1044 OM_uint32 ret_flags;
1048 Gssctxt *ctx = NULL;
1050 xhost = xstrdup(get_canonical_hostname(1));
1051 resolve_localhost(&xhost);
1056 req_flags |= GSS_C_REPLAY_FLAG;
1058 /* Do mutual authentication */
1059 req_flags |= GSS_C_MUTUAL_FLAG;
1061 service_name = (char *) xmalloc(strlen("host") +
1063 2 /* 1 for '@', 1 for NUL */);
1065 sprintf(service_name, "host@%s", xhost);
1070 name_type = GSS_C_NT_HOSTBASED_SERVICE;
1072 debug("Service name is %s", service_name);
1074 /* Forward credentials? */
1075 if(options->gss_deleg_creds) {
1076 debug("Delegating GSSAPI credentials");
1077 req_flags |= GSS_C_DELEG_FLAG;
1080 debug("req_flags = %u", (unsigned int)req_flags);
1082 name_tok.value = service_name;
1083 name_tok.length = strlen(service_name) + 1;
1084 maj_stat = gss_import_name(&min_stat, &name_tok,
1085 name_type, &target_name);
1088 service_name = NULL;
1090 if (maj_stat != GSS_S_COMPLETE) {
1091 ssh_gssapi_error(GSS_C_NO_OID, maj_stat, min_stat);
1095 maj_stat = gss_indicate_mechs(&min_stat, &gss_mechs);
1097 if (maj_stat != GSS_S_COMPLETE) {
1098 ssh_gssapi_error(GSS_C_NO_OID, maj_stat, min_stat);
1102 /* The GSSAPI supports the mechs in gss_mechs, but which ones do
1103 we have credentials for? We only get one try, so we don't want
1104 to propose a mechanism we know is going to fail. */
1105 maj_stat = gss_create_empty_oid_set(&min_stat, &my_mechs);
1106 for (i=0; supported_mechs[i].name != NULL; i++) {
1107 maj_stat = gss_test_oid_set_member(&min_stat, &supported_mechs[i].oid,
1108 gss_mechs, &present);
1110 if (!GSS_ERROR(ssh_gssapi_client_ctx(&ctx, &supported_mechs[i].oid,
1112 maj_stat = gss_add_oid_set_member(&min_stat,
1113 &supported_mechs[i].oid,
1115 debug("GSSAPI mechanism %s supported", supported_mechs[i].name);
1117 debug("no credentials for GSSAPI mechanism %s",
1118 supported_mechs[i].name);
1121 debug("GSSAPI mechanism %s not supported", supported_mechs[i].name);
1125 if (my_mechs->count == 0) {
1126 debug("No GSSAPI mechanisms.");
1131 * Send over a packet to the daemon, letting it know we're doing
1132 * GSSAPI and our mech_oid(s).
1134 debug("Sending mech oid(s) to server");
1135 packet_start(SSH_CMSG_AUTH_GSSAPI);
1136 packet_put_int(my_mechs->count); /* Number of mechs we're sending */
1138 /* Send GSI before Kerberos, because if GSI fails, we can always fall
1139 back and try regular Kerberos authentication with our Kerberos cred. */
1140 maj_stat = gss_test_oid_set_member(&min_stat, &supported_mechs[GSS_GSI].oid,
1141 my_mechs, &present);
1143 packet_put_string(supported_mechs[GSS_GSI].oid.elements,
1144 supported_mechs[GSS_GSI].oid.length);
1147 for (my_mech_num = 0; my_mech_num < my_mechs->count; my_mech_num++) {
1149 /* Skip GSI. We already sent it above. */
1150 if ((my_mechs->elements[my_mech_num].length ==
1151 supported_mechs[GSS_GSI].oid.length) &&
1152 memcmp(my_mechs->elements[my_mech_num].elements,
1153 supported_mechs[GSS_GSI].oid.elements,
1154 my_mechs->elements[my_mech_num].length) == 0) {
1158 packet_put_string(my_mechs->elements[my_mech_num].elements,
1159 my_mechs->elements[my_mech_num].length);
1162 packet_write_wait();
1165 * Get reply from the daemon to see if our mech was acceptable
1167 type = packet_read();
1170 case SSH_SMSG_AUTH_GSSAPI_RESPONSE:
1171 debug("Server accepted mechanism");
1172 /* Successful negotiation */
1175 case SSH_MSG_AUTH_GSSAPI_ABORT:
1176 case SSH_SMSG_FAILURE:
1177 debug("Unable to negotiate GSSAPI mechanism type with server");
1182 packet_disconnect("Protocol error during GSSAPI authentication:"
1183 " packet type %d received",
1185 /* Does not return */
1188 /* Read the mechanism the server returned */
1189 mech_oid.elements = packet_get_string(&slen);
1190 mech_oid.length = slen; /* safe typecast */
1194 * Perform the context-establishement loop.
1196 * On each pass through the loop, token_ptr points to the token
1197 * to send to the server (or GSS_C_NO_BUFFER on the first pass).
1198 * Every generated token is stored in send_tok which is then
1199 * transmitted to the server; every received token is stored in
1200 * recv_tok, which token_ptr is then set to, to be processed by
1201 * the next call to gss_init_sec_context.
1203 * GSS-API guarantees that send_tok's length will be non-zero
1204 * if and only if the server is expecting another token from us,
1205 * and that gss_init_sec_context returns GSS_S_CONTINUE_NEEDED if
1206 * and only if the server has another token to send us.
1209 token_ptr = GSS_C_NO_BUFFER;
1210 gss_context = GSS_C_NO_CONTEXT;
1214 gss_init_sec_context(&min_stat,
1215 GSS_C_NO_CREDENTIAL,
1221 NULL, /* no channel bindings */
1223 NULL, /* ignore mech type */
1226 NULL); /* ignore time_rec */
1228 if (token_ptr != GSS_C_NO_BUFFER)
1229 (void) gss_release_buffer(&min_stat, &recv_tok);
1231 if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED) {
1232 ssh_gssapi_error(&mech_oid, maj_stat, min_stat);
1234 /* Send an abort message */
1235 packet_start(SSH_MSG_AUTH_GSSAPI_ABORT);
1237 packet_write_wait();
1242 if (send_tok.length != 0) {
1243 debug("Sending authenticaton token...");
1244 packet_start(SSH_MSG_AUTH_GSSAPI_TOKEN);
1245 packet_put_string((char *) send_tok.value, send_tok.length);
1247 packet_write_wait();
1249 (void) gss_release_buffer(&min_stat, &send_tok);
1252 if (maj_stat == GSS_S_CONTINUE_NEEDED) {
1254 debug("Continue needed. Reading response...");
1256 type = packet_read();
1260 case SSH_MSG_AUTH_GSSAPI_TOKEN:
1261 /* This is what we expected */
1264 case SSH_MSG_AUTH_GSSAPI_ABORT:
1265 case SSH_SMSG_FAILURE:
1266 debug("Server aborted GSSAPI authentication.");
1271 packet_disconnect("Protocol error during GSSAPI authentication:"
1272 " packet type %d received",
1274 /* Does not return */
1277 recv_tok.value = packet_get_string(&slen);
1278 recv_tok.length=slen; /* safe typecast */
1280 token_ptr = &recv_tok;
1282 } while (maj_stat == GSS_S_CONTINUE_NEEDED);
1287 debug("GSSAPI authentication successful");
1290 * Read hash of host and server keys and make sure it
1291 * matches what we got earlier.
1293 debug("Reading hash of server and host keys...");
1294 type = packet_read();
1296 if (type == SSH_MSG_AUTH_GSSAPI_ABORT || type == SSH_SMSG_FAILURE) {
1297 debug("Server aborted GSSAPI authentication.");
1302 } else if (type == SSH_SMSG_AUTH_GSSAPI_HASH) {
1303 gss_buffer_desc wrapped_buf;
1304 gss_buffer_desc unwrapped_buf;
1306 gss_qop_t qop_state;
1309 wrapped_buf.value = packet_get_string(&slen);
1310 wrapped_buf.length=slen; /* safe typecast */
1313 maj_stat = gss_unwrap(&min_stat,
1320 if (maj_stat != GSS_S_COMPLETE) {
1321 ssh_gssapi_error(&mech_oid, maj_stat, min_stat);
1322 packet_disconnect("Verification of SSHD keys through GSSAPI-secured channel failed: "
1323 "Unwrapping of hash failed.");
1326 if (unwrapped_buf.length != sizeof(ssh_key_digest)) {
1327 packet_disconnect("Verification of SSHD keys through GSSAPI-secured channel failed: "
1328 "Size of key hashes do not match (%d != %d)!",
1329 (int)unwrapped_buf.length,
1330 (int)sizeof(ssh_key_digest));
1333 if (memcmp(ssh_key_digest, unwrapped_buf.value, sizeof(ssh_key_digest)) != 0) {
1334 packet_disconnect("Verification of SSHD keys through GSSAPI-secured channel failed: "
1335 "Hashes don't match!");
1338 debug("Verified SSHD keys through GSSAPI-secured channel.");
1340 gss_release_buffer(&min_stat, &unwrapped_buf);
1343 packet_disconnect("Protocol error during GSSAPI authentication:"
1344 "packet type %d received", type);
1345 /* Does not return */
1350 if (target_name != NULL)
1351 (void) gss_release_name(&min_stat, &target_name);
1363 ssh_kex(char *host, struct sockaddr *hostaddr)
1367 Key *host_key, *server_key;
1369 int ssh_cipher_default = SSH_CIPHER_3DES;
1370 u_char session_key[SSH_SESSION_KEY_LENGTH];
1372 u_int supported_ciphers;
1373 u_int server_flags, client_flags;
1376 debug("Waiting for server public key.");
1378 /* Wait for a public key packet from the server. */
1379 packet_read_expect(SSH_SMSG_PUBLIC_KEY);
1381 /* Get cookie from the packet. */
1382 for (i = 0; i < 8; i++)
1383 cookie[i] = packet_get_char();
1385 /* Get the public key. */
1386 server_key = key_new(KEY_RSA1);
1387 bits = packet_get_int();
1388 packet_get_bignum(server_key->rsa->e);
1389 packet_get_bignum(server_key->rsa->n);
1391 rbits = BN_num_bits(server_key->rsa->n);
1392 if (bits != rbits) {
1393 log("Warning: Server lies about size of server public key: "
1394 "actual size is %d bits vs. announced %d.", rbits, bits);
1395 log("Warning: This may be due to an old implementation of ssh.");
1397 /* Get the host key. */
1398 host_key = key_new(KEY_RSA1);
1399 bits = packet_get_int();
1400 packet_get_bignum(host_key->rsa->e);
1401 packet_get_bignum(host_key->rsa->n);
1403 rbits = BN_num_bits(host_key->rsa->n);
1404 if (bits != rbits) {
1405 log("Warning: Server lies about size of server host key: "
1406 "actual size is %d bits vs. announced %d.", rbits, bits);
1407 log("Warning: This may be due to an old implementation of ssh.");
1414 unsigned char *data;
1415 unsigned int data_len;
1418 * Hash the server and host keys. Later we will check them against
1419 * a hash sent over a secure channel to make sure they are legit.
1421 debug("Calculating MD5 hash of server and host keys...");
1423 /* Write all the keys to a temporary buffer */
1427 buffer_put_bignum(&buf, server_key->rsa->e);
1428 buffer_put_bignum(&buf, server_key->rsa->n);
1431 buffer_put_bignum(&buf, host_key->rsa->e);
1432 buffer_put_bignum(&buf, host_key->rsa->n);
1434 /* Get the resulting data */
1435 data = (unsigned char *) buffer_ptr(&buf);
1436 data_len = buffer_len(&buf);
1439 MD5_Init(&md5context);
1440 MD5_Update(&md5context, data, data_len);
1441 MD5_Final(ssh_key_digest, &md5context);
1449 /* Get protocol flags. */
1450 server_flags = packet_get_int();
1451 packet_set_protocol_flags(server_flags);
1453 supported_ciphers = packet_get_int();
1454 supported_authentications = packet_get_int();
1457 debug("Received server public key (%d bits) and host key (%d bits).",
1458 BN_num_bits(server_key->rsa->n), BN_num_bits(host_key->rsa->n));
1460 if (verify_host_key(host, hostaddr, host_key) == -1)
1461 fatal("Host key verification failed.");
1463 client_flags = SSH_PROTOFLAG_SCREEN_NUMBER | SSH_PROTOFLAG_HOST_IN_FWD_OPEN;
1465 compute_session_id(session_id, cookie, host_key->rsa->n, server_key->rsa->n);
1467 /* Generate a session key. */
1471 * Generate an encryption key for the session. The key is a 256 bit
1472 * random number, interpreted as a 32-byte key, with the least
1473 * significant 8 bits being the first byte of the key.
1475 for (i = 0; i < 32; i++) {
1477 rand = arc4random();
1478 session_key[i] = rand & 0xff;
1483 * According to the protocol spec, the first byte of the session key
1484 * is the highest byte of the integer. The session key is xored with
1485 * the first 16 bytes of the session id.
1487 if ((key = BN_new()) == NULL)
1488 fatal("respond_to_rsa_challenge: BN_new failed");
1489 BN_set_word(key, 0);
1490 for (i = 0; i < SSH_SESSION_KEY_LENGTH; i++) {
1491 BN_lshift(key, key, 8);
1493 BN_add_word(key, session_key[i] ^ session_id[i]);
1495 BN_add_word(key, session_key[i]);
1499 * Encrypt the integer using the public key and host key of the
1500 * server (key with smaller modulus first).
1502 if (BN_cmp(server_key->rsa->n, host_key->rsa->n) < 0) {
1503 /* Public key has smaller modulus. */
1504 if (BN_num_bits(host_key->rsa->n) <
1505 BN_num_bits(server_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
1506 fatal("respond_to_rsa_challenge: host_key %d < server_key %d + "
1507 "SSH_KEY_BITS_RESERVED %d",
1508 BN_num_bits(host_key->rsa->n),
1509 BN_num_bits(server_key->rsa->n),
1510 SSH_KEY_BITS_RESERVED);
1512 rsa_public_encrypt(key, key, server_key->rsa);
1513 rsa_public_encrypt(key, key, host_key->rsa);
1515 /* Host key has smaller modulus (or they are equal). */
1516 if (BN_num_bits(server_key->rsa->n) <
1517 BN_num_bits(host_key->rsa->n) + SSH_KEY_BITS_RESERVED) {
1518 fatal("respond_to_rsa_challenge: server_key %d < host_key %d + "
1519 "SSH_KEY_BITS_RESERVED %d",
1520 BN_num_bits(server_key->rsa->n),
1521 BN_num_bits(host_key->rsa->n),
1522 SSH_KEY_BITS_RESERVED);
1524 rsa_public_encrypt(key, key, host_key->rsa);
1525 rsa_public_encrypt(key, key, server_key->rsa);
1528 /* Destroy the public keys since we no longer need them. */
1529 key_free(server_key);
1532 if (options.cipher == SSH_CIPHER_NOT_SET) {
1533 if (cipher_mask_ssh1(1) & supported_ciphers & (1 << ssh_cipher_default))
1534 options.cipher = ssh_cipher_default;
1535 } else if (options.cipher == SSH_CIPHER_ILLEGAL ||
1536 !(cipher_mask_ssh1(1) & (1 << options.cipher))) {
1537 log("No valid SSH1 cipher, using %.100s instead.",
1538 cipher_name(ssh_cipher_default));
1539 options.cipher = ssh_cipher_default;
1541 /* Check that the selected cipher is supported. */
1542 if (!(supported_ciphers & (1 << options.cipher)))
1543 fatal("Selected cipher type %.100s not supported by server.",
1544 cipher_name(options.cipher));
1546 debug("Encryption type: %.100s", cipher_name(options.cipher));
1548 /* Send the encrypted session key to the server. */
1549 packet_start(SSH_CMSG_SESSION_KEY);
1550 packet_put_char(options.cipher);
1552 /* Send the cookie back to the server. */
1553 for (i = 0; i < 8; i++)
1554 packet_put_char(cookie[i]);
1556 /* Send and destroy the encrypted encryption key integer. */
1557 packet_put_bignum(key);
1560 /* Send protocol flags. */
1561 packet_put_int(client_flags);
1563 /* Send the packet now. */
1565 packet_write_wait();
1567 debug("Sent encrypted session key.");
1569 /* Set the encryption key. */
1570 packet_set_encryption_key(session_key, SSH_SESSION_KEY_LENGTH, options.cipher);
1572 /* We will no longer need the session key here. Destroy any extra copies. */
1573 memset(session_key, 0, sizeof(session_key));
1576 * Expect a success message from the server. Note that this message
1577 * will be received in encrypted form.
1579 packet_read_expect(SSH_SMSG_SUCCESS);
1581 debug("Received encrypted confirmation.");
1588 ssh_userauth1(const char *local_user, const char *server_user, char *host,
1589 Sensitive *sensitive)
1593 const char *save_server_user = NULL;
1598 krb5_context context = NULL;
1599 krb5_auth_context auth_context = NULL;
1603 if (supported_authentications == 0)
1604 fatal("ssh_userauth1: server supports no auth methods");
1608 /* if no user given, tack on the subject name after the server_user.
1609 * This will allow us to run gridmap early to get real user
1610 * This name will start with /C=
1612 if ((supported_authentications & (1 << SSH_AUTH_GSSAPI)) &&
1613 options.gss_authentication) {
1618 save_server_user = server_user;
1620 retname = get_gsi_name();
1623 debug("passing gssapi name '%s'", retname);
1625 newname = (char *) malloc(strlen(retname) + strlen(server_user) + 4);
1627 strcpy(newname, server_user);
1628 if(options.implicit) {
1629 strcat(newname,":i:");
1631 strcat(newname,":x:");
1633 strcat(newname, retname);
1634 server_user = newname;
1639 debug("server_user %s", server_user);
1644 /* Send the name of the user to log in as on the server. */
1645 packet_start(SSH_CMSG_USER);
1646 packet_put_cstring(server_user);
1648 packet_write_wait();
1651 if(save_server_user)
1653 server_user = save_server_user;
1657 * The server should respond with success if no authentication is
1658 * needed (the user has no password). Otherwise the server responds
1661 type = packet_read();
1663 /* check whether the connection was accepted without authentication. */
1664 if (type == SSH_SMSG_SUCCESS)
1666 if (type != SSH_SMSG_FAILURE)
1667 packet_disconnect("Protocol error: got %d in response to SSH_CMSG_USER", type);
1670 /* Try GSSAPI authentication */
1671 if ((supported_authentications & (1 << SSH_AUTH_GSSAPI)) &&
1672 options.gss_authentication)
1675 int gssapi_succeeded;
1676 debug("Trying GSSAPI authentication...");
1677 canonhost = xstrdup(get_canonical_hostname(1));
1678 resolve_localhost(&canonhost);
1679 gssapi_succeeded = try_gssapi_authentication(canonhost, &options);
1683 if (gssapi_succeeded) {
1684 type = packet_read();
1685 if (type == SSH_SMSG_SUCCESS)
1687 if (type != SSH_SMSG_FAILURE)
1688 packet_disconnect("Protocol error: got %d in response to GSSAPI auth", type);
1691 debug("GSSAPI authentication failed");
1696 if ((supported_authentications & (1 << SSH_AUTH_KERBEROS)) &&
1697 options.kerberos_authentication) {
1698 debug("Trying Kerberos v5 authentication.");
1700 if (try_krb5_authentication(&context, &auth_context)) {
1701 type = packet_read();
1702 if (type == SSH_SMSG_SUCCESS)
1704 if (type != SSH_SMSG_FAILURE)
1705 packet_disconnect("Protocol error: got %d in response to Kerberos v5 auth", type);
1711 if ((supported_authentications & (1 << SSH_AUTH_KERBEROS)) &&
1712 options.kerberos_authentication) {
1713 debug("Trying Kerberos v4 authentication.");
1715 if (try_krb4_authentication()) {
1716 type = packet_read();
1717 if (type == SSH_SMSG_SUCCESS)
1719 if (type != SSH_SMSG_FAILURE)
1720 packet_disconnect("Protocol error: got %d in response to Kerberos v4 auth", type);
1726 * Use rhosts authentication if running in privileged socket and we
1727 * do not wish to remain anonymous.
1729 if ((supported_authentications & (1 << SSH_AUTH_RHOSTS)) &&
1730 options.rhosts_authentication) {
1731 debug("Trying rhosts authentication.");
1732 packet_start(SSH_CMSG_AUTH_RHOSTS);
1733 packet_put_cstring(local_user);
1735 packet_write_wait();
1737 /* The server should respond with success or failure. */
1738 type = packet_read();
1739 if (type == SSH_SMSG_SUCCESS)
1741 if (type != SSH_SMSG_FAILURE)
1742 packet_disconnect("Protocol error: got %d in response to rhosts auth",
1746 * Try .rhosts or /etc/hosts.equiv authentication with RSA host
1749 if ((supported_authentications & (1 << SSH_AUTH_RHOSTS_RSA)) &&
1750 options.rhosts_rsa_authentication) {
1751 for (i = 0; i < sensitive->nkeys; i++) {
1752 if (sensitive->keys[i] != NULL &&
1753 sensitive->keys[i]->type == KEY_RSA1 &&
1754 try_rhosts_rsa_authentication(local_user,
1755 sensitive->keys[i]))
1759 /* Try RSA authentication if the server supports it. */
1760 if ((supported_authentications & (1 << SSH_AUTH_RSA)) &&
1761 options.rsa_authentication) {
1763 * Try RSA authentication using the authentication agent. The
1764 * agent is tried first because no passphrase is needed for
1765 * it, whereas identity files may require passphrases.
1767 if (try_agent_authentication())
1770 /* Try RSA authentication for each identity. */
1771 for (i = 0; i < options.num_identity_files; i++)
1772 if (options.identity_keys[i] != NULL &&
1773 options.identity_keys[i]->type == KEY_RSA1 &&
1774 try_rsa_authentication(i))
1777 /* Try challenge response authentication if the server supports it. */
1778 if ((supported_authentications & (1 << SSH_AUTH_TIS)) &&
1779 options.challenge_response_authentication && !options.batch_mode) {
1780 if (try_challenge_response_authentication())
1783 /* Try password authentication if the server supports it. */
1784 if ((supported_authentications & (1 << SSH_AUTH_PASSWORD)) &&
1785 options.password_authentication && !options.batch_mode) {
1788 snprintf(prompt, sizeof(prompt), "%.30s@%.128s's password: ",
1790 if (try_password_authentication(prompt))
1793 /* All authentication methods have failed. Exit with an error message. */
1794 fatal("Permission denied.");
1799 /* Try Kerberos v5 TGT passing. */
1800 if ((supported_authentications & (1 << SSH_PASS_KERBEROS_TGT)) &&
1801 options.kerberos_tgt_passing && context && auth_context) {
1802 if (options.cipher == SSH_CIPHER_NONE)
1803 log("WARNING: Encryption is disabled! Ticket will be transmitted in the clear!");
1804 send_krb5_tgt(context, auth_context);
1807 krb5_auth_con_free(context, auth_context);
1809 krb5_free_context(context);
1813 /* Try Kerberos v4 TGT passing if the server supports it. */
1814 if ((supported_authentications & (1 << SSH_PASS_KERBEROS_TGT)) &&
1815 options.kerberos_tgt_passing) {
1816 if (options.cipher == SSH_CIPHER_NONE)
1817 log("WARNING: Encryption is disabled! Ticket will be transmitted in the clear!");
1820 /* Try AFS token passing if the server supports it. */
1821 if ((supported_authentications & (1 << SSH_PASS_AFS_TOKEN)) &&
1822 options.afs_token_passing && k_hasafs()) {
1823 if (options.cipher == SSH_CIPHER_NONE)
1824 log("WARNING: Encryption is disabled! Token will be transmitted in the clear!");
1829 return; /* need statement after label */