comparison libpurple/protocols/jabber/auth.c @ 27463:f541583e31bd

More uniformity among disconnect error messages
author Mark Doliner <mark@kingant.net>
date Mon, 06 Jul 2009 09:07:42 +0000
parents c4e5ba03ff73
children c585572e80dd
comparison
equal deleted inserted replaced
27462:1bbed9fd046b 27463:f541583e31bd
50 if(purple_ssl_is_supported()) { 50 if(purple_ssl_is_supported()) {
51 jabber_send_raw(js, 51 jabber_send_raw(js,
52 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); 52 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1);
53 return TRUE; 53 return TRUE;
54 } else if(xmlnode_get_child(starttls, "required")) { 54 } else if(xmlnode_get_child(starttls, "required")) {
55 purple_connection_error_reason (js->gc, 55 purple_connection_error_reason(js->gc,
56 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, 56 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
57 _("Server requires TLS/SSL, but no TLS/SSL support was found.")); 57 _("Server requires TLS/SSL, but no TLS/SSL support was found."));
58 return TRUE; 58 return TRUE;
59 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE)) { 59 } else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE)) {
60 purple_connection_error_reason (js->gc, 60 purple_connection_error_reason(js->gc,
61 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, 61 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
62 _("You require encryption, but no TLS/SSL support was found.")); 62 _("You require encryption, but no TLS/SSL support was found."));
63 return TRUE; 63 return TRUE;
64 } 64 }
65 } 65 }
120 finish_plaintext_authentication(account->gc->proto_data); 120 finish_plaintext_authentication(account->gc->proto_data);
121 } 121 }
122 122
123 static void disallow_plaintext_auth(PurpleAccount *account) 123 static void disallow_plaintext_auth(PurpleAccount *account)
124 { 124 {
125 purple_connection_error_reason (account->gc, 125 purple_connection_error_reason(account->gc,
126 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, 126 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR,
127 _("Server requires plaintext authentication over an unencrypted stream")); 127 _("Server requires plaintext authentication over an unencrypted stream"));
128 } 128 }
129 129
130 #ifdef HAVE_CYRUS_SASL 130 #ifdef HAVE_CYRUS_SASL
413 } 413 }
414 } 414 }
415 jabber_send(js, auth); 415 jabber_send(js, auth);
416 xmlnode_free(auth); 416 xmlnode_free(auth);
417 } else { 417 } else {
418 purple_connection_error_reason (js->gc, 418 purple_connection_error_reason(js->gc,
419 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, 419 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
420 _("SASL authentication failed")); 420 _("SASL authentication failed"));
421 } 421 }
422 } 422 }
423 423
488 } 488 }
489 489
490 mechs = xmlnode_get_child(packet, "mechanisms"); 490 mechs = xmlnode_get_child(packet, "mechanisms");
491 491
492 if(!mechs) { 492 if(!mechs) {
493 purple_connection_error_reason (js->gc, 493 purple_connection_error_reason(js->gc,
494 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 494 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
495 _("Invalid response from server.")); 495 _("Invalid response from server"));
496 return; 496 return;
497 } 497 }
498 498
499 #ifdef HAVE_CYRUS_SASL 499 #ifdef HAVE_CYRUS_SASL
500 js->sasl_mechs = g_string_new(""); 500 js->sasl_mechs = g_string_new("");
559 g_free(msg); 559 g_free(msg);
560 return; 560 return;
561 } 561 }
562 finish_plaintext_authentication(js); 562 finish_plaintext_authentication(js);
563 } else { 563 } else {
564 purple_connection_error_reason (js->gc, 564 purple_connection_error_reason(js->gc,
565 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, 565 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
566 _("Server does not use any supported authentication method")); 566 _("Server does not use any supported authentication method"));
567 } 567 }
568 #endif 568 #endif
569 } 569 }
588 /* Clear the pasword if it isn't being saved */ 588 /* Clear the pasword if it isn't being saved */
589 if (!purple_account_get_remember_password(js->gc->account)) 589 if (!purple_account_get_remember_password(js->gc->account))
590 purple_account_set_password(js->gc->account, NULL); 590 purple_account_set_password(js->gc->account, NULL);
591 } 591 }
592 592
593 purple_connection_error_reason (js->gc, reason, msg); 593 purple_connection_error_reason(js->gc, reason, msg);
594 g_free(msg); 594 g_free(msg);
595 } 595 }
596 } 596 }
597 597
598 static void auth_old_cb(JabberStream *js, const char *from, 598 static void auth_old_cb(JabberStream *js, const char *from,
604 const char *pw = purple_connection_get_password(js->gc); 604 const char *pw = purple_connection_get_password(js->gc);
605 605
606 if (type == JABBER_IQ_ERROR) { 606 if (type == JABBER_IQ_ERROR) {
607 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; 607 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
608 char *msg = jabber_parse_error(js, packet, &reason); 608 char *msg = jabber_parse_error(js, packet, &reason);
609 purple_connection_error_reason (js->gc, reason, msg); 609 purple_connection_error_reason(js->gc, reason, msg);
610 g_free(msg); 610 g_free(msg);
611 } else if (type == JABBER_IQ_RESULT) { 611 } else if (type == JABBER_IQ_RESULT) {
612 query = xmlnode_get_child(packet, "query"); 612 query = xmlnode_get_child(packet, "query");
613 if(js->stream_id && xmlnode_get_child(query, "digest")) { 613 if(js->stream_id && xmlnode_get_child(query, "digest")) {
614 char *s, *hash; 614 char *s, *hash;
674 g_free(msg); 674 g_free(msg);
675 return; 675 return;
676 } 676 }
677 finish_plaintext_authentication(js); 677 finish_plaintext_authentication(js);
678 } else { 678 } else {
679 purple_connection_error_reason (js->gc, 679 purple_connection_error_reason(js->gc,
680 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, 680 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
681 _("Server does not use any supported authentication method")); 681 _("Server does not use any supported authentication method"));
682 return; 682 return;
683 } 683 }
684 } 684 }
693 * <stream:features/> and we're not using old-style SSL. If the user 693 * <stream:features/> and we're not using old-style SSL. If the user
694 * is requiring SSL/TLS, we need to enforce it. 694 * is requiring SSL/TLS, we need to enforce it.
695 */ 695 */
696 if (!jabber_stream_is_ssl(js) && 696 if (!jabber_stream_is_ssl(js) &&
697 purple_account_get_bool(purple_connection_get_account(js->gc), "require_tls", FALSE)) { 697 purple_account_get_bool(purple_connection_get_account(js->gc), "require_tls", FALSE)) {
698 purple_connection_error_reason (js->gc, 698 purple_connection_error_reason(js->gc,
699 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, 699 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR,
700 _("You require encryption, but it is not available on this server.")); 700 _("You require encryption, but it is not available on this server."));
701 return; 701 return;
702 } 702 }
703 703
854 char *dec_in; 854 char *dec_in;
855 char *enc_out; 855 char *enc_out;
856 GHashTable *parts; 856 GHashTable *parts;
857 857
858 if(!enc_in) { 858 if(!enc_in) {
859 purple_connection_error_reason (js->gc, 859 purple_connection_error_reason(js->gc,
860 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 860 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
861 _("Invalid response from server.")); 861 _("Invalid response from server"));
862 return; 862 return;
863 } 863 }
864 864
865 dec_in = (char *)purple_base64_decode(enc_in, NULL); 865 dec_in = (char *)purple_base64_decode(enc_in, NULL);
866 purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded challenge (%" 866 purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded challenge (%"
877 !strcmp(rspauth, js->expected_rspauth)) { 877 !strcmp(rspauth, js->expected_rspauth)) {
878 jabber_send_raw(js, 878 jabber_send_raw(js,
879 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", 879 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />",
880 -1); 880 -1);
881 } else { 881 } else {
882 purple_connection_error_reason (js->gc, 882 purple_connection_error_reason(js->gc,
883 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 883 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
884 _("Invalid challenge from server")); 884 _("Invalid challenge from server"));
885 } 885 }
886 g_free(js->expected_rspauth); 886 g_free(js->expected_rspauth);
887 js->expected_rspauth = NULL; 887 js->expected_rspauth = NULL;
903 realm = g_hash_table_lookup(parts, "realm"); 903 realm = g_hash_table_lookup(parts, "realm");
904 if(!realm) 904 if(!realm)
905 realm = js->user->domain; 905 realm = js->user->domain;
906 906
907 if (nonce == NULL || realm == NULL) 907 if (nonce == NULL || realm == NULL)
908 purple_connection_error_reason (js->gc, 908 purple_connection_error_reason(js->gc,
909 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 909 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
910 _("Invalid challenge from server")); 910 _("Invalid challenge from server"));
911 else { 911 else {
912 GString *response = g_string_new(""); 912 GString *response = g_string_new("");
913 char *a2; 913 char *a2;
978 js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, 978 js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen,
979 NULL, &c_out, &clen); 979 NULL, &c_out, &clen);
980 g_free(enc_in); 980 g_free(enc_in);
981 g_free(dec_in); 981 g_free(dec_in);
982 if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) { 982 if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) {
983 purple_debug_error("jabber", "Error is %d : %s\n",js->sasl_state,sasl_errdetail(js->sasl)); 983 gchar *tmp = g_strdup_printf(_("SASL error: %s"),
984 purple_connection_error_reason (js->gc, 984 sasl_errdetail(js->sasl));
985 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 985 purple_debug_error("jabber", "Error is %d : %s\n",
986 _("SASL error")); 986 js->sasl_state, sasl_errdetail(js->sasl));
987 purple_connection_error_reason(js->gc,
988 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
989 g_free(tmp);
987 return; 990 return;
988 } else { 991 } else {
989 response = xmlnode_new("response"); 992 response = xmlnode_new("response");
990 xmlnode_set_namespace(response, "urn:ietf:params:xml:ns:xmpp-sasl"); 993 xmlnode_set_namespace(response, "urn:ietf:params:xml:ns:xmpp-sasl");
991 if (clen > 0) { 994 if (clen > 0) {
1023 #ifdef HAVE_CYRUS_SASL 1026 #ifdef HAVE_CYRUS_SASL
1024 const void *x; 1027 const void *x;
1025 #endif 1028 #endif
1026 1029
1027 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) { 1030 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
1028 purple_connection_error_reason (js->gc, 1031 purple_connection_error_reason(js->gc,
1029 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1032 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1030 _("Invalid response from server.")); 1033 _("Invalid response from server"));
1031 return; 1034 return;
1032 } 1035 }
1033 1036
1034 #ifdef HAVE_CYRUS_SASL 1037 #ifdef HAVE_CYRUS_SASL
1035 /* The SASL docs say that if the client hasn't returned OK yet, we 1038 /* The SASL docs say that if the client hasn't returned OK yet, we
1050 g_free(enc_in); 1053 g_free(enc_in);
1051 g_free(dec_in); 1054 g_free(dec_in);
1052 1055
1053 if (js->sasl_state != SASL_OK) { 1056 if (js->sasl_state != SASL_OK) {
1054 /* This should never happen! */ 1057 /* This should never happen! */
1055 purple_connection_error_reason (js->gc, 1058 purple_connection_error_reason(js->gc,
1056 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1059 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1057 _("Invalid response from server.")); 1060 _("Invalid response from server"));
1058 } 1061 }
1059 } 1062 }
1060 /* If we've negotiated a security layer, we need to enable it */ 1063 /* If we've negotiated a security layer, we need to enable it */
1061 if (js->sasl) { 1064 if (js->sasl) {
1062 sasl_getprop(js->sasl, SASL_SSF, &x); 1065 sasl_getprop(js->sasl, SASL_SSF, &x);
1096 } 1099 }
1097 } 1100 }
1098 #endif 1101 #endif
1099 msg = jabber_parse_error(js, packet, &reason); 1102 msg = jabber_parse_error(js, packet, &reason);
1100 if(!msg) { 1103 if(!msg) {
1101 purple_connection_error_reason (js->gc, 1104 purple_connection_error_reason(js->gc,
1102 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1105 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1103 _("Invalid response from server.")); 1106 _("Invalid response from server"));
1104 } else { 1107 } else {
1105 purple_connection_error_reason (js->gc, reason, msg); 1108 purple_connection_error_reason(js->gc, reason, msg);
1106 g_free(msg); 1109 g_free(msg);
1107 } 1110 }
1108 } 1111 }