28
28
#include "arc-types.h"
29
29
#include "arc-util.h"
30
30
31
+ /* libidn2 */
32
+ #include <idn2.h>
33
+
31
34
/* libbsd if found */
32
35
#ifdef USE_BSD_H
33
36
#include <bsd/string.h>
@@ -85,7 +88,7 @@ arc_get_key_dns(ARC_MESSAGE *msg, char *buf, size_t buflen)
85
88
unsigned char * cp ;
86
89
unsigned char * eom ;
87
90
char * eob ;
88
- unsigned char qname [ARC_MAXHOSTNAMELEN + 1 ];
91
+ char qname [ARC_MAXHOSTNAMELEN + 1 ];
89
92
unsigned char ansbuf [MAXPACKET ];
90
93
struct timeval timeout ;
91
94
HEADER hdr ;
@@ -96,14 +99,32 @@ arc_get_key_dns(ARC_MESSAGE *msg, char *buf, size_t buflen)
96
99
97
100
lib = msg -> arc_library ;
98
101
99
- n = snprintf (( char * ) qname , sizeof qname - 1 , "%s.%s.%s" ,
100
- msg -> arc_selector , ARC_DNSKEYNAME , msg -> arc_domain );
102
+ n = snprintf (qname , sizeof qname - 1 , "%s.%s.%s" , msg -> arc_selector ,
103
+ ARC_DNSKEYNAME , msg -> arc_domain );
101
104
if (n == -1 || n > sizeof qname - 1 )
102
105
{
103
106
arc_error (msg , "key query name too large" );
104
107
return ARC_STAT_NORESOURCE ;
105
108
}
106
109
110
+ char * qname_idn ;
111
+ status = idn2_to_ascii_8z (qname , & qname_idn ,
112
+ IDN2_NONTRANSITIONAL | IDN2_NFC_INPUT );
113
+ if (status != IDN2_OK )
114
+ {
115
+ arc_error (msg , "failed to translate %s to ASCII: %s" , qname ,
116
+ idn2_strerror (status ));
117
+ return ARC_STAT_KEYFAIL ;
118
+ }
119
+
120
+ if (strlcpy (qname , qname_idn , sizeof qname ) >= sizeof qname )
121
+ {
122
+ arc_error (msg , "key query name too large" );
123
+ idn2_free (qname_idn );
124
+ return ARC_STAT_NORESOURCE ;
125
+ }
126
+ idn2_free (qname_idn );
127
+
107
128
anslen = sizeof ansbuf ;
108
129
109
130
timeout .tv_sec = msg -> arc_timeout ;
@@ -116,8 +137,8 @@ arc_get_key_dns(ARC_MESSAGE *msg, char *buf, size_t buflen)
116
137
return ARC_STAT_KEYFAIL ;
117
138
}
118
139
119
- status = lib -> arcl_dns_start (lib -> arcl_dns_service , T_TXT , qname , ansbuf ,
120
- anslen , & q );
140
+ status = lib -> arcl_dns_start (lib -> arcl_dns_service , T_TXT ,
141
+ ( unsigned char * ) qname , ansbuf , anslen , & q );
121
142
122
143
if (status != 0 )
123
144
{
@@ -199,7 +220,7 @@ arc_get_key_dns(ARC_MESSAGE *msg, char *buf, size_t buflen)
199
220
for (qdcount = ntohs ((unsigned short ) hdr .qdcount ); qdcount > 0 ; qdcount -- )
200
221
{
201
222
/* copy it first */
202
- (void ) dn_expand ((unsigned char * ) & ansbuf , eom , cp , ( char * ) qname ,
223
+ (void ) dn_expand ((unsigned char * ) & ansbuf , eom , cp , qname ,
203
224
sizeof qname );
204
225
205
226
if ((n = dn_skipname (cp , eom )) < 0 )
@@ -408,8 +429,17 @@ arc_get_key_file(ARC_MESSAGE *msg, char *buf, size_t buflen)
408
429
return ARC_STAT_NORESOURCE ;
409
430
}
410
431
432
+ char * idn_name ;
433
+ if (idn2_to_ascii_8z (name , & idn_name ,
434
+ IDN2_NONTRANSITIONAL | IDN2_NFC_INPUT ) != IDN2_OK )
435
+ {
436
+ arc_error (msg , "failed to translate %s to ASCII" , name );
437
+ fclose (f );
438
+ return ARC_STAT_KEYFAIL ;
439
+ }
440
+
411
441
memset (buf , '\0' , buflen );
412
- while (fgets (( char * ) buf , buflen , f ) != NULL )
442
+ while (fgets (buf , buflen , f ) != NULL )
413
443
{
414
444
if (buf [0 ] == '#' )
415
445
{
@@ -436,14 +466,16 @@ arc_get_key_file(ARC_MESSAGE *msg, char *buf, size_t buflen)
436
466
}
437
467
}
438
468
439
- if (strcasecmp (( char * ) name , ( char * ) buf ) == 0 && p2 != NULL )
469
+ if (strcasecmp (idn_name , buf ) == 0 && p2 != NULL )
440
470
{
441
471
memmove (buf , p2 , strlen (p2 ) + 1 );
472
+ idn2_free (idn_name );
442
473
fclose (f );
443
474
return ARC_STAT_OK ;
444
475
}
445
476
}
446
477
478
+ idn2_free (idn_name );
447
479
fclose (f );
448
480
449
481
return ARC_STAT_NOKEY ;
0 commit comments