changeset 19074:3004bfa0e846

- x509_nss sha1sum
author William Ehlhardt <williamehlhardt@gmail.com>
date Fri, 03 Aug 2007 08:30:26 +0000
parents 2156321c5482
children a0138be8d725
files libpurple/plugins/ssl/ssl-nss.c
diffstat 1 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-nss.c	Fri Aug 03 07:43:40 2007 +0000
+++ b/libpurple/plugins/ssl/ssl-nss.c	Fri Aug 03 08:30:26 2007 +0000
@@ -473,7 +473,35 @@
 static GByteArray *
 x509_sha1sum(PurpleCertificate *crt)
 {
-	return NULL;
+	CERTCertificate *crt_dat;
+	size_t hashlen = 20; /* Size of an sha1sum */
+	GByteArray *sha1sum;
+	SECItem *derCert; /* DER representation of the cert */
+	SECStatus st;
+
+	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);
+
+	/* Get the certificate DER representation */
+	derCert = &(crt_dat->derCert);
+
+	/* Make a hash! */
+	sha1sum = g_byte_array_sized_new(hashlen);
+	st = PK11_HashBuf(SEC_OID_SHA1, sha1sum->data,
+			  derCert->data, derCert->len);
+
+	/* Check for errors */
+	if (st != SECSuccess) {
+		g_byte_array_free(sha1sum, TRUE);
+		purple_debug_error("nss/x509",
+				   "Error: hashing failed!\n");
+		return NULL;
+	}
+
+	return sha1sum;
 }
 
 static gchar *