diff common/logging.c @ 625:2303caf56dbb

Add logging function for der data and add logging to NSS installation
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 20 Jun 2014 12:53:16 +0200
parents 5042ace08cba
children 698b6a9bd75e
line wrap: on
line diff
--- a/common/logging.c	Fri Jun 20 12:17:47 2014 +0200
+++ b/common/logging.c	Fri Jun 20 12:53:16 2014 +0200
@@ -162,14 +162,9 @@
 void
 log_certificate(const char* store, char *b64cert, bool install)
 {
-  char subject[MAX_LOG + 1],
-       *der_data = NULL;
+  char *der_data = NULL;
   size_t der_size = 0;
-  int ret = 0,
-      i = 0;
-  x509_crt chain;
-  unsigned char sha256sum[32];
-  char fingerprint[32 * 3 + 1];
+  int ret = 0;
 
   ret = str_base64_decode (&der_data, &der_size, b64cert, strlen(b64cert));
 
@@ -179,12 +174,26 @@
       return;
     }
 
+  log_certificate_der (store, (unsigned char *) der_data, der_size, install);
+
+  xfree (der_data);
+}
+
+void
+log_certificate_der(const char *store, unsigned char *der_data, size_t der_size, bool install)
+{
+  char subject[MAX_LOG + 1];
+  int ret = 0,
+      i = 0;
+  x509_crt chain;
+  unsigned char sha256sum[32];
+  char fingerprint[32 * 3 + 1];
+
   x509_crt_init(&chain);
   if (x509_crt_parse_der(&chain, (const unsigned char *)der_data,
                          der_size) != 0)
     {
       ERRORPRINTF("Failed to parse cert..");
-      xfree (der_data);
       return;
     }
 
@@ -193,7 +202,6 @@
   if (ret == -1)
     {
       ERRORPRINTF("Failed to parse subject..");
-      xfree (der_data);
       return;
     }
   subject[MAX_LOG] = '\0';
@@ -202,9 +210,9 @@
 
   for (i = 0; i < 31; i++)
     {
-      snprintf (fingerprint + i * 3, 3, "%02X:", sha256sum[i]);
+      snprintf (fingerprint + (i * 3), 4, "%02X:", sha256sum[i]);
     }
-  snprintf (fingerprint + 31 * 3, 2, "%02X", sha256sum[31]);
+  snprintf (fingerprint + (31 * 3), 3, "%02X", sha256sum[31]);
 
   fingerprint[32*3] = '\0';
 
@@ -227,12 +235,11 @@
     }
 #else
   /* Please keep the following line in line with message from events.mc */
-  linux_log ("%s of root certificate: %s\nSha256 thumbprint:<%s>.\nCertificate store \"%s\"",
-             install ? "Installation" : "Removal",
-             subject, fingerprint, store);
+  syslog_info_printf ("%s of root certificate: %s Sha256 thumbprint:<%s>. Certificate store \"%s\"",
+                      install ? "Installation" : "Removal",
+                      subject, fingerprint, store);
 #endif
   x509_crt_free (&chain);
-  xfree (der_data);
 }
 
 void

http://wald.intevation.org/projects/trustbridge/