Skip to content

Commit

Permalink
experimental IDNA-fication
Browse files Browse the repository at this point in the history
  • Loading branch information
dlenski committed Sep 5, 2024
1 parent d1f419a commit daabf8a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vpn_slice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def do_post_connect(env, args):
for ip, aliases in args.aliases.items():
host_map.append((ip, aliases))

# convert any non-ASCII hostnames to internationalized hostnames
# (FIXME: is this really a sensible thing to do? Does anything besides
# web browsers actually understand these? OpenSSH certainly doesn't.)
host_map = [(ip, [providers.dns.encode_intl(n) for n in names]) for (ip, names) in host_map]

# add them to /etc/hosts
if host_map:
providers.hosts.write_hosts(host_map, args.name)
Expand Down
3 changes: 3 additions & 0 deletions vpn_slice/dnspython.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ def lookup_srv(self, query):
result.update((x.priority, x.weight, str(x.target).rstrip('.')) for x in a)

return [r[2] for r in sorted(result)]

def encode_intl(self, name):
return from_text(name).to_text(True)
9 changes: 9 additions & 0 deletions vpn_slice/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def lookup_srv(self, query):
interpretation of these results.
"""

def encode_intl(self, hostname):
"""Convert a potentially non-ASCII hostname to its
internationalized representation, for example
(following IDNA2003):
www.foobár.com -> www.xn--foobr-0qa.com"""
if hostname.isascii():
return hostname
raise NotImplementedError()

class HostsProvider(metaclass=ABCMeta):
@abstractmethod
def write_hosts(self, host_map, name):
Expand Down

0 comments on commit daabf8a

Please sign in to comment.