gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r33576 - gnunet/src/dns gnunet/src/gnsrecord gnunet/src/inc


From: gnunet
Subject: [GNUnet-SVN] r33576 - gnunet/src/dns gnunet/src/gnsrecord gnunet/src/include gnunet-gtk/src/namestore
Date: Sat, 7 Jun 2014 02:24:59 +0200

Author: grothoff
Date: 2014-06-07 02:24:59 +0200 (Sat, 07 Jun 2014)
New Revision: 33576

Modified:
   gnunet-gtk/src/namestore/plugin_gtk_namestore_tlsa.c
   gnunet/src/dns/dnsparser.c
   gnunet/src/gnsrecord/plugin_gnsrecord_dns.c
   gnunet/src/include/gnunet_dnsparser_lib.h
Log:
more tlsa fixes

Modified: gnunet/src/dns/dnsparser.c
===================================================================
--- gnunet/src/dns/dnsparser.c  2014-06-06 23:52:35 UTC (rev 33575)
+++ gnunet/src/dns/dnsparser.c  2014-06-07 00:24:59 UTC (rev 33576)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2010-2013 Christian Grothoff (and other contributing authors)
+      (C) 2010-2014 Christian Grothoff (and other contributing authors)
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -1229,4 +1229,39 @@
   return GNUNET_OK;
 }
 
+
+/**
+ * Convert a block of binary data to HEX.
+ *
+ * @param data binary data to convert
+ * @param data_size number of bytes in @a data
+ * @return HEX string (lower case)
+ */
+char *
+GNUNET_DNSPARSER_bin_to_hex (const void *data,
+                             size_t data_size)
+{
+  GNUNET_break (0); // FIXME: not implemented
+  return NULL;
+}
+
+
+/**
+ * Convert a HEX string to block of binary data.
+ *
+ * @param hex HEX string to convert (may contain mixed case)
+ * @param data where to write result, must be
+ *             at least `strlen(hex)/2` bytes long
+ * @return number of bytes written to data
+ */
+size_t
+GNUNET_DNSPARSER_hex_to_bin (const char *hex,
+                             void *data)
+{
+  GNUNET_break (0);  // FIXME: not implemented
+  return 0;
+}
+
+
+
 /* end of dnsparser.c */

Modified: gnunet/src/gnsrecord/plugin_gnsrecord_dns.c
===================================================================
--- gnunet/src/gnsrecord/plugin_gnsrecord_dns.c 2014-06-06 23:52:35 UTC (rev 
33575)
+++ gnunet/src/gnsrecord/plugin_gnsrecord_dns.c 2014-06-07 00:24:59 UTC (rev 
33576)
@@ -44,7 +44,6 @@
                      const void *data,
                      size_t data_size)
 {
-  const char *cdata;
   char* result;
   char tmp[INET6_ADDRSTRLEN];
 
@@ -231,23 +230,26 @@
   case GNUNET_DNSPARSER_TYPE_TLSA:
     {
       const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
-      char* tlsa_str;
+      char *tlsa_str;
+      char *hex;
 
-      cdata = data;
-      if ( (data_size <= sizeof (struct GNUNET_TUN_DnsTlsaRecord)) ||
-          ('\0' != cdata[data_size - 1]) )
+      if (data_size < sizeof (struct GNUNET_TUN_DnsTlsaRecord))
        return NULL; /* malformed */
       tlsa = data;
+      hex = GNUNET_DNSPARSER_bin_to_hex (&tlsa[1],
+                                         data_size - sizeof (struct 
GNUNET_TUN_DnsTlsaRecord));
       if (0 == GNUNET_asprintf (&tlsa_str,
                                "%u %u %u %s",
                                (unsigned int) tlsa->usage,
                                (unsigned int) tlsa->selector,
                                (unsigned int) tlsa->matching_type,
-                               (const char *) &tlsa[1]))
+                               hex))
       {
+        GNUNET_free (hex);
        GNUNET_free (tlsa_str);
        return NULL;
       }
+      GNUNET_free (hex);
       return tlsa_str;
     }
   default:
@@ -603,23 +605,40 @@
       unsigned int usage;
       unsigned int selector;
       unsigned int matching_type;
+      size_t slen = strlen (s) + 1;
+      char hex[slen];
 
-      *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (s) - 6;
-      *data = tlsa = GNUNET_malloc (*data_size);
       if (4 != SSCANF (s,
                        "%u %u %u %s",
-                       (char*)&tlsa[1]))
+                       &usage,
+                       &selector,
+                       &matching_type,
+                       hex))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     _("Unable to parse TLSA record string `%s'\n"),
                     s);
         *data_size = 0;
-        GNUNET_free (tlsa);
         return GNUNET_SYSERR;
       }
+
+      *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
+      *data = tlsa = GNUNET_malloc (*data_size);
       tlsa->usage = (uint8_t) usage;
       tlsa->selector = (uint8_t) selector;
       tlsa->matching_type = (uint8_t) matching_type;
