comparison mcabber/mcabber/xmpp.c @ 2203:170597f5365b

Use more generic routines to convert fingerprints to/from hexadecimal This is a first step towards non-MD5 fingerprints; now we need Loudmouth support...
author Mikael Berthe <mikael@lilotux.net>
date Mon, 12 Oct 2015 17:19:19 +0200
parents 527ba1c1873e
children 412322678d59
comparison
equal deleted inserted replaced
2202:ff18feb75a6d 2203:170597f5365b
41 #include "utils.h" 41 #include "utils.h"
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
47 #define FINGERPRINT_LENGTH 16 // Currently Loudmouth only supports MD5
46 48
47 LmConnection* lconnection = NULL; 49 LmConnection* lconnection = NULL;
48 static guint AutoConnection; 50 static guint AutoConnection;
49 51
50 inline void update_last_use(void); 52 inline void update_last_use(void);
712 case LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH: 714 case LM_SSL_STATUS_CERT_HOSTNAME_MISMATCH:
713 scr_LogPrint(LPRINT_LOGNORM, 715 scr_LogPrint(LPRINT_LOGNORM,
714 "Certificate hostname does not match expected hostname!"); 716 "Certificate hostname does not match expected hostname!");
715 break; 717 break;
716 case LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH: { 718 case LM_SSL_STATUS_CERT_FINGERPRINT_MISMATCH: {
717 char fpr[49] = {0}; 719 char fpr[3*FINGERPRINT_LENGTH] = {0};
718 fingerprint_to_hex(lm_ssl_get_fingerprint(ssl), fpr); 720 fingerprint_to_hex(lm_ssl_get_fingerprint(ssl), fpr, FINGERPRINT_LENGTH);
719 scr_LogPrint(LPRINT_LOGNORM, 721 scr_LogPrint(LPRINT_LOGNORM,
720 "Certificate fingerprint does not match expected fingerprint!"); 722 "Certificate fingerprint does not match expected fingerprint!");
721 scr_LogPrint(LPRINT_LOGNORM, "Remote fingerprint: %s", fpr); 723 scr_LogPrint(LPRINT_LOGNORM, "Remote fingerprint: %s", fpr);
722 724
723 scr_LogPrint(LPRINT_LOGNORM, "Expected fingerprint: %s", 725 scr_LogPrint(LPRINT_LOGNORM, "Expected fingerprint: %s",
741 static void connection_auth_cb(LmConnection *connection, gboolean success, 743 static void connection_auth_cb(LmConnection *connection, gboolean success,
742 gpointer user_data) 744 gpointer user_data)
743 { 745 {
744 LmSSL *lssl; 746 LmSSL *lssl;
745 if ((lssl = lm_connection_get_ssl(connection)) != NULL) { 747 if ((lssl = lm_connection_get_ssl(connection)) != NULL) {
746 char fpr[49] = {0}; 748 char fpr[3*FINGERPRINT_LENGTH] = {0};
747 fingerprint_to_hex(lm_ssl_get_fingerprint(lssl), fpr); 749 fingerprint_to_hex(lm_ssl_get_fingerprint(lssl), fpr, FINGERPRINT_LENGTH);
748 scr_LogPrint(LPRINT_LOGNORM, "Connection established.\n" 750 scr_LogPrint(LPRINT_LOGNORM, "Connection established.\n"
749 "Remote fingerprint: %s", fpr); 751 "Remote fingerprint: %s", fpr);
750 } 752 }
751 753
752 if (success) { 754 if (success) {
1736 // (no JID, no password, etc.) 1738 // (no JID, no password, etc.)
1737 gint xmpp_connect(void) 1739 gint xmpp_connect(void)
1738 { 1740 {
1739 const char *userjid, *password, *resource, *servername, *ssl_fpr; 1741 const char *userjid, *password, *resource, *servername, *ssl_fpr;
1740 char *dynresource = NULL; 1742 char *dynresource = NULL;
1741 char fpr[17] = {0}; 1743 char fpr[FINGERPRINT_LENGTH] = {0};
1742 const char *proxy_host; 1744 const char *proxy_host;
1743 const char *resource_prefix = PACKAGE_NAME; 1745 const char *resource_prefix = PACKAGE_NAME;
1744 char *fjid; 1746 char *fjid;
1745 int ssl, tls; 1747 int ssl, tls;
1746 LmSSL *lssl; 1748 LmSSL *lssl;
1881 1883
1882 if (!port) 1884 if (!port)
1883 port = (ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT); 1885 port = (ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT);
1884 lm_connection_set_port(lconnection, port); 1886 lm_connection_set_port(lconnection, port);
1885 1887
1886 if (ssl_fpr && (!hex_to_fingerprint(ssl_fpr, fpr))) { 1888 if (ssl_fpr && (!hex_to_fingerprint(ssl_fpr, fpr, FINGERPRINT_LENGTH))) {
1887 scr_LogPrint(LPRINT_LOGNORM, "** Please set the fingerprint in the format " 1889 scr_LogPrint(LPRINT_LOGNORM, "** Please set the fingerprint in the format "
1888 "97:5C:00:3F:1D:77:45:25:E2:C5:70:EC:83:C8:87:EE"); 1890 "97:5C:00:3F:1D:77:45:25:E2:C5:70:EC:83:C8:87:EE");
1889 return -1; 1891 return -1;
1890 } 1892 }
1891 1893