Switch from libidn to libidn2 to get IDN conversion conforming to IDNA2008 + TR46 specifications (RFC 5890, RFC 5891, RFC 5892, RFC 5893, TR 46)

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-11-20 08:58:48 +01:00
parent 7f0a0a77da
commit 07f040ea0b
4 changed files with 17 additions and 15 deletions
+5 -2
View File
@@ -283,9 +283,12 @@ find_package(Threads REQUIRED)
find_library(LIBHOGWEED NAMES libhogweed${CMAKE_STATIC_LIBRARY_SUFFIX} hogweed HINTS /usr/local/lib64)
find_library(LIBGMP NAMES libgmp${CMAKE_STATIC_LIBRARY_SUFFIX} gmp)
find_library(LIBNETTLE NAMES libnettle${CMAKE_STATIC_LIBRARY_SUFFIX} nettle HINTS /usr/local/lib64)
find_library(LIBIDN NAMES libidn${CMAKE_STATIC_LIBRARY_SUFFIX} idn)
target_link_libraries(pihole-FTL rt Threads::Threads ${LIBHOGWEED} ${LIBGMP} ${LIBNETTLE} ${LIBIDN})
# for IDN2 we need the idn2 library which in turn depends on the unistring library
find_library(LIBIDN2 NAMES libidn2${CMAKE_STATIC_LIBRARY_SUFFIX} idn)
find_library(LIBUNISTRING NAMES libunistring${CMAKE_STATIC_LIBRARY_SUFFIX} unistring)
target_link_libraries(pihole-FTL rt Threads::Threads ${LIBHOGWEED} ${LIBGMP} ${LIBNETTLE} ${LIBIDN2} ${LIBUNISTRING})
if(LUA_DL STREQUAL "true")
find_library(LIBDL dl)
+6 -7
View File
@@ -19,8 +19,7 @@
#include "database/network-table.h"
// valid_domain()
#include "tools/gravity-parseList.h"
#include <idna.h>
#include <idn2.h>
static int api_list_read(struct ftl_conn *api,
const int code,
@@ -75,9 +74,9 @@ static int api_list_read(struct ftl_conn *api,
else // domainlists
{
char *unicode = NULL;
const Idna_rc rc = idna_to_unicode_lzlz(table.domain, &unicode, 0);
const int rc = idn2_to_unicode_lzlz(table.domain, &unicode, IDN2_NONTRANSITIONAL);
JSON_COPY_STR_TO_OBJECT(row, "domain", table.domain);
if(rc == IDNA_SUCCESS)
if(rc == IDN2_OK)
JSON_COPY_STR_TO_OBJECT(row, "unicode", unicode);
else
JSON_COPY_STR_TO_OBJECT(row, "unicode", table.domain);
@@ -417,14 +416,14 @@ static int api_list_write(struct ftl_conn *api,
listtype == GRAVITY_DOMAINLIST_DENY_EXACT)
{
char *punycode = NULL;
const Idna_rc rc = idna_to_ascii_lz(it->valuestring, &punycode, 0);
if (rc != IDNA_SUCCESS)
const int rc = idn2_to_ascii_lz(it->valuestring, &punycode, IDN2_NONTRANSITIONAL);
if (rc != IDN2_OK)
{
// Invalid domain name
return send_json_error(api, 400,
"bad_request",
"Invalid request: Invalid domain name",
idna_strerror(rc));
idn2_strerror(rc));
}
// Convert punycode domain to lowercase
for(unsigned int i = 0u; i < strlen(punycode); i++)
+5 -5
View File
@@ -15,7 +15,7 @@
#include "database/gravity-db.h"
// match_regex()
#include "regex_r.h"
#include <idna.h>
#include <idn2.h>
#define MAX_SEARCH_RESULTS 10000u
@@ -182,18 +182,18 @@ int api_search(struct ftl_conn *api)
// use characters drawn from a large repertoire (Unicode), but IDNA
// allows the non-ASCII characters to be represented using only the
// ASCII characters already allowed in so-called host names today.
// idna_to_ascii_lz() convert domain name in the locales encoding to an
// idn2_to_ascii_lz() convert domain name in the locales encoding to an
// ASCII string. The domain name may contain several labels, separated
// by dots. The output buffer must be deallocated by the caller.
char *punycode = NULL;
const Idna_rc rc = idna_to_ascii_lz(domain, &punycode, 0);
if (rc != IDNA_SUCCESS)
const int rc = idn2_to_ascii_lz(domain, &punycode, IDN2_NONTRANSITIONAL);
if (rc != IDN2_OK)
{
// Invalid domain name
return send_json_error(api, 400,
"bad_request",
"Invalid request: Invalid domain name",
idna_strerror(rc));
idn2_strerror(rc));
}
// Convert punycode domain to lowercase
+1 -1
View File
@@ -205,7 +205,7 @@ RESOLVFILE
/* Pi-hole definitions */
#define HAVE_LUASCRIPT
#define HAVE_IDN
#define HAVE_LIBIDN2
#define HAVE_DNSSEC
#ifdef DNSMASQ_ALL_OPTS
#define HAVE_DBUS