diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-07 00:24:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-07 00:24:59 +0000 |
commit | 222e534eed64a24d843e0ee676579ea9b6264bbc (patch) | |
tree | 697ecd3137dbb87428be857fad1134787fc951bc /src | |
parent | 0925fad2014e4910d44bb4d9d9681da4e6962e49 (diff) | |
download | gnunet-222e534eed64a24d843e0ee676579ea9b6264bbc.tar.gz gnunet-222e534eed64a24d843e0ee676579ea9b6264bbc.zip |
more tlsa fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/dns/dnsparser.c | 37 | ||||
-rw-r--r-- | src/gnsrecord/plugin_gnsrecord_dns.c | 39 | ||||
-rw-r--r-- | src/include/gnunet_dnsparser_lib.h | 27 |
3 files changed, 91 insertions, 12 deletions
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c index 338591644..97f47333b 100644 --- a/src/dns/dnsparser.c +++ b/src/dns/dnsparser.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -1229,4 +1229,39 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p, | |||
1229 | return GNUNET_OK; | 1229 | return GNUNET_OK; |
1230 | } | 1230 | } |
1231 | 1231 | ||
1232 | |||
1233 | /** | ||
1234 | * Convert a block of binary data to HEX. | ||
1235 | * | ||
1236 | * @param data binary data to convert | ||
1237 | * @param data_size number of bytes in @a data | ||
1238 | * @return HEX string (lower case) | ||
1239 | */ | ||
1240 | char * | ||
1241 | GNUNET_DNSPARSER_bin_to_hex (const void *data, | ||
1242 | size_t data_size) | ||
1243 | { | ||
1244 | GNUNET_break (0); // FIXME: not implemented | ||
1245 | return NULL; | ||
1246 | } | ||
1247 | |||
1248 | |||
1249 | /** | ||
1250 | * Convert a HEX string to block of binary data. | ||
1251 | * | ||
1252 | * @param hex HEX string to convert (may contain mixed case) | ||
1253 | * @param data where to write result, must be | ||
1254 | * at least `strlen(hex)/2` bytes long | ||
1255 | * @return number of bytes written to data | ||
1256 | */ | ||
1257 | size_t | ||
1258 | GNUNET_DNSPARSER_hex_to_bin (const char *hex, | ||
1259 | void *data) | ||
1260 | { | ||
1261 | GNUNET_break (0); // FIXME: not implemented | ||
1262 | return 0; | ||
1263 | } | ||
1264 | |||
1265 | |||
1266 | |||
1232 | /* end of dnsparser.c */ | 1267 | /* end of dnsparser.c */ |
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c index b52dee374..b55d595d4 100644 --- a/src/gnsrecord/plugin_gnsrecord_dns.c +++ b/src/gnsrecord/plugin_gnsrecord_dns.c | |||
@@ -44,7 +44,6 @@ dns_value_to_string (void *cls, | |||
44 | const void *data, | 44 | const void *data, |
45 | size_t data_size) | 45 | size_t data_size) |
46 | { | 46 | { |
47 | const char *cdata; | ||
48 | char* result; | 47 | char* result; |
49 | char tmp[INET6_ADDRSTRLEN]; | 48 | char tmp[INET6_ADDRSTRLEN]; |
50 | 49 | ||
@@ -231,23 +230,26 @@ dns_value_to_string (void *cls, | |||
231 | case GNUNET_DNSPARSER_TYPE_TLSA: | 230 | case GNUNET_DNSPARSER_TYPE_TLSA: |
232 | { | 231 | { |
233 | const struct GNUNET_TUN_DnsTlsaRecord *tlsa; | 232 | const struct GNUNET_TUN_DnsTlsaRecord *tlsa; |
234 | char* tlsa_str; | 233 | char *tlsa_str; |
234 | char *hex; | ||
235 | 235 | ||
236 | cdata = data; | 236 | if (data_size < sizeof (struct GNUNET_TUN_DnsTlsaRecord)) |
237 | if ( (data_size <= sizeof (struct GNUNET_TUN_DnsTlsaRecord)) || | ||
238 | ('\0' != cdata[data_size - 1]) ) | ||
239 | return NULL; /* malformed */ | 237 | return NULL; /* malformed */ |
240 | tlsa = data; | 238 | tlsa = data; |
239 | hex = GNUNET_DNSPARSER_bin_to_hex (&tlsa[1], | ||
240 | data_size - sizeof (struct GNUNET_TUN_DnsTlsaRecord)); | ||
241 | if (0 == GNUNET_asprintf (&tlsa_str, | 241 | if (0 == GNUNET_asprintf (&tlsa_str, |
242 | "%u %u %u %s", | 242 | "%u %u %u %s", |
243 | (unsigned int) tlsa->usage, | 243 | (unsigned int) tlsa->usage, |
244 | (unsigned int) tlsa->selector, | 244 | (unsigned int) tlsa->selector, |
245 | (unsigned int) tlsa->matching_type, | 245 | (unsigned int) tlsa->matching_type, |
246 | (const char *) &tlsa[1])) | 246 | hex)) |
247 | { | 247 | { |
248 | GNUNET_free (hex); | ||
248 | GNUNET_free (tlsa_str); | 249 | GNUNET_free (tlsa_str); |
249 | return NULL; | 250 | return NULL; |
250 | } | 251 | } |
252 | GNUNET_free (hex); | ||
251 | return tlsa_str; | 253 | return tlsa_str; |
252 | } | 254 | } |
253 | default: | 255 | default: |
@@ -603,23 +605,40 @@ dns_string_to_value (void *cls, | |||
603 | unsigned int usage; | 605 | unsigned int usage; |
604 | unsigned int selector; | 606 | unsigned int selector; |
605 | unsigned int matching_type; | 607 | unsigned int matching_type; |
608 | size_t slen = strlen (s) + 1; | ||
609 | char hex[slen]; | ||
606 | 610 | ||
607 | *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (s) - 6; | ||
608 | *data = tlsa = GNUNET_malloc (*data_size); | ||
609 | if (4 != SSCANF (s, | 611 | if (4 != SSCANF (s, |
610 | "%u %u %u %s", | 612 | "%u %u %u %s", |
611 | (char*)&tlsa[1])) | 613 | &usage, |
614 | &selector, | ||
615 | &matching_type, | ||
616 | hex)) | ||
612 | { | 617 | { |
613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 618 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
614 | _("Unable to parse TLSA record string `%s'\n"), | 619 | _("Unable to parse TLSA record string `%s'\n"), |
615 | s); | 620 | s); |
616 | *data_size = 0; | 621 | *data_size = 0; |
617 | GNUNET_free (tlsa); | ||
618 | return GNUNET_SYSERR; | 622 | return GNUNET_SYSERR; |
619 | } | 623 | } |
624 | |||
625 | *data_size = sizeof (struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2; | ||
626 | *data = tlsa = GNUNET_malloc (*data_size); | ||
620 | tlsa->usage = (uint8_t) usage; | 627 | tlsa->usage = (uint8_t) usage; |
621 | tlsa->selector = (uint8_t) selector; | 628 | tlsa->selector = (uint8_t) selector; |
622 | tlsa->matching_type = (uint8_t) matching_type; | 629 | tlsa->matching_type = (uint8_t) matching_type; |
630 | if (strlen (hex) / 2 != | ||
631 | GNUNET_DNSPARSER_hex_to_bin (hex, | ||
632 | &tlsa[1])) | ||
633 | { | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
635 | _("Unable to parse TLSA record string `%s'\n"), | ||
636 | s); | ||
637 | GNUNET_free (*data); | ||
638 | *data = NULL; | ||
639 | *data_size = 0; | ||
640 | return GNUNET_SYSERR; | ||
641 | } | ||
623 | return GNUNET_OK; | 642 | return GNUNET_OK; |
624 | } | 643 | } |
625 | default: | 644 | default: |
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h index fc4b7444e..2684a794b 100644 --- a/src/include/gnunet_dnsparser_lib.h +++ b/src/include/gnunet_dnsparser_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -859,4 +859,29 @@ void | |||
859 | GNUNET_DNSPARSER_free_cert (struct GNUNET_DNSPARSER_CertRecord *cert); | 859 | GNUNET_DNSPARSER_free_cert (struct GNUNET_DNSPARSER_CertRecord *cert); |
860 | 860 | ||
861 | 861 | ||
862 | /** | ||
863 | * Convert a block of binary data to HEX. | ||
864 | * | ||
865 | * @param data binary data to convert | ||
866 | * @param data_size number of bytes in @a data | ||
867 | * @return HEX string (lower case) | ||
868 | */ | ||
869 | char * | ||
870 | GNUNET_DNSPARSER_bin_to_hex (const void *data, | ||
871 | size_t data_size); | ||
872 | |||
873 | |||
874 | /** | ||
875 | * Convert a HEX string to block of binary data. | ||
876 | * | ||
877 | * @param hex HEX string to convert (may contain mixed case) | ||
878 | * @param data where to write result, must be | ||
879 | * at least `strlen(hex)/2` bytes long | ||
880 | * @return number of bytes written to data | ||
881 | */ | ||
882 | size_t | ||
883 | GNUNET_DNSPARSER_hex_to_bin (const char *hex, | ||
884 | void *data); | ||
885 | |||
886 | |||
862 | #endif | 887 | #endif |