diff --git a/vpn_slice/__main__.py b/vpn_slice/__main__.py index 01c60b8..fe7ba8d 100755 --- a/vpn_slice/__main__.py +++ b/vpn_slice/__main__.py @@ -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) diff --git a/vpn_slice/dnspython.py b/vpn_slice/dnspython.py index 42a2169..8d3a297 100644 --- a/vpn_slice/dnspython.py +++ b/vpn_slice/dnspython.py @@ -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) \ No newline at end of file diff --git a/vpn_slice/provider.py b/vpn_slice/provider.py index c9c43f7..f5c35db 100644 --- a/vpn_slice/provider.py +++ b/vpn_slice/provider.py @@ -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):