[Openvas-commits] r3541 - in trunk/openvas-libraries: . libopenvas libopenvascommon

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 29 19:09:55 CEST 2009


Author: mattm
Date: 2009-05-29 19:09:54 +0200 (Fri, 29 May 2009)
New Revision: 3541

Added:
   trunk/openvas-libraries/libopenvascommon/certificate.c
   trunk/openvas-libraries/libopenvascommon/certificate.h
Modified:
   trunk/openvas-libraries/ChangeLog
   trunk/openvas-libraries/Makefile
   trunk/openvas-libraries/libopenvas/Makefile
Log:
	Add certificate facilities.

	* libopenvascommon/certificate.h, libopenvascommon/certificate.c: New
	files.

	* libopenvas/Makefile: Add libopenvascommon/certificate.

	* Makefile: Install libopenvascommon/certificate.h.

Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog	2009-05-29 13:38:59 UTC (rev 3540)
+++ trunk/openvas-libraries/ChangeLog	2009-05-29 17:09:54 UTC (rev 3541)
@@ -1,3 +1,14 @@
+2009-05-29  Matthew Mundell <mmundell at intevation.de>
+
+	Add certificate facilities.
+
+	* libopenvascommon/certificate.h, libopenvascommon/certificate.c: New
+	files.
+
+	* libopenvas/Makefile: Add libopenvascommon/certificate.
+
+	* Makefile: Install libopenvascommon/certificate.h.
+
 2009-05-28  Matthew Mundell <mmundell at intevation.de>
 
 	* libopenvascommon/nvti.c (nvti_to_keyfile): Rename gerror to error.  Free

Modified: trunk/openvas-libraries/Makefile
===================================================================
--- trunk/openvas-libraries/Makefile	2009-05-29 13:38:59 UTC (rev 3540)
+++ trunk/openvas-libraries/Makefile	2009-05-29 17:09:54 UTC (rev 3541)
@@ -54,7 +54,6 @@
 	$(INSTALL) -m 0444 libopenvas/kb.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/network.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/ntp.h $(DESTDIR)${includedir}/openvas
-	$(INSTALL) -m 0444 libopenvascommon/nvti.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/pcap_openvas.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/plugutils.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/popen.h $(DESTDIR)${includedir}/openvas
@@ -71,6 +70,8 @@
 	$(INSTALL) -m 0444 libopenvas/store.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/system.h $(DESTDIR)${includedir}/openvas
 	$(INSTALL) -m 0444 libopenvas/www_funcs.h $(DESTDIR)${includedir}/openvas
+	$(INSTALL) -m 0444 libopenvascommon/nvti.h $(DESTDIR)${includedir}/openvas
+	$(INSTALL) -m 0444 libopenvascommon/certificate.h $(DESTDIR)${includedir}/openvas
 	test -d $(DESTDIR)${bindir} || ${INSTALL_DIR} -m 755 $(DESTDIR)${bindir}
 	$(INSTALL) -m 0755 libopenvas-config $(DESTDIR)${bindir}/libopenvas-config
 	test -d $(DESTDIR)${mandir} || ${INSTALL_DIR} -m 755 $(DESTDIR)${mandir}

Modified: trunk/openvas-libraries/libopenvas/Makefile
===================================================================
--- trunk/openvas-libraries/libopenvas/Makefile	2009-05-29 13:38:59 UTC (rev 3540)
+++ trunk/openvas-libraries/libopenvas/Makefile	2009-05-29 17:09:54 UTC (rev 3541)
@@ -32,7 +32,8 @@
 	bpf_share.o rand.o popen.o services.o services1.o \
 	proctitle.o store.o kb.o share_fd.o hash_table_file.o \
 	openvas_ssh_login.o openvas_server.o openvas_auth.o \
-	../libopenvascommon/nvti.o openvas_logging.o
+	../libopenvascommon/nvti.o openvas_logging.o \
+	../libopenvascommon/certificate.o
 	
 LO_OBJS = plugutils.lo system.lo network.lo resolve.lo arglists.lo \
 	ftp_funcs.lo scanners_utils.lo pcap.lo hlst.lo  harglists.lo \
@@ -40,7 +41,7 @@
 	rand.lo popen.lo bpf_share.lo services.lo services1.lo \
 	proctitle.lo store.lo kb.lo share_fd.lo hash_table_file.lo \
 	openvas_ssh_login.lo openvas_server.lo openvas_auth.lo \
-	nvti.lo openvas_logging.lo
+	nvti.lo openvas_logging.lo certificate.lo
 
 # += does not work with non-GNU make ...
 # CFLAGS+=-I../$(CIPHER_SUBDIR)
@@ -54,6 +55,10 @@
 ../libopenvascommon/nvti.o: ../libopenvascommon/nvti.c ../libopenvascommon/nvti.h
 	$(COMPILE) -c ../libopenvascommon/nvti.c
 
