changeset 19273:db42632ac756

- Add x509_import_from_file
author William Ehlhardt <williamehlhardt@gmail.com>
date Fri, 17 Aug 2007 08:45:02 +0000
parents c861705e934b
children 6913d4dbc25b
files libpurple/plugins/ssl/ssl-nss.c
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-nss.c	Fri Aug 17 08:36:33 2007 +0000
+++ b/libpurple/plugins/ssl/ssl-nss.c	Fri Aug 17 08:45:02 2007 +0000
@@ -394,8 +394,35 @@
 static PurpleCertificate *
 x509_import_from_file(const gchar *filename)
 {
-	/* TODO: Write me! */
-	return NULL;
+	gchar *rawcert;
+	gsize len = 0;
+	CERTCertificate *crt_dat;
+	PurpleCertificate *crt;
+
+	g_return_val_if_fail(filename, NULL);
+
+	purple_debug_info("nss/x509",
+			  "Loading certificate from %s\n",
+			  filename);
+	
+	/* Load the raw data up */
+	g_return_val_if_fail(
+		g_file_get_contents(filename,
+				    &rawcert, &len,
+				    NULL ),
+		NULL);
+
+	/* Decode the certificate */
+	crt_dat = CERT_DecodeCertFromPackage(rawcert, len);
+	g_free(rawcert);
+
+	g_return_val_if_fail(crt_dat, NULL);
+	
+	crt = g_new0(PurpleCertificate, 1);
+	crt->scheme = &x509_nss;
+	crt->data = crt_dat;
+	
+	return crt;
 }
 
 /**