pidgin: d2bd7113: Add GnuTLS support for exporting DER dat...

qulogic at pidgin.im qulogic at pidgin.im
Thu Dec 22 21:25:48 EST 2011


----------------------------------------------------------------------
Revision: d2bd7113cc8d907c6e79a25e829de581ea302814
Parent:   3d32666bcc77cb7ef618be30d7de24663ae04089
Author:   qulogic at pidgin.im
Date:     12/22/11 21:05:09
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d2bd7113cc8d907c6e79a25e829de581ea302814

Changelog: 

Add GnuTLS support for exporting DER data.

Changes against parent 3d32666bcc77cb7ef618be30d7de24663ae04089

  patched  libpurple/plugins/ssl/ssl-gnutls.c

-------------- next part --------------
============================================================
--- libpurple/plugins/ssl/ssl-gnutls.c	1da6bdaf868c12329feac7b2dd7141f296a984ea
+++ libpurple/plugins/ssl/ssl-gnutls.c	109587e7087179a687b2378e342d299a73a53e68
@@ -1142,6 +1142,37 @@ x509_times (PurpleCertificate *crt, time
 	return success;
 }
 
+static GByteArray *
+x509_get_der_data(PurpleCertificate *crt)
+{
+	gnutls_x509_crt crt_dat;
+	GByteArray *data;
+	size_t len;
+	int ret;
+
+	crt_dat = X509_GET_GNUTLS_DATA(crt);
+	g_return_val_if_fail(crt_dat, NULL);
+
+	/* Obtain the output size required */
+	len = 0;
+	ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_DER, NULL, &len);
+	g_return_val_if_fail(ret == GNUTLS_E_SHORT_MEMORY_BUFFER, NULL);
+
+	/* Now allocate a buffer and *really* export it */
+	data = g_byte_array_sized_new(len);
+	data->len = len;
+	ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_DER, data->data, &len);
+	if (ret != 0) {
+		purple_debug_error("gnutls/x509",
+		                   "Failed to export cert to buffer with code %d\n",
+		                   ret);
+		g_byte_array_free(data, TRUE);
+		return NULL;
+	}
+
+	return data;
+}
+
 /* X.509 certificate operations provided by this plugin */
 static PurpleCertificateScheme x509_gnutls = {
 	"x509",                          /* Scheme name */
@@ -1158,9 +1189,9 @@ static PurpleCertificateScheme x509_gnut
 	x509_check_name,                 /* Check subject name */
 	x509_times,                      /* Activation/Expiration time */
 	x509_importcerts_from_file,      /* Multiple certificates import function */
+	x509_get_der_data,               /* Binary DER data */
 
 	NULL,
-	NULL,
 	NULL
 
 };


More information about the Commits mailing list