+../libopenvascommon/certificate.o: ../libopenvascommon/certificate.c \
+                                   ../libopenvascommon/certificate.h
+	$(COMPILE) -c ../libopenvascommon/certificate.c
+
 plugutils.o: plugutils.c arglists.h comm.h harglists.h kb.h network.h \
              rand.h plugutils.h services.h share_fd.h store_internal.h system.h \
              scanners_utils.h

Added: trunk/openvas-libraries/libopenvascommon/certificate.c
===================================================================
--- trunk/openvas-libraries/libopenvascommon/certificate.c	2009-05-29 13:38:59 UTC (rev 3540)
+++ trunk/openvas-libraries/libopenvascommon/certificate.c	2009-05-29 17:09:54 UTC (rev 3541)
@@ -0,0 +1,255 @@
+/* openvas-libraries/libopenvascommon
+ * $Id$
+ * Description: Facilities for certificates and certificate collections.
+ *
+ * Authors:
+ * Matthew Mundell <matt at mundell.ukfsn.org>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file certificate.c
+ * @brief Facilities for certificates and certificate collections.
+ *
+ * This file provides facilities for data about certificates, and
+ * collections of such data.  This includes two types, certificate_t
+ * and certificates_t, and functions for manipulating structures of
+ * these types.
+ */
+
+#include "certificate.h"
+
+/**
+ * @brief Create a new, empty certificate structure.
+ *
+ * @return NULL in case the memory could not be allocated.
+ *         Else an empty certificate structure which needs to be
+ *         released using @ref certificate_free .
+ */
+certificate_t *
+certificate_create ()
+{
+  return (certificate_t *) g_malloc0 (sizeof (certificate_t));
+}
+
+/**
+ * @brief Free memory of a certificate structure.
+ *
+ * @param  n  The structure to be freed.
+ */
+void
+certificate_free (certificate_t * certificate)
+{
+  if (certificate == NULL) return;
+  if (certificate->fingerprint) g_free (certificate->fingerprint);
+  if (certificate->owner) g_free (certificate->owner);
+  if (certificate->public_key) g_free (certificate->public_key);
+  g_free (certificate);
+}
+
+/**
+ * @brief Get the fingerprint of a certificate.
+ *
+ * @param  certificate  The certificate.
+ *
+ * @return The fingerprint, which may be NULL.
+ */
+const gchar *
+certificate_fingerprint (const certificate_t * certificate)
+{
+  return certificate->fingerprint;
+}
+
+/**
+ * @brief Get the owner of a certificate.
+ *
+ * @param  certificate  The certificate.
+ *
+ * @return The owner, which may be NULL.
+ */
+const gchar *
+certificate_owner (const certificate_t * certificate)
+{
+  return certificate->owner;
+}
+
+/**
+ * @brief Get the public key of a certificate.
+ *
+ * @param  certificate  The certificate.
+ *
+ * @return The public key, which may be NULL.
+ */
+const gchar *
+certificate_public_key (const certificate_t * certificate)
+{
+  return certificate->public_key;
+}
+
+/**
+ * @brief Get the trustedness of a certificate.
+ *
+ * @param  certificate  The certificate.
+ *
+ * @return TRUE if the key is trusted, else FALSE.
+ */
+gboolean
+certificate_trusted (const certificate_t * certificate)
+{
+  return certificate->trusted;
+}
+
+/**
+ * @brief Set the fingerprint of a certificate.
+ *
+ * @param  certificate  The certificate.
+ * @param  fingerprint  The fingerprint.
+ *
+ * @return 0 on success, -1 on error.
+ */
+int
+certificate_set_fingerprint (certificate_t * certificate, const gchar * fingerprint)
+{
+  if (certificate->fingerprint)
+    g_free (certificate->fingerprint);
+  // FIX this aborts on out of mem, while certificate_create returns NULL
+  certificate->fingerprint = g_strdup (fingerprint);
+  return 0;
+}
+
+/**
+ * @brief Set the owner of a certificate.
+ *
+ * @param  certificate  The certificate.
+ * @param  owner        The owner.
+ *
+ * @return 0 on success, -1 on error.
+ */
+int
+certificate_set_owner (certificate_t * certificate, const gchar * owner)
+{
+  if (certificate->owner)
+    g_free (certificate->owner);
+  certificate->owner = g_strdup (owner);
+  return 0;
+}
+
+/**
+ * @brief Set the public key of a certificate.
+ *
+ * @param  certificate  The certificate.
+ * @param  public key   The public key.
+ *
+ * @return 0 on success, -1 on error.
+ */
+int
+certificate_set_public_key (certificate_t * certificate, const gchar * public_key)
+{
+  if (certificate->public_key)
+    g_free (certificate->public_key);
+  certificate->public_key = g_strdup (public_key);
+  return 0;
+}
+
+/**
+ * @brief Set the trustedness of a certificate.
+ *
+ * @param  certificate  The certificate.
+ * @param  trusted      TRUE if trusted, else FALSE.
+ */
+void
+certificate_set_trusted (certificate_t * certificate, gboolean trusted)
+{
+  certificate->trusted = trusted;
+}
+
+
+/* Collections of certificates. */
+
+/**
+ * @brief Make a collection of certificates.
+ *
+ * @return A new collection of certificates or NULL on error.
+ */
+certificates_t*
+certificates_create ()
+{
+  certificates_t *certs;
+  certs = (certificates_t *) g_malloc0 (sizeof (certificates_t));
+  return certs;
+}
+
+/**
+ * @brief Free a collection of certificates.
+ *
+ * @param  certificates  The collection of certificates.
+ */
+void
+certificates_free (certificates_t* certificates)
+{
+  GSList *list;
+  if (certificates == NULL) return;
+  for (list = certificates->list; list; list = g_slist_next (list))
+    certificate_free (list->data);
+  g_slist_free (certificates->list);
+  g_free (certificates);
+}
+
+/**
+ * @brief Get the size of a collection of certificates.
+ *
+ * @return The number of entries in the collection.
+ */
+guint
+certificates_size (certificates_t* certificates)
+{
+  return g_slist_length (certificates->list);
+}
+
+/**
+ * @brief Add a certificate to a collection of certificate
+ *
+ * @param  certificates  The collection of certificates.
+ */
+void
+certificates_add (certificates_t* certificates, certificate_t* certificate)
+{
+  if (certificate)
+    certificates->list = g_slist_prepend (certificates->list,
+                                          (gpointer) certificate);
+}
+
+/**
+ * @brief Search the certificates with a function.
+ *
+ * @param  certificates  Certificates to search.
+ * @param  data          First argument to function.
+ * @param  function      Compare function.
+ *
+ * @return The first element for which the function returns 0.
+ */
+certificate_t*
+certificates_find (certificates_t* certificates,
+                   gconstpointer data,
+                   GCompareFunc function)
+{
+  GSList* element = g_slist_find_custom (certificates->list, data, function);
+  if (element) return element->data;
+  return NULL;
+}

