Skip to content

Instantly share code, notes, and snippets.

@syldrathecat
Last active March 28, 2016 13:13
Show Gist options
  • Save syldrathecat/e0c8d78d43ebed092907 to your computer and use it in GitHub Desktop.
Save syldrathecat/e0c8d78d43ebed092907 to your computer and use it in GitHub Desktop.
#include <glib.h>
// libpurple
#include "debug.h"
#include "plugin.h"
#include "sslconn.h"
#include "version.h"
// NSS
#include <ssl.h>
#define FLIST_NSSFIX_PLUGIN_ID "flist_nssfix"
typedef struct
{
PRFileDesc *fd;
PRFileDesc *in;
guint handshake_handler;
guint handshake_timer;
} nssfixPurpleSslNssData;
static PurpleSslOps new_ops = { };
static void (*original_connectfunc)(PurpleSslConnection *gsc) = NULL;
void hooked_connectfunc(PurpleSslConnection *gsc)
{
if (purple_debug_is_verbose())
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Running hooked connectfunc\n");
original_connectfunc(gsc);
nssfixPurpleSslNssData *nss_data = gsc->private_data;
if (purple_debug_is_verbose())
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Setting Peer ID: %s\n", gsc->host);
SSL_SetSockPeerID(nss_data->in, gsc->host);
}
static gboolean
plugin_load(PurplePlugin *plugin)
{
if (strcmp(NSSSSL_GetVersion(), "3.23") >= 0)
{
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Doing nothing - NSS is version 3.23 or later\n");
return TRUE;
}
PurpleSslOps *current_opts = purple_ssl_get_ops();
if (!current_opts)
{
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Doing nothing - SSL operations were not set\n");
return TRUE;
}
memcpy(&new_ops, current_opts, sizeof(PurpleSslOps));
if (original_connectfunc != NULL || new_ops.connectfunc == hooked_connectfunc)
{
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Doing nothing - SSL operations were already hooked\n");
return TRUE;
}
original_connectfunc = new_ops.connectfunc;
new_ops.connectfunc = hooked_connectfunc;
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Hooking SSL operations\n");
purple_ssl_set_ops(&new_ops);
return TRUE;
}
static gboolean
plugin_unload(PurplePlugin *plugin)
{
if (original_connectfunc != NULL)
{
new_ops.connectfunc = original_connectfunc;
purple_debug_info(FLIST_NSSFIX_PLUGIN_ID, "Un-hooking SSL operations\n");
purple_ssl_set_ops(&new_ops);
original_connectfunc = NULL;
}
return TRUE;
}
static PurplePluginInfo info =
{
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD, /**< type */
NULL, /**< ui_requirement */
0, /**< flags */
NULL, /**< dependencies */
PURPLE_PRIORITY_HIGHEST, /**< priority */
FLIST_NSSFIX_PLUGIN_ID, /**< id */
"FList NSS Fix", /**< name */
"1.0", /**< version */
/** summary */
"Hacky plugin to fix an issue with pre-3.23 versions of NSS",
/** description */
"Hacky plugin to fix an issue with pre-3.23 versions of NSS",
"SyldraTheCat",
"https://f-list.net/", /**< homepage */
plugin_load, /**< load */
plugin_unload, /**< unload */
NULL, /**< destroy */
NULL, /**< ui_info */
NULL, /**< extra_info */
NULL,
NULL,
/* padding */
NULL,
NULL,
NULL,
NULL
};
static GList dependency_ssl_nss =
{
"ssl-nss",
NULL,
NULL
};
static void
init_plugin(PurplePlugin *plugin)
{
plugin->info->dependencies = &dependency_ssl_nss;
}
PURPLE_INIT_PLUGIN(flist_nssfix, init_plugin, info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment