gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated (aa8979eac -> 0d77fac87)


From: gnunet
Subject: [gnunet] branch master updated (aa8979eac -> 0d77fac87)
Date: Fri, 01 Dec 2023 10:26:47 +0100

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a change to branch master
in repository gnunet.

    from aa8979eac meson: add some more transport tests
     new 4bbdc27de URI & SMIMEA DNS RR
     new f3415ad20 URI RR fix
     new 109075509 URI RR fix
     new c14c96b7c LIGHTEST service & protocol box checks
     new 5e1ffe738 BOX record namestore test
     new 86e8344d6 Refactored service and protocol resolution in GNS resolver
     new 8b0cafb1d Fix URI record serialization issue
     new fe90b3598 test_gns_lightest.sh for lightest lookup tests
     new 0d77fac87 fix: BOX at @ not working

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/cli/gns/test_gns_lightest.sh                   | 135 +++++++++++++++++++++
 src/cli/namestore/gnunet-namestore.c               |   3 +-
 src/cli/namestore/gnunet-zoneimport.c              |  11 ++
 ...store_put.sh => test_namestore_box_lightest.sh} |  38 +++---
 src/include/gnunet_dnsparser_lib.h                 |  86 +++++++++++++
 src/include/gnunet_tun_lib.h                       |  23 ++++
 src/lib/util/dnsparser.c                           | 130 ++++++++++++++++++++
 src/plugin/gnsrecord/plugin_gnsrecord_dns.c        |  76 +++++++++++-
 src/service/dns/gnunet-dns-monitor.c               |  17 +++
 src/service/dns/gnunet-zonewalk.c                  |  11 +-
 src/service/gns/gnunet-service-gns_interceptor.c   |  18 +++
 src/service/gns/gnunet-service-gns_resolver.c      | 114 ++++++++++++++++-
 12 files changed, 639 insertions(+), 23 deletions(-)
 create mode 100755 src/cli/gns/test_gns_lightest.sh
 copy src/cli/namestore/{test_namestore_put.sh => 
test_namestore_box_lightest.sh} (50%)
 mode change 100755 => 100644

