From: Schanzenbach, Martin Date: Sat, 30 Nov 2019 19:27:51 +0000 (+0100) Subject: add support for zkey TLDs in GNS2DNS records X-Git-Tag: v0.12.0~58^2~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=02fcbc17951c0a14357607ad133a8e842d6f463c;p=oweals%2Fgnunet.git add support for zkey TLDs in GNS2DNS records --- diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 764590589..9f0e0bbb6 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -282,6 +282,7 @@ check_SCRIPTS = \ test_gns_caa_lookup.sh\ test_gns_mx_lookup.sh \ test_gns_gns2dns_lookup.sh \ + test_gns_gns2dns_zkey_lookup.sh \ test_gns_gns2dns_cname_lookup.sh \ test_gns_dht_lookup.sh\ test_gns_delegated_lookup.sh \ diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 9792aff58..8639a239b 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -1766,8 +1766,8 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, continue; } tld = GNS_get_tld (ip); - if (0 != strcmp (tld, - "+")) + if ((0 != strcmp (tld, "+")) && + (GNUNET_OK != GNUNET_GNSRECORD_zkey_to_pkey (tld, &zone))) { /* 'ip' is a DNS name */ gp = GNUNET_new (struct Gns2DnsPending); @@ -1790,16 +1790,19 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, ac->authority_info.dns_authority.gp_tail, gp); gp->rh = GNUNET_new (struct GNS_ResolverHandle); - ip = translate_dot_plus (rh, - ip); - tld = GNS_get_tld (ip); - if (GNUNET_OK != - GNUNET_GNSRECORD_zkey_to_pkey (tld, - &zone)) + if (0 == strcmp (tld, "+")) { - GNUNET_break_op (0); - GNUNET_free (ip); - continue; + ip = translate_dot_plus (rh, + ip); + tld = GNS_get_tld (ip); + if (GNUNET_OK != + GNUNET_GNSRECORD_zkey_to_pkey (tld, + &zone)) + { + GNUNET_break_op (0); + GNUNET_free (ip); + continue; + } } gp->rh->authority_zone = zone; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1845,7 +1848,7 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, if (IDNA_SUCCESS != idna_to_ascii_8z (tmp, &ac->label, IDNA_ALLOW_UNASSIGNED)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Name `%s' cannot be converted to IDNA."), tmp); + _ ("Name `%s' cannot be converted to IDNA."), tmp); return GNUNET_SYSERR; } GNUNET_free (tmp); diff --git a/src/gns/test_gns_gns2dns_zkey_lookup.sh b/src/gns/test_gns_gns2dns_zkey_lookup.sh new file mode 100755 index 000000000..5c2cddd3c --- /dev/null +++ b/src/gns/test_gns_gns2dns_zkey_lookup.sh @@ -0,0 +1,114 @@ +#!/bin/sh +trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT + +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` +# IP address of 'docs.gnunet.org' +TEST_IP_ALT2="147.87.255.218" +# IP address of 'www.gnunet.org' +TEST_IP="131.159.74.67" +# IPv6 address of 'gnunet.org' +TEST_IP6="2001:4ca0:2001:42:225:90ff:fe6b:d60" +# permissive DNS resolver we will use for the test +TEST_IP_GNS2DNS="8.8.8.8" + +# main label used during resolution +TEST_RECORD_NAME="homepage" + +if ! nslookup gnunet.org $TEST_IP_GNS2DNS > /dev/null 2>&1 +then + echo "Cannot reach DNS, skipping test" + exit 77 +fi + +# helper record for pointing to the DNS resolver +TEST_RESOLVER_LABEL="resolver" + +MY_EGO="myego" +# various names we will use for resolution +TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO" +TEST_DOMAIN_ALT="${TEST_RECORD_NAME}.$MY_EGO" +TEST_DOMAIN_ALT2="docs.${TEST_RECORD_NAME}.$MY_EGO" + +which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 15" + + +gnunet-arm -s -c test_gns_lookup.conf + +OUT=`$DO_TIMEOUT gnunet-resolver -c test_gns_lookup.conf gnunet.org` +echo $OUT | grep $TEST_IP - > /dev/null || { gnunet-arm -e -c test_gns_lookup.conf ; echo "IPv4 for gnunet.org not found ($OUT), skipping test"; exit 77; } +echo $OUT | grep $TEST_IP6 - > /dev/null || { gnunet-arm -e -c test_gns_lookup.conf ; echo "IPv6 for gnunet.org not found ($OUT), skipping test"; exit 77; } + + + +gnunet-identity -C $MY_EGO -c test_gns_lookup.conf +MY_EGO_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep ${MY_EGO} | awk '{print $3}') +# GNS2DNS record value: delegate to DNS domain 'gnunet.org' +# using the TEST_RESOLVER_LABEL DNS server for resolution +TEST_RECORD_GNS2DNS="gnunet.org@${TEST_RESOLVER_LABEL}.${MY_EGO_PKEY}" + +# set IP address for DNS resolver for resolving in gnunet.org domain +gnunet-namestore -p -z $MY_EGO -a -n $TEST_RESOLVER_LABEL -t A -V $TEST_IP_GNS2DNS -e never -c test_gns_lookup.conf +# map '$TEST_RECORD_NAME.$MY_EGO' to 'gnunet.org' in DNS +gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf + +# lookup 'www.gnunet.org', IPv4 +RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t A -c test_gns_lookup.conf` +# lookup 'www.gnunet.org', IPv6 +RES_IP6=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t AAAA -c test_gns_lookup.conf` +# lookup 'gnunet.org', IPv4 +RES_IP_ALT=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN_ALT -t A -c test_gns_lookup.conf` +# lookup 'docs.gnunet.org', IPv4 +RES_IP_ALT2=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN_ALT2 -t A -c test_gns_lookup.conf` + +# clean up +gnunet-namestore -z $MY_EGO -d -n $TEST_RESOLVER_LABEL -t A -V $TEST_IP_GNS2DNS -e never -c test_gns_lookup.conf +gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -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` + +ret=0 +if echo "$RES_IP" | grep "$TEST_IP" > /dev/null +then + echo "PASS: Resolved $TEST_DOMAIN to $RES_IP." +else + echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP, wanted $TEST_IP." + ret=1 +fi + +if [ "$RES_IP6" = "$TEST_IP6" ] +then + echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6." +else + echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP6, wanted $TEST_IP6." + ret=1 +fi + +if echo "$RES_IP_ALT" | grep "$TEST_IP" > /dev/null +then + echo "PASS: Resolved $TEST_DOMAIN_ALT to $RES_IP_ALT." +else + echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT, got $RES_IP_ALT, wanted $TEST_IP." + ret=1 +fi + +if echo "$RES_IP_ALT2" | grep "$TEST_IP_ALT2" > /dev/null +then + echo "PASS: Resolved $TEST_DOMAIN_ALT2 to $RES_IP_ALT2." +else + echo "Failed to resolve to proper IP for $TEST_DOMAIN_ALT2, got $RES_IP_ALT2, wanted $TEST_IP_ALT2." + ret=1 +fi +exit $ret