# HG changeset patch # User William Ehlhardt # Date 1186129826 0 # Node ID 3004bfa0e8466853c14ba90b0c4083acf9cae26c # Parent 2156321c5482d162634c5df14f7ff48f84df3928 - x509_nss sha1sum diff -r 2156321c5482 -r 3004bfa0e846 libpurple/plugins/ssl/ssl-nss.c --- 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 *