diff --git a/src/cli/gns/test_gns_lightest.sh b/src/cli/gns/test_gns_lightest.sh
new file mode 100755
index 000000000..03c313a7b
--- /dev/null
+++ b/src/cli/gns/test_gns_lightest.sh
@@ -0,0 +1,135 @@
+#!/bin/sh
+# This file is in the public domain.
+trap "gnunet-arm -e -c test_gns_lookup.conf" INT
+
+LOCATION=$(which gnunet-config)
+if [ -z $LOCATION ]
+then
+  LOCATION="gnunet-config"
+fi
+$LOCATION --version 1> /dev/null
+if test $? != 0
+then
+       echo "GNUnet command line tools cannot be found, check environmental 
variables PATH and GNUNET_PREFIX"
+       exit 77
+fi
+
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
+which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
+MY_EGO="test-lightest"
+LABEL="test-scheme"
+PTR_LABEL="test-ptr"
+TEST_URI="10 1 \"https://ec.europa.eu/tools/lotl/eu-lotl.xml\"";
+TEST_SMIMEA="3 0 1 
f7e8e4e554fb7c7a8f6f360e0ca2f59d466c8f9539a25963f5ed37e905f0c797"
+SCHEME="_scheme"
+TRUST="_trust"
+TRUSTLIST="_trustlist"
+TEST_PTR="$SCHEME.$TRUST.$LABEL.$MY_EGO"
+TEST_PTR2="$TRUSTLIST.$TRUST.$LABEL.$MY_EGO"
+gnunet-arm -s -c test_gns_lookup.conf
+gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n $PTR_LABEL -t BOX -V "242 1003 12 
$TEST_PTR" -e never -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n $PTR_LABEL -t BOX -V "242 1002 12 
$TEST_PTR2" -e never -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n $LABEL -t BOX -V "242 1003 256 $TEST_URI" 
-e never -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n $LABEL -t BOX -V "242 1003 53 
$TEST_SMIMEA" -e never -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n $LABEL -t BOX -V "242 1002 256 $TEST_URI" 
-e never -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n $LABEL -t BOX -V "242 1002 53 
$TEST_SMIMEA" -e never -c test_gns_lookup.conf
+sleep 0.5
+PTR_SCHEME=`$DO_TIMEOUT gnunet-gns --raw -u $SCHEME.$TRUST.$PTR_LABEL.$MY_EGO 
-t PTR -c test_gns_lookup.conf`
+PTR_TRUSTLIST=`$DO_TIMEOUT gnunet-gns --raw -u 
$TRUSTLIST.$TRUST.$PTR_LABEL.$MY_EGO -t PTR -c test_gns_lookup.conf`
+
+SUCCESS=0
+if [ "$PTR_SCHEME" != "$TEST_PTR" ]
+then
+  echo "Failed to resolve to proper PTR, got '$PTR_SCHEME'."
+  SUCCESS=1
+else
+  echo "Resolved to proper PTR, got '$PTR_SCHEME'."
+fi
+
+if [ "$PTR_TRUSTLIST" != "$TEST_PTR2" ]
+then
+  echo "Failed to resolve to proper PTR, got '$PTR_TRUSTLIST'."
+  SUCCESS=1
+else
+  echo "Resolved to proper PTR, got '$PTR_TRUSTLIST'."
+fi
+
+if [ "$SUCCESS" = "1" ]
+then
+  gnunet-namestore -z $MY_EGO -X -c test_gns_lookup.conf
+  gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
+  gnunet-arm -e -c test_gns_lookup.conf
+  rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o 
GNUNET_TEST_HOME`
+  exit 1
+fi
+
+
+RES_URI_SCHEME=`$DO_TIMEOUT gnunet-gns --raw -u $PTR_SCHEME -t URI -c 
test_gns_lookup.conf`
+RES_SMIMEA_SCHEME=`$DO_TIMEOUT gnunet-gns --raw -u $PTR_SCHEME -t SMIMEA -c 
test_gns_lookup.conf`
+
+RES_URI_TRUSTLIST=`$DO_TIMEOUT gnunet-gns --raw -u $PTR_TRUSTLIST -t URI -c 
test_gns_lookup.conf`
+RES_SMIMEA_TRUSTLIST=`$DO_TIMEOUT gnunet-gns --raw -u $PTR_TRUSTLIST -t SMIMEA 
-c test_gns_lookup.conf`
+
+
+if [ "$RES_URI_SCHEME" != "$TEST_URI" ]
+then
+  echo "Failed to resolve to proper URI, got '$RES_URI_SCHEME'."
+  SUCCESS=1
+else
+  echo "Resolved to proper URI, got '$RES_URI_SCHEME'."
+fi
+
+if [ "$RES_SMIMEA_SCHEME" != "$TEST_SMIMEA" ]
+then
+  echo "Failed to resolve to proper SMIMEA, got '$RES_SMIMEA_SCHEME'."
+  SUCCESS=1
+else
+  echo "Resolved to proper SMIMEA, got '$RES_SMIMEA_SCHEME'."
+fi
+
+if [ "$RES_URI_TRUSTLIST" != "$TEST_URI" ]
+then
+  echo "Failed to resolve to proper URI, got '$RES_URI_TRUSTLIST'."
+  SUCCESS=1
+else
+  echo "Resolved to proper URI, got '$RES_URI_TRUSTLIST'."
+fi
+
+if [ "$RES_SMIMEA_TRUSTLIST" != "$TEST_SMIMEA" ]
+then
+  echo "Failed to resolve to proper SMIMEA, got '$RES_SMIMEA_TRUSTLIST'."
+  SUCCESS=1
+else
+  echo "Resolved to proper SMIMEA, got '$RES_SMIMEA_TRUSTLIST'."
+fi
+
+gnunet-namestore -p -z $MY_EGO -a -n $LABEL -t BOX -V "242 1003 256 10 1 
\"thisisnotavaliduri\"" -e never -c test_gns_lookup.conf
+status=$?
+gnunet-namestore -p -z $MY_EGO -a -n $LABEL -t BOX -V "242 1003 256 10 1 
mailto:thisrecordismilformed@test.com"; -e never -c test_gns_lookup.conf
+status2=$?
+
+if [ "$status" = "0" ]
+then
+  echo "Failed to detect malformed URI."
+  SUCCESS=1
+else
+  echo "Detected malformed URI."
+fi
+
+if [ "$status2" = "0" ]
+then
+  echo "Failed to detect malformed URI Record Presentation."
+  SUCCESS=1
+else
+  echo "Detected malformed URI Presentation."
+fi
+
+
+
+gnunet-namestore -z $MY_EGO -X -c test_gns_lookup.conf
+gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
+gnunet-arm -e -c test_gns_lookup.conf
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
+
+exit $SUCCESS
\ No newline at end of file
diff --git a/src/cli/namestore/gnunet-namestore.c 
b/src/cli/namestore/gnunet-namestore.c
index baa036ac7..00eacfcfd 100644
--- a/src/cli/namestore/gnunet-namestore.c
+++ b/src/cli/namestore/gnunet-namestore.c
@@ -1465,10 +1465,11 @@ run_with_zone_pkey (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
     }
     if ((GNUNET_DNSPARSER_TYPE_SRV == type) ||
         (GNUNET_DNSPARSER_TYPE_TLSA == type) ||
+        (GNUNET_DNSPARSER_TYPE_SMIMEA == type) ||
         (GNUNET_DNSPARSER_TYPE_OPENPGPKEY == type))
     {
       fprintf (stderr,
-               _ ("For DNS record types `SRV', `TLSA' and `OPENPGPKEY'"));
+               _ ("For DNS record types `SRV', `TLSA', `SMIMEA' and 
`OPENPGPKEY'"));
       fprintf (stderr, ", please use a `BOX' record instead\n");
       ret = 1;
       finish_command ();
diff --git a/src/cli/namestore/gnunet-zoneimport.c 
b/src/cli/namestore/gnunet-zoneimport.c
index c7e0cf65f..9e8185653 100644
--- a/src/cli/namestore/gnunet-zoneimport.c
+++ b/src/cli/namestore/gnunet-zoneimport.c
@@ -876,6 +876,17 @@ process_record (void *cls, const struct 
GNUNET_DNSPARSER_Record *rec)
     }
     break;
 