+      if (strlen (hex) / 2 !=
+          GNUNET_DNSPARSER_hex_to_bin (hex,
+                                       &tlsa[1]))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    _("Unable to parse TLSA record string `%s'\n"),
+                    s);
+        GNUNET_free (*data);
+        *data = NULL;
+        *data_size = 0;
+        return GNUNET_SYSERR;
+      }
       return GNUNET_OK;
     }
   default:

Modified: gnunet/src/include/gnunet_dnsparser_lib.h
===================================================================
--- gnunet/src/include/gnunet_dnsparser_lib.h   2014-06-06 23:52:35 UTC (rev 
33575)
+++ gnunet/src/include/gnunet_dnsparser_lib.h   2014-06-07 00:24:59 UTC (rev 
33576)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2010-2013 Christian Grothoff (and other contributing authors)
+      (C) 2010-2014 Christian Grothoff (and other contributing authors)
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -859,4 +859,29 @@
 GNUNET_DNSPARSER_free_cert (struct GNUNET_DNSPARSER_CertRecord *cert);
 
 
+/**
+ * Convert a block of binary data to HEX.
+ *
+ * @param data binary data to convert
+ * @param data_size number of bytes in @a data
+ * @return HEX string (lower case)
+ */
+char *
+GNUNET_DNSPARSER_bin_to_hex (const void *data,
+                             size_t data_size);
+
+
+/**
+ * Convert a HEX string to block of binary data.
+ *
+ * @param hex HEX string to convert (may contain mixed case)
+ * @param data where to write result, must be
+ *             at least `strlen(hex)/2` bytes long
+ * @return number of bytes written to data
+ */
+size_t
+GNUNET_DNSPARSER_hex_to_bin (const char *hex,
+                             void *data);
+
+
 #endif

Modified: gnunet-gtk/src/namestore/plugin_gtk_namestore_tlsa.c
===================================================================
--- gnunet-gtk/src/namestore/plugin_gtk_namestore_tlsa.c        2014-06-06 
23:52:35 UTC (rev 33575)
+++ gnunet-gtk/src/namestore/plugin_gtk_namestore_tlsa.c        2014-06-07 
00:24:59 UTC (rev 33576)
@@ -274,9 +274,9 @@
                       &iter,
                       1, &service,
                       -1);
-  usage = 0;
-  selector = 0;
-  matching_type = 0;
+  usage = 42; // FIXME: get from GUI!
+  selector = 42; // FIXME: get from GUI!
+  matching_type = 42; // FIXME: get from GUI!
 
   tb = gtk_text_view_get_buffer (GTK_TEXT_VIEW
                                  (gtk_builder_get_object (builder,
@@ -329,6 +329,7 @@
   gnutls_datum_t datum;
   gnutls_pkcs7_t pkcs7;
   int ret;
+  unsigned int matching_type;
 
   entry = GTK_EDITABLE (gtk_builder_get_object (builder,
                                                
"edit_dialog_tlsa_target_entry"));
@@ -347,23 +348,49 @@
                                                           
"edit_dialog_tlsa_value_textview")));
   gtk_text_buffer_get_iter_at_offset (tb, &ti_start, 0);
   gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1);
-
   value = gtk_text_buffer_get_text (tb,
                                     &ti_start,
                                     &ti_end,
                                     FALSE);
-  datum.size = strlen (value);
-  datum.data = (void *) value;
-  gnutls_pkcs7_init (&pkcs7);
-  if (GNUTLS_E_SUCCESS !=
-      gnutls_pkcs7_import (pkcs7,
-                           &datum,
-                           GNUTLS_X509_FMT_PEM))
-    ret = GNUNET_SYSERR;
-  else
-    ret = GNUNET_OK;
-  gnutls_pkcs7_deinit (pkcs7);
-  g_free (value);
+  {
+    size_t slen = strlen (value);
+    uint8_t bin[slen / 2];
+
+    if (slen / 2 !=
+        GNUNET_DNSPARSER_hex_to_bin (value,
+                                     bin))
+    {
+      /* not hex */
+      return GNUNET_SYSERR;
+    }
+    matching_type = 42; // FIXME: get from GUI!
+
+    switch (matching_type)
+    {
+    case 0: /* exact match */
+      datum.size = sizeof (bin);
+      datum.data = bin;
+      gnutls_pkcs7_init (&pkcs7);
+      if (GNUTLS_E_SUCCESS !=
+          gnutls_pkcs7_import (pkcs7,
+                               &datum,
+                               GNUTLS_X509_FMT_DER))
+        ret = GNUNET_SYSERR;
+      else
+        ret = GNUNET_OK;
+      gnutls_pkcs7_deinit (pkcs7);
+      break;
+    case 1: /* SHA-256 hash */
+      ret = (256 / 8 == slen / 2) ? GNUNET_OK : GNUNET_SYSERR;
+      break;
+    case 2: /* SHA-512 hash */
+      ret = (512 / 8 == slen / 2) ? GNUNET_OK : GNUNET_SYSERR;
+      break;
+    default:
+      GNUNET_break (0);
+      break;
+    }
+  }
   return ret;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]