changeset 19071:d224a1e4b919

- x509_nss get_subject_name (x509_common_name)
author William Ehlhardt <williamehlhardt@gmail.com>
date Fri, 03 Aug 2007 07:26:32 +0000
parents 7ccb5ab3e07e
children 4bdf4ce3473b
files libpurple/plugins/ssl/ssl-nss.c
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-nss.c	Fri Aug 03 07:11:06 2007 +0000
+++ b/libpurple/plugins/ssl/ssl-nss.c	Fri Aug 03 07:26:32 2007 +0000
@@ -479,7 +479,33 @@
 static gchar *
 x509_common_name (PurpleCertificate *crt)
 {
-	return NULL;
+	CERTCertificate *crt_dat;
+	char *nss_cn;
+	gchar *ret_cn;
+	
+	g_return_val_if_fail(crt, NULL);
+	g_return_val_if_fail(crt->scheme == &x509_nss, NULL);
+
+	crt_dat = X509_NSS_DATA(crt);
+	g_return_val_if_fail(crt_dat, NULL);
+
+	/* Q:
+	   Why get a newly allocated string out of NSS, strdup it, and then
+	   return the new copy?
+
+	   A:
+	   The NSS LXR docs state that I should use the NSPR free functions on
+	   the strings that the NSS cert functions return. Since the libpurple
+	   API expects a g_free()-able string, we make our own copy and return
+	   that.
+
+	   NSPR is something of a prima donna. */
+
+	nss_cn = CERT_GetCommonName( &(crt_dat->subject) );
+	ret_cn = g_strdup(nss_cn);
+	PORT_Free(nss_cn);
+
+	return ret_cn;
 }
 
 static gboolean