+  case GNUNET_DNSPARSER_TYPE_URI:
+    if (GNUNET_OK ==
+        GNUNET_DNSPARSER_builder_add_uri (dst, dst_len, &off, rec->data.uri))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Converting URI record for `%s'\n",
+                  rec->name);
+      add_record (req, rec->type, expiration_time, dst, off);
+    }
+    break;
+
   case GNUNET_DNSPARSER_TYPE_PTR:
     if (GNUNET_OK == GNUNET_DNSPARSER_builder_add_name (dst,
                                                         dst_len,
diff --git a/src/cli/namestore/test_namestore_put.sh 
b/src/cli/namestore/test_namestore_box_lightest.sh
old mode 100755
new mode 100644
similarity index 50%
copy from src/cli/namestore/test_namestore_put.sh
copy to src/cli/namestore/test_namestore_box_lightest.sh
index eaf7d44b4..add966f8f
--- a/src/cli/namestore/test_namestore_put.sh
+++ b/src/cli/namestore/test_namestore_box_lightest.sh
@@ -15,16 +15,9 @@ then
 fi
 
 rm -rf `$LOCATION -c $CONFIGURATION -s PATHS -o GNUNET_HOME`
-TEST_DOMAIN_PLUS="www.gnu"
-TEST_DOMAIN_DNS="www3.gnu"
-TEST_IP_PLUS="127.0.0.1"
-TEST_IP_DNS="131.159.74.67"
-TEST_RECORD_CNAME_SERVER="server"
-TEST_RECORD_CNAME_PLUS="server.+"
-TEST_RECORD_CNAME_DNS="gnunet.org"
-TEST_RECORD_NAME_SERVER="server"
-TEST_RECORD_NAME_PLUS="www"
-TEST_RECORD_NAME_DNS="www3"
+TEST_RECORD_NAME_DNS="trust"
+TEST_RECORD_VALUE_SMIMEA="1002 242 53 0 0 1 
d2abde240d7cd3ee6b4b28c54df034b97983a1d16e8a410e4561cb106618e971"
+TEST_RECORD_VALUE_URI='1003 242 256 10 10 "http://lightest.nletlabs.nl/";'
 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
 
 function start_peer
@@ -41,15 +34,30 @@ function stop_peer
 
 
 start_peer
-# Create a public record
-gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t A -V 
$TEST_IP_PLUS -e never -c $CONFIGURATION
+# Create a public SMIMEA record
+gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t A -V 
$TEST_RECORD_VALUE_SMIMEA -e never -c $CONFIGURATION
 NAMESTORE_RES=$?
-stop_peer
 
 if [ $NAMESTORE_RES = 0 ]
 then
-  echo "PASS: Creating name in namestore"
+  echo "PASS: Creating boxed name in namestore SMIMEA"
 else
-  echo "FAIL: Creating name in namestore failed with $NAMESTORE_RES."
+  echo "FAIL: Creating boxed name in namestore failed with $NAMESTORE_RES."
+  stop_peer
   exit 1
 fi
+
+# Create a public URI record
+gnunet-namestore -p -z testego -a -n $TEST_RECORD_NAME_DNS -t A -V 
$TEST_RECORD_VALUE_URI -e never -c $CONFIGURATION
+NAMESTORE_RES=$?
+
+if [ $NAMESTORE_RES = 0 ]
+then
+  echo "PASS: Creating boxed name in namestore URI"
+else
+  echo "FAIL: Creating boxed name in namestore failed with $NAMESTORE_RES."
+  stop_peer
+  exit 1
+fi
+
+stop_peer
\ No newline at end of file
diff --git a/src/include/gnunet_dnsparser_lib.h 
b/src/include/gnunet_dnsparser_lib.h
index 8064b554b..9a84f346f 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -84,6 +84,7 @@
 #define GNUNET_DNSPARSER_TYPE_NSEC3 50
 #define GNUNET_DNSPARSER_TYPE_NSEC3PARAM 51
 #define GNUNET_DNSPARSER_TYPE_TLSA 52
+#define GNUNET_DNSPARSER_TYPE_SMIMEA 53
 #define GNUNET_DNSPARSER_TYPE_HIP 55
 #define GNUNET_DNSPARSER_TYPE_CDS 59
 #define GNUNET_DNSPARSER_TYPE_CDNSKEY 60
@@ -177,6 +178,33 @@ struct GNUNET_DNSPARSER_SrvRecord
 };
 
 
+/**
+ * Information from URI records (RFC 7553).
+ */
+struct GNUNET_DNSPARSER_UriRecord
+{
+  /**
+   * URI of the target,
+   * where the URI is as specified in RFC 3986.
+   */
+  char *target;
+
+  /**
+   * Preference for this entry (lower value is higher preference).  Clients
+   * will contact hosts from the lowest-priority group first and fall back
+   * to higher priorities if the low-priority entries are unavailable.
+   */
+  uint16_t priority;
+
+  /**
+   * Relative weight for records with the same priority.  Clients will use
+   * the hosts of the same (lowest) priority with a probability proportional
+   * to the weight given.
+   */
+  uint16_t weight;
+};
+
+
 /**
  * DNS CERT types as defined in RFC 4398.
  */
@@ -478,6 +506,11 @@ struct GNUNET_DNSPARSER_Record
      */
     struct GNUNET_DNSPARSER_SrvRecord *srv;
 
+    /**
+     * URI data for URI records.
+     */
+    struct GNUNET_DNSPARSER_UriRecord *uri;
+
     /**
      * Raw data for all other types.
      */
@@ -743,6 +776,25 @@ GNUNET_DNSPARSER_builder_add_srv (char *dst,
                                   size_t *off,
                                   const struct GNUNET_DNSPARSER_SrvRecord 
*srv);
 
+
+/**
+ * Add an URI record to the UDP packet at the given location.
+ *
+ * @param dst where to write the URI record
+ * @param dst_len number of bytes in @a dst
+ * @param off pointer to offset where to write the URI information (increment 
by bytes used)
+ *            can also change if there was an error
+ * @param uri URI information to write
+ * @return #GNUNET_SYSERR if @a uri is invalid
+ *         #GNUNET_NO if @a uri did not fit
+ *         #GNUNET_OK if @a uri was added to @a dst
+ */
+int
+GNUNET_DNSPARSER_builder_add_uri (char *dst,
+                                  size_t dst_len,
+                                  size_t *off,
+                                  const struct GNUNET_DNSPARSER_UriRecord 
*uri);
+
 /* ***************** low-level parsing API ******************** */
 
 /**
@@ -853,6 +905,21 @@ GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
                             size_t udp_payload_length,
                             size_t *off);
 
+
+/**
+ * Parse a DNS URI record.
+ *
+ * @param udp_payload reference to UDP packet
+ * @param udp_payload_length length of @a udp_payload
+ * @param off pointer to the offset of the query to parse in the URI record 
(to be
+ *                    incremented by the size of the record), unchanged on 
error
+ * @return the parsed URI record, NULL on error
+ */
+struct GNUNET_DNSPARSER_UriRecord *
+GNUNET_DNSPARSER_parse_uri (const char *udp_payload,
+                            size_t udp_payload_length,
+                            size_t *off);
+
 /* ***************** low-level duplication API ******************** */
 
 /**
@@ -909,6 +976,16 @@ GNUNET_DNSPARSER_duplicate_srv_record (const struct
                                        GNUNET_DNSPARSER_SrvRecord *r);
 
 
+/**
+ * Duplicate (deep-copy) the given DNS record
+ *
+ * @param r the record
+ * @return the newly allocated record
+ */
+struct GNUNET_DNSPARSER_UriRecord *
+GNUNET_DNSPARSER_duplicate_uri_record (const struct
+                                       GNUNET_DNSPARSER_UriRecord *r);
+
 /* ***************** low-level deallocation API ******************** */
 
 /**
@@ -938,6 +1015,15 @@ void
 GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv);
 
 
+/**
+ * Free URI information record.
+ *
+ * @param uri record to free
+ */
+void
+GNUNET_DNSPARSER_free_uri (struct GNUNET_DNSPARSER_UriRecord *uri);
+
+
 /**
  * Free SOA information record.
  *
diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h
index 17acfe5f8..6c7d2cd42 100644
--- a/src/include/gnunet_tun_lib.h
+++ b/src/include/gnunet_tun_lib.h
@@ -549,6 +549,29 @@ struct GNUNET_TUN_DnsSrvRecord
 };
 
 
+/**
+ * Payload of DNS URI record (header).
+ */
+struct GNUNET_TUN_DnsUriRecord
+{
+  /**
+   * Preference for this entry (lower value is higher preference).  Clients
+   * will contact hosts from the lowest-priority group first and fall back
+   * to higher priorities if the low-priority entries are unavailable. (NBO)
+   */
+  uint16_t prio GNUNET_PACKED;
+
+  /**
+   * Relative weight for records with the same priority.  Clients will use
+   * the hosts of the same (lowest) priority with a probability proportional
+   * to the weight given. (NBO)
+   */
+  uint16_t weight GNUNET_PACKED;
+
+  /* followed by 'target' name */
+};
+
+
 /**
  * Payload of DNS CERT record.
  */
diff --git a/src/lib/util/dnsparser.c b/src/lib/util/dnsparser.c
index dab38def7..5dc6dcf5b 100644
--- a/src/lib/util/dnsparser.c
+++ b/src/lib/util/dnsparser.c
@@ -145,6 +145,21 @@ GNUNET_DNSPARSER_free_srv (struct 
GNUNET_DNSPARSER_SrvRecord *srv)
 }
 
 
+/**
+ * Free URI information record.
+ *
+ * @param uri record to free
+ */
+void
+GNUNET_DNSPARSER_free_uri (struct GNUNET_DNSPARSER_UriRecord *uri)
+{
+  if (NULL == uri)
+    return;
+  GNUNET_free (uri->target);
+  GNUNET_free (uri);
+}
+
+
 /**
  * Free MX information record.
  *
@@ -183,6 +198,10 @@ GNUNET_DNSPARSER_free_record (struct 
GNUNET_DNSPARSER_Record *r)
     GNUNET_DNSPARSER_free_srv (r->data.srv);
     break;
 
+  case GNUNET_DNSPARSER_TYPE_URI:
+    GNUNET_DNSPARSER_free_uri (r->data.uri);
+    break;
+
   case GNUNET_DNSPARSER_TYPE_CERT:
     GNUNET_DNSPARSER_free_cert (r->data.cert);
     break;
@@ -505,6 +524,46 @@ GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
 }
 
 
+/**
+ * Parse a DNS URI record.
+ *
+ * @param udp_payload reference to UDP packet
+ * @param udp_payload_length length of @a udp_payload
+ * @param off pointer to the offset of the query to parse in the URI record 
(to be
+ *                    incremented by the size of the record), unchanged on 
error
+ * @return the parsed URI record, NULL on error
+ */
+struct GNUNET_DNSPARSER_UriRecord *
+GNUNET_DNSPARSER_parse_uri (const char *udp_payload,
+                            size_t udp_payload_length,
+                            size_t *off)
+{
+  struct GNUNET_DNSPARSER_UriRecord *uri;
+  struct GNUNET_TUN_DnsUriRecord uri_bin;
+  size_t old_off;
+
+  old_off = *off;
+  if (*off + sizeof(struct GNUNET_TUN_DnsUriRecord) > udp_payload_length)
+    return NULL;
+  GNUNET_memcpy (&uri_bin,
+                 &udp_payload[*off],
+                 sizeof(struct GNUNET_TUN_DnsUriRecord));
+  (*off) += sizeof(struct GNUNET_TUN_DnsUriRecord);
+  uri = GNUNET_new (struct GNUNET_DNSPARSER_UriRecord);
+  uri->priority = ntohs (uri_bin.prio);
+  uri->weight = ntohs (uri_bin.weight);
+  int len =  GNUNET_asprintf(&(uri->target), "%.*s", udp_payload_length - 
sizeof(struct GNUNET_TUN_DnsUriRecord), &udp_payload[*off]);
+  (*off) += len;
+  if (NULL == uri->target) // || GNUNET_STRINGS_parse_uri(uri->target, NULL, 
NULL) == GNUNET_NO)
+  {
+    GNUNET_DNSPARSER_free_uri (uri);
+    *off = old_off;
+    return NULL;
+  }
+  return uri;
+}
+
+
 /**
  * Parse a DNS CERT record.
  *
@@ -633,6 +692,16 @@ GNUNET_DNSPARSER_parse_record (const char *udp_payload,
     }
     return GNUNET_OK;
 
+  case GNUNET_DNSPARSER_TYPE_URI:
+    r->data.uri =
+      GNUNET_DNSPARSER_parse_uri (udp_payload, udp_payload_length, off);
+    if ((NULL == r->data.uri) || (old_off + data_len != *off))
+    {
+      GNUNET_break_op (0);
+      return GNUNET_SYSERR;
+    }
+    return GNUNET_OK;
+
   default:
     r->data.raw.data = GNUNET_malloc (data_len);
     r->data.raw.data_len = data_len;
@@ -768,6 +837,11 @@ GNUNET_DNSPARSER_duplicate_record (const struct 
GNUNET_DNSPARSER_Record *r)
       break;
     }
 
+  case GNUNET_DNSPARSER_TYPE_URI: {
+      dup->data.uri = GNUNET_DNSPARSER_duplicate_uri_record (r->data.uri);
+      break;
+    }
+
   default: {
       dup->data.raw.data = GNUNET_memdup (r->data.raw.data,
                                           r->data.raw.data_len);
@@ -845,6 +919,23 @@ GNUNET_DNSPARSER_duplicate_srv_record (
 }
 
 
+/**
+ * Duplicate (deep-copy) the given DNS record
+ *
+ * @param r the record
+ * @return the newly allocated record
+ */
+struct GNUNET_DNSPARSER_UriRecord *
+GNUNET_DNSPARSER_duplicate_uri_record (
+  const struct GNUNET_DNSPARSER_UriRecord *r)
+{
+  struct GNUNET_DNSPARSER_UriRecord *dup = GNUNET_memdup (r, sizeof(*r));
+
+  dup->target = GNUNET_strdup (r->target);
+  return dup;
+}
+
+
 /**
  * Free memory taken by a packet.
  *
@@ -1140,6 +1231,40 @@ GNUNET_DNSPARSER_builder_add_srv (char *dst,
 }
 
 
+/**
+ * Add an URI record to the UDP packet at the given location.
+ *
+ * @param dst where to write the URI record
+ * @param dst_len number of bytes in @a dst
+ * @param off pointer to offset where to write the URI information (increment 
by bytes used)
+ *            can also change if there was an error
+ * @param uri URI information to write
+ * @return #GNUNET_SYSERR if @a uri is invalid
+ *         #GNUNET_NO if @a uri did not fit
+ *         #GNUNET_OK if @a uri was added to @a dst
+ */
+int
+GNUNET_DNSPARSER_builder_add_uri (char *dst,
+                                  size_t dst_len,
+                                  size_t *off,
+                                  const struct GNUNET_DNSPARSER_UriRecord *uri)
+{
+  struct GNUNET_TUN_DnsUriRecord sd;
+  int ret;
+
+  if (*off + sizeof(struct GNUNET_TUN_DnsUriRecord) > dst_len)
+    return GNUNET_NO;
+  sd.prio = htons (uri->priority);
+  sd.weight = htons (uri->weight);
+  GNUNET_memcpy (&dst[*off], &sd, sizeof(sd));
+  (*off) += sizeof(sd);
+  strncpy(&dst[*off], uri->target, dst_len - sizeof(struct 
GNUNET_TUN_DnsUriRecord) - 1);
+  (*off) += strlen(uri->target);
+  dst[*off++] = '\0'; 
+  return GNUNET_OK;
+}
+
+
 /**
  * Add a DNS record to the UDP packet at the given location.
  *
@@ -1205,6 +1330,11 @@ add_record (char *dst,
       GNUNET_DNSPARSER_builder_add_srv (dst, dst_len, &pos, record->data.srv);
     break;
 
+  case GNUNET_DNSPARSER_TYPE_URI:
+    ret =
+      GNUNET_DNSPARSER_builder_add_uri (dst, dst_len, &pos, record->data.uri);
+    break;
+
   default:
     if (pos + record->data.raw.data_len > dst_len)
     {
diff --git a/src/plugin/gnsrecord/plugin_gnsrecord_dns.c 
b/src/plugin/gnsrecord/plugin_gnsrecord_dns.c
index 5844d9eda..dde5ddcea 100644
--- a/src/plugin/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/plugin/gnsrecord/plugin_gnsrecord_dns.c
@@ -207,7 +207,30 @@ dns_value_to_string (void *cls,
       GNUNET_DNSPARSER_free_srv (srv);
       return result;
     }
+  
+  case GNUNET_DNSPARSER_TYPE_URI: {   // RFC7553
+      struct GNUNET_DNSPARSER_UriRecord *uri;
+      size_t off;
+
+      off = 0;
+      uri = GNUNET_DNSPARSER_parse_uri (data, data_size, &off);
+      if ((NULL == uri) || (off != data_size))
+      {
+        GNUNET_break_op (0);
+        if (NULL != uri)
+          GNUNET_DNSPARSER_free_uri (uri);
+        return NULL;
+      }
+      GNUNET_asprintf (&result,
+                       "%d %d \"%s\"",
+                       uri->priority,
+                       uri->weight,
+                       uri->target);
+      GNUNET_DNSPARSER_free_uri (uri);
+      return result;
+  }
 
+  case GNUNET_DNSPARSER_TYPE_SMIMEA:
   case GNUNET_DNSPARSER_TYPE_TLSA: {
       const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
       char *tlsa_str;
@@ -627,6 +650,52 @@ dns_string_to_value (void *cls,
       return GNUNET_OK;
     }
 
+  case GNUNET_DNSPARSER_TYPE_URI: {
+      struct GNUNET_DNSPARSER_UriRecord uri;
+      char target[strlen(s)];
+      unsigned int priority;
+      unsigned int weight;
+      size_t off;
+
+      if (3 != sscanf (s, "%u %u \"%s", &priority, &weight, &target)) // only 
\" bevor %s becuse %s will consume the ending " of the presentation of the URI 
record
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    _ ("Unable to parse URI record `%s'\n"),
+                    s);
+        return GNUNET_SYSERR;
+      }
+      target[strlen(target)-1] = '\0'; // Removing the last " of the 
presentation of the URI record
+
+      uri.priority = (uint16_t) priority;
+      uri.weight = (uint16_t) weight;
+      uri.target = target;
+      off = 0;
+
+      // TODO add more precise uri checking (RFC3986)
+      if (strstr(target, &":") == NULL || target[0] == 58 || 
target[strlen(target)-1] == 58)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    _ ("Failed to serialize URI record with target `%s'\n"),
+                    target);
+        return GNUNET_SYSERR;
+      }
+
+      char uribuf[sizeof(struct GNUNET_TUN_DnsUriRecord) + strlen(target) + 
1]; 
+
+      if (GNUNET_OK !=
+          GNUNET_DNSPARSER_builder_add_uri (uribuf, sizeof(uribuf), &off, 
&uri))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    _ ("Failed to serialize URI record with target `%s'\n"),
+                    target);
+        return GNUNET_SYSERR;
+      }
+      *data_size = off;
+      *data = GNUNET_malloc (off);
+      GNUNET_memcpy (*data, uribuf, off);
+      return GNUNET_OK;
+    }
+
   case GNUNET_DNSPARSER_TYPE_TXT:
     *data = GNUNET_strdup (s);
     *data_size = strlen (s);