Added: trunk/openvas-libraries/libopenvascommon/certificate.h
===================================================================
--- trunk/openvas-libraries/libopenvascommon/certificate.h	2009-05-29 13:38:59 UTC (rev 3540)
+++ trunk/openvas-libraries/libopenvascommon/certificate.h	2009-05-29 17:09:54 UTC (rev 3541)
@@ -0,0 +1,89 @@
+/* openvas-libraries/libopenvascommon
+ * $Id$
+ * Description: Certificate header file.
+ *
+ * Authors:
+ * Matthew Mundell <matt at mundell.ukfsn.org>
+ *
+ * Copyright:
+ * Copyright (C) 2009 Greenbone Networks GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * or, at your option, any later version as published by the Free
+ * Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * @file certificate.h
+ * @brief Certificate header file.
+ */
+
+#ifndef _CERTIFICATE_H
+#define _CERTIFICATE_H
+
+#include <glib.h>
+
+/**
+ * @brief Information about a certificate.
+ *
+ * The elements of this structure should always be accessed using the
+ * function interface (get_fingerprint, set_owner, etc.).
+ */
+typedef struct {
+  char* fingerprint;  // Fingerprint.
+  char* owner;        // Name of the owner of the certificate.
+  char* public_key;   // Full public key.
+  gboolean trusted;   // True if the certificate is trusted.
+} certificate_t;
+
+certificate_t *certificate_create (void);
+void certificate_free (certificate_t *);
+
+const gchar *certificate_fingerprint (const certificate_t *);
+const gchar *certificate_owner (const certificate_t *);
+const gchar *certificate_public_key (const certificate_t *);
+gboolean certificate_trusted (const certificate_t *);
+
+const gchar *certificate_trust_level (const certificate_t *);
+
+int certificate_set_fingerprint (certificate_t *, const gchar *);
+int certificate_set_owner (certificate_t *, const gchar *);
+int certificate_set_public_key (certificate_t *, const gchar *);
+void certificate_set_trusted (certificate_t *, gboolean);
+
+
+/* Collections of certificates. */
+
+/**
+ * @brief A collection of certificates.
+ *
+ * The elements of this structure should always be accessed using the
+ * function interface (certificates_add, etc.).
+ */
+typedef struct {
+  GSList *list;  // A list of pointers to certificate_t's.
+} certificates_t;
+
+certificates_t *certificates_create ();
+void certificates_free (certificates_t *);
+
+guint certificates_size (certificates_t *);
+
+void certificates_add (certificates_t *, certificate_t *);
+
+certificate_t*
+certificates_find (certificates_t* certificates,
+                   gconstpointer data,
+                   GCompareFunc function);
+
+#endif /* not _CERTIFICATE_H */



More information about the Openvas-commits mailing list