pidgin/pidgin

Parents 2408742b4c06
Children 4b8cc47d05da
jabber: Rework jabber_caps_calculate_hash() to allow any size digest

jabber_caps_calculate_hash() previously only allowed hash digests of
up to 20 bytes. There was a note stating to check the size if any
new hashes were used since the cipher API at the time of that writing
didn't include a way to get the size of the hash digest. Now that
it's been ported to GChecksum, which does include such a function,
it can be made to support any size hash digest. This patch does so.
--- a/libpurple/protocols/jabber/caps.c Thu Jun 01 19:09:16 2017 -0500
+++ b/libpurple/protocols/jabber/caps.c Fri Jun 02 15:09:01 2017 -0500
@@ -455,11 +455,7 @@
if (userdata->hash) {
gchar *hash = NULL;
GChecksumType hash_type = G_CHECKSUM_SHA1;
- /*
- * TODO: If you add *any* hash here, make sure the checksum buffer
- * size in jabber_caps_calculate_hash is large enough. The cipher API
- * doesn't seem to offer a "Get the hash size" function(?).
- */
+
if (g_str_equal(userdata->hash, "sha-1")) {
hash_type = G_CHECKSUM_SHA1;
} else if (g_str_equal(userdata->hash, "md5")) {
@@ -832,8 +828,9 @@
{
GChecksum *hash;
GList *node;
- guint8 checksum[20];
- gsize checksum_size = 20;
+ guint8 *checksum;
+ gsize checksum_size;
+ gchar *ret;
if (!info)
return NULL;
@@ -915,10 +912,16 @@
}
}
+ checksum_size = g_checksum_type_get_length(hash_type);
+ checksum = g_new(guint8, checksum_size);
+
/* generate hash */
g_checksum_get_digest(hash, checksum, &checksum_size);
- return purple_base64_encode(checksum, checksum_size);
+ ret = purple_base64_encode(checksum, checksum_size);
+ g_free(checksum);
+
+ return ret;
}
void jabber_caps_calculate_own_hash(JabberStream *js) {