@@ -645,6 +714,7 @@ dns_string_to_value (void *cls,
     GNUNET_memcpy (*data, &value_aaaa, sizeof(value_aaaa));
     return GNUNET_OK;
 
+  case GNUNET_DNSPARSER_TYPE_SMIMEA:
   case GNUNET_DNSPARSER_TYPE_TLSA: {
       unsigned int usage;
       unsigned int selector;
@@ -656,7 +726,7 @@ dns_string_to_value (void *cls,
                        hex))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    _ ("Unable to parse TLSA record string `%s'\n"),
+                    _ ("Unable to parse TLSA/SMIMEA record string `%s'\n"),
                     s);
         *data_size = 0;
         return GNUNET_SYSERR;
@@ -670,7 +740,7 @@ dns_string_to_value (void *cls,
       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"),
+                    _ ("Unable to parse TLSA/SMIMEA record string `%s'\n"),
                     s);
         GNUNET_free (*data);
         *data = NULL;
@@ -727,7 +797,9 @@ static struct
                  { "TXT", GNUNET_DNSPARSER_TYPE_TXT },
                  { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA },
                  { "SRV", GNUNET_DNSPARSER_TYPE_SRV },
+                 { "URI", GNUNET_DNSPARSER_TYPE_URI },
                  { "TLSA", GNUNET_DNSPARSER_TYPE_TLSA },
+                 { "SMIMEA", GNUNET_DNSPARSER_TYPE_SMIMEA },
                  { "CERT", GNUNET_DNSPARSER_TYPE_CERT },
                  { "CAA", GNUNET_DNSPARSER_TYPE_CAA },
                  { NULL, UINT32_MAX } };
diff --git a/src/service/dns/gnunet-dns-monitor.c 
b/src/service/dns/gnunet-dns-monitor.c
index c1ef17255..afdb336f0 100644
--- a/src/service/dns/gnunet-dns-monitor.c
+++ b/src/service/dns/gnunet-dns-monitor.c
@@ -84,6 +84,8 @@ get_type (uint16_t type)
   case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA";
 
   case GNUNET_DNSPARSER_TYPE_SRV: return "SRV";
+
+  case GNUNET_DNSPARSER_TYPE_URI: return "URI";
   }
   GNUNET_snprintf (buf, sizeof(buf), "%u", (unsigned int) type);
   return buf;
@@ -210,6 +212,21 @@ display_record (const struct GNUNET_DNSPARSER_Record 
*record)
       format = tmp;
     }
     break;
+  
+  case GNUNET_DNSPARSER_TYPE_URI:
+    if (NULL == record->data.uri)
+      format = "<invalid>";
+    else
+    {
+      GNUNET_asprintf (&tmp,
+                       "priority %u, weight = %u, target = \"%s\"",
+                       (unsigned int) record->data.uri->priority,
+                       (unsigned int) record->data.uri->weight,
+                       record->data.uri->target);
+      format = tmp;
+    }
+    break;
+
 
   case GNUNET_DNSPARSER_TYPE_TXT:
     GNUNET_asprintf (&tmp,
diff --git a/src/service/dns/gnunet-zonewalk.c 
b/src/service/dns/gnunet-zonewalk.c
index 0526df698..f4b676d6c 100644
--- a/src/service/dns/gnunet-zonewalk.c
+++ b/src/service/dns/gnunet-zonewalk.c
@@ -214,6 +214,15 @@ process_record (struct Request *req,
              rec->data.srv->weight,
              rec->data.srv->port);
     break;
+  
+  case GNUNET_DNSPARSER_TYPE_URI:
+    fprintf (stdout,
+             "%s URI \"%s\" %u %u\n",
+             req->hostname,
+             rec->data.uri->target,
+             rec->data.uri->priority,
+             rec->data.uri->weight);
+    break;
 
   case GNUNET_DNSPARSER_TYPE_PTR:
     fprintf (stdout,
@@ -247,7 +256,6 @@ process_record (struct Request *req,
   case GNUNET_DNSPARSER_TYPE_RP:
   case GNUNET_DNSPARSER_TYPE_TKEY:
   case GNUNET_DNSPARSER_TYPE_TSIG:
-  case GNUNET_DNSPARSER_TYPE_URI:
   case GNUNET_DNSPARSER_TYPE_TA:
 
   /* DNSSEC */
@@ -265,6 +273,7 @@ process_record (struct Request *req,
   case GNUNET_DNSPARSER_TYPE_SSHFP:
   case GNUNET_DNSPARSER_TYPE_IPSECKEY:
   case GNUNET_DNSPARSER_TYPE_TLSA:
+  case GNUNET_DNSPARSER_TYPE_SMIMEA:
   case GNUNET_DNSPARSER_TYPE_OPENPGPKEY:
 
   /* obsolete records */
diff --git a/src/service/gns/gnunet-service-gns_interceptor.c 
b/src/service/gns/gnunet-service-gns_interceptor.c
index f49d60b94..ecd1b5475 100644
--- a/src/service/gns/gnunet-service-gns_interceptor.c
+++ b/src/service/gns/gnunet-service-gns_interceptor.c
@@ -168,6 +168,11 @@ reply_to_dns (void *cls, uint32_t rd_count,
           skip_answers++;
           break;
 
+        case GNUNET_DNSPARSER_TYPE_URI:
+          /* FIXME: URI is not yet supported */
+          skip_answers++;
+          break;
+
         case GNUNET_DNSPARSER_TYPE_MX:
           answer_records[i - skip_answers].data.mx
             = GNUNET_DNSPARSER_parse_mx (rd[i].data,
@@ -245,6 +250,19 @@ reply_to_dns (void *cls, uint32_t rd_count,
           skip_answers++;
           break;
 
+        case GNUNET_DNSPARSER_TYPE_URI:
+          additional_records[i - skip_additional].data.uri
+            = GNUNET_DNSPARSER_parse_uri (rd[i].data,
+                                           rd[i].data_size,
+                                           &off);
+          if ((off != rd[i].data_size) ||
+              (NULL == additional_records[i].data.uri))
+          {
+            GNUNET_break_op (0);
+            skip_additional++;
+          }
+          break;
+
         default:
           additional_records[i - skip_additional].data.raw.data_len =
             rd[i].data_size;
diff --git a/src/service/gns/gnunet-service-gns_resolver.c 
b/src/service/gns/gnunet-service-gns_resolver.c
index aa0189b15..d9cdbd60e 100644
--- a/src/service/gns/gnunet-service-gns_resolver.c
+++ b/src/service/gns/gnunet-service-gns_resolver.c
@@ -579,6 +579,54 @@ timeout_resolution (void *cls)
 }
 
 
+/**
+ * Function called to receive the protocol number for a service.
+ *
+ * @param name name of the protocol
+*/
+static struct protoent *
+resolver_getprotobyname (const char *name)
+{
+  struct protoent *pe = getprotobyname (name);
+  if (pe == NULL && strcmp (name, "trust") == 0)
+  {
+    pe = GNUNET_new (struct protoent);
+    pe->p_name = "trust";
+    pe->p_proto = 242;
+  }
+  return pe;
+}
+
+
+/**
+ * Function called to receive the port number for a service.
+ *
+ * @param name name of the service
+ * @param proto name of the protocol
+*/
+static struct servent *
+resolver_getservbyname (const char *name, const char *proto)
+{
+  struct servent *se = getservbyname (name, proto);
+  if (se == NULL && strcmp (proto, "trust") == 0)
+  {
+    if (strcmp (name, "trustlist") == 0)
+    {
+      se = GNUNET_new (struct servent);
+      se->s_name = "trustlist";
+      se->s_port = htons (1002);
+    }
+    else if (strcmp (name, "scheme") == 0)
+    {
+      se = GNUNET_new (struct servent);
+      se->s_name = "scheme";
+      se->s_port = htons (1003);
+    }
+  }
+  return se;
+}
+
+
 /**
  * Get the next, rightmost label from the name that we are trying to resolve,
  * and update the resolution position accordingly.  Labels usually consist
@@ -662,7 +710,7 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle 
*rh)
                                  rh->name_resolution_pos - (dot - rh->name)
                                  - 2);
     rh->name_resolution_pos = 0;
-    pe = getprotobyname (proto_name);
+    pe = resolver_getprotobyname (proto_name);
     if (NULL == pe)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -672,8 +720,8 @@ resolver_lookup_get_next_label (struct GNS_ResolverHandle 
*rh)
       GNUNET_free (srv_name);
       return ret;
     }
-    se = getservbyname (srv_name,
-                        proto_name);
+    se = resolver_getservbyname (srv_name,
+                                 proto_name);
     if (NULL == se)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1086,6 +1134,22 @@ dns_result_parser (void *cls,
         rd[i - skip].data = &buf[buf_start];
         break;
 
+      case GNUNET_DNSPARSER_TYPE_URI:
+        buf_start = buf_off;
+        if (GNUNET_OK !=
+            GNUNET_DNSPARSER_builder_add_uri (buf,
+                                              sizeof(buf),
+                                              &buf_off,
+                                              rec->data.uri))
+        {
+          GNUNET_break (0);
+          skip++;
+          continue;
+        }
+        rd[i - skip].data_size = buf_off - buf_start;
+        rd[i - skip].data = &buf[buf_start];
+        break;
+
       default:
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                     _ ("Skipping record of unsupported type %d\n"),
@@ -1990,7 +2054,10 @@ handle_gns_resolution_result (void *cls,
       if ((0 != rh->protocol) &&
           (0 != rh->service) &&
           (GNUNET_GNSRECORD_TYPE_BOX != rd[i].record_type))
-        continue;     /* we _only_ care about boxed records */
+        if (GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type &&
+            GNUNET_GNSRECORD_TYPE_EDKEY != rd[i].record_type)
+          continue;
+      /* we _only_ care about boxed records */
 
       GNUNET_assert (rd_off < rd_count);
       rd_new[rd_off] = rd[i];
@@ -2170,6 +2237,45 @@ handle_gns_resolution_result (void *cls,
         }
         break;
 
+      case GNUNET_DNSPARSER_TYPE_URI:
+        {
+          struct GNUNET_DNSPARSER_UriRecord *uri;
+
+          off = 0;
+          uri = GNUNET_DNSPARSER_parse_uri (rd[i].data,
+                                            rd[i].data_size,
+                                            &off);
+          if ((NULL == uri) ||
+              (off != rd[i].data_size))
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                        _ ("Failed to deserialize URI record with target\n"));
+            GNUNET_break_op (0);      /* record not well-formed */
+          }
+          else
+          {
+            scratch_start = scratch_off;
+            if (GNUNET_OK !=
+                GNUNET_DNSPARSER_builder_add_uri (scratch,
+                                                  sizeof(scratch),
+                                                  &scratch_off,
+                                                  uri))
+            {
+              GNUNET_break (0);
+            }
+            else
+            {
+              GNUNET_assert (rd_off < rd_count);
+              rd_new[rd_off].data = &scratch[scratch_start];
+              rd_new[rd_off].data_size = scratch_off - scratch_start;
+              rd_off++;
+            }
+          }
+          if (NULL != uri)
+            GNUNET_DNSPARSER_free_uri (uri);
+        }
+        break;
+
       case GNUNET_GNSRECORD_TYPE_PKEY:
       case GNUNET_GNSRECORD_TYPE_EDKEY:
         {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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