Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/xmpp.c @ 2248:377b6a52b25f
Prepare for loudmouth with sha256 support (>=1.5.3)
author | franky |
---|---|
date | Sat, 13 Feb 2016 11:05:07 +0100 |
parents | fe89cdd66446 |
children | df5837a72b35 |
comparison
equal
deleted
inserted
replaced
2247:fe89cdd66446 | 2248:377b6a52b25f |
---|---|
42 #include "main.h" | 42 #include "main.h" |
43 #include "carbons.h" | 43 #include "carbons.h" |
44 | 44 |
45 #define RECONNECTION_TIMEOUT 60L | 45 #define RECONNECTION_TIMEOUT 60L |
46 | 46 |
47 #define FINGERPRINT_LENGTH 16 // Currently Loudmouth only supports MD5 | 47 #ifndef LOUDMOUTH_USES_SHA256 |
48 #define FINGERPRINT_LENGTH 16 // old loudmouth still uses MD5 :( | |
49 #endif | |
48 | 50 |
49 LmConnection* lconnection = NULL; | 51 LmConnection* lconnection = NULL; |
50 static guint AutoConnection; | 52 static guint AutoConnection; |
51 | 53 |
52 inline void update_last_use(void); | 54 inline void update_last_use(void); |
721 case LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH: | 723 case LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH: |
722 scr_LogPrint(LPRINT_LOGNORM, | 724 scr_LogPrint(LPRINT_LOGNORM, |
723 "Certificate hostname does not match expected hostname!"); | 725 "Certificate hostname does not match expected hostname!"); |
724 break; | 726 break; |
725 case LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH: { | 727 case LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH: { |
728 #ifndef LOUDMOUTH_USES_SHA256 | |
726 char fpr[3*FINGERPRINT_LENGTH] = {0}; | 729 char fpr[3*FINGERPRINT_LENGTH] = {0}; |
727 fingerprint_to_hex(lm_ssl_get_fingerprint(ssl), fpr, FINGERPRINT_LENGTH); | 730 fingerprint_to_hex(lm_ssl_get_fingerprint(ssl), fpr, FINGERPRINT_LENGTH); |
731 #endif | |
728 scr_LogPrint(LPRINT_LOGNORM, | 732 scr_LogPrint(LPRINT_LOGNORM, |
729 "Certificate fingerprint does not match expected fingerprint!"); | 733 "Certificate fingerprint does not match expected fingerprint!"); |
734 #ifndef LOUDMOUTH_USES_SHA256 | |
730 scr_LogPrint(LPRINT_LOGNORM, "Remote fingerprint: %s", fpr); | 735 scr_LogPrint(LPRINT_LOGNORM, "Remote fingerprint: %s", fpr); |
731 | 736 #else |
732 scr_LogPrint(LPRINT_LOGNORM, "Expected fingerprint: %s", | 737 scr_LogPrint(LPRINT_LOGNORM, "Remote fingerprint: %s", lm_ssl_get_fingerprint(ssl)); |
738 #endif | |
739 | |
740 scr_LogPrint(LPRINT_LOGNORM, "Expect fingerprint: %s", | |
733 settings_opt_get("ssl_fingerprint")); | 741 settings_opt_get("ssl_fingerprint")); |
734 | 742 |
735 return LM_SSL_RESPONSE_STOP; | 743 return LM_SSL_RESPONSE_STOP; |
736 } | 744 } |
737 break; | 745 break; |
750 static void connection_auth_cb(LmConnection *connection, gboolean success, | 758 static void connection_auth_cb(LmConnection *connection, gboolean success, |
751 gpointer user_data) | 759 gpointer user_data) |
752 { | 760 { |
753 LmSSL *lssl; | 761 LmSSL *lssl; |
754 if ((lssl = lm_connection_get_ssl(connection)) != NULL) { | 762 if ((lssl = lm_connection_get_ssl(connection)) != NULL) { |
763 #ifndef LOUDMOUTH_USES_SHA256 | |
755 char fpr[3*FINGERPRINT_LENGTH] = {0}; | 764 char fpr[3*FINGERPRINT_LENGTH] = {0}; |
756 fingerprint_to_hex(lm_ssl_get_fingerprint(lssl), fpr, FINGERPRINT_LENGTH); | 765 fingerprint_to_hex(lm_ssl_get_fingerprint(lssl), fpr, FINGERPRINT_LENGTH); |
757 scr_LogPrint(LPRINT_LOGNORM, "Connection established.\n" | 766 scr_LogPrint(LPRINT_LOGNORM, "Connection established.\n" |
758 "Remote fingerprint: %s", fpr); | 767 "Remote fingerprint: %s", fpr); |
768 #else | |
769 scr_LogPrint(LPRINT_LOGNORM, "Connection established.\n" | |
770 "Remote fingerprint: %s", lm_ssl_get_fingerprint(lssl)); | |
771 #endif | |
759 } | 772 } |
760 | 773 |
761 if (success) { | 774 if (success) { |
762 xmpp_iq_request(NULL, NS_ROSTER); | 775 xmpp_iq_request(NULL, NS_ROSTER); |
763 xmpp_iq_request(NULL, NS_DISCO_INFO); | 776 xmpp_iq_request(NULL, NS_DISCO_INFO); |
1755 // (no JID, no password, etc.) | 1768 // (no JID, no password, etc.) |
1756 gint xmpp_connect(void) | 1769 gint xmpp_connect(void) |
1757 { | 1770 { |
1758 const char *userjid, *password, *resource, *servername, *ssl_fpr; | 1771 const char *userjid, *password, *resource, *servername, *ssl_fpr; |
1759 char *dynresource = NULL; | 1772 char *dynresource = NULL; |
1773 #ifndef LOUDMOUTH_USES_SHA256 | |
1760 char fpr[FINGERPRINT_LENGTH] = {0}; | 1774 char fpr[FINGERPRINT_LENGTH] = {0}; |
1775 #endif | |
1761 const char *proxy_host; | 1776 const char *proxy_host; |
1762 const char *resource_prefix = PACKAGE_NAME; | 1777 const char *resource_prefix = PACKAGE_NAME; |
1763 char *fjid; | 1778 char *fjid; |
1764 int ssl, tls; | 1779 int ssl, tls; |
1765 LmSSL *lssl; | 1780 LmSSL *lssl; |
1900 | 1915 |
1901 if (!port) | 1916 if (!port) |
1902 port = (ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT); | 1917 port = (ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT); |
1903 lm_connection_set_port(lconnection, port); | 1918 lm_connection_set_port(lconnection, port); |
1904 | 1919 |
1920 #ifndef LOUDMOUTH_USES_SHA256 | |
1905 if (ssl_fpr && (!hex_to_fingerprint(ssl_fpr, fpr, FINGERPRINT_LENGTH))) { | 1921 if (ssl_fpr && (!hex_to_fingerprint(ssl_fpr, fpr, FINGERPRINT_LENGTH))) { |
1906 scr_LogPrint(LPRINT_LOGNORM, "** Please set the fingerprint in the format " | 1922 scr_LogPrint(LPRINT_LOGNORM, "** Please set the fingerprint in the format " |
1907 "97:5C:00:3F:1D:77:45:25:E2:C5:70:EC:83:C8:87:EE"); | 1923 "97:5C:00:3F:1D:77:45:25:E2:C5:70:EC:83:C8:87:EE"); |
1908 return -1; | 1924 return -1; |
1909 } | 1925 } |
1910 | 1926 |
1911 lssl = lm_ssl_new((ssl_fpr ? fpr : NULL), ssl_cb, NULL, NULL); | 1927 lssl = lm_ssl_new((ssl_fpr ? fpr : NULL), ssl_cb, NULL, NULL); |
1928 #else | |
1929 lssl = lm_ssl_new(ssl_fpr, ssl_cb, NULL, NULL); | |
1930 #endif | |
1912 if (lssl) { | 1931 if (lssl) { |
1913 #ifdef HAVE_LM_SSL_CIPHER_LIST | 1932 #ifdef HAVE_LM_SSL_CIPHER_LIST |
1914 const char *ssl_ciphers = settings_opt_get("ssl_ciphers"); | 1933 const char *ssl_ciphers = settings_opt_get("ssl_ciphers"); |
1915 lm_ssl_set_cipher_list(lssl, ssl_ciphers); | 1934 lm_ssl_set_cipher_list(lssl, ssl_ciphers); |
1916 #endif | 1935 #endif |