Skip to content

ValueError when attempting to connect to host via link-local IPv6 Address #169

@AdmiralNemo

Description

@AdmiralNemo

I encountered this issue today when deploying a service on a network that exclusively uses link-local addressing and multicast DNS.

Traceback (most recent call last):
  …
  File "/usr/lib64/python3.6/site-packages/asyncssh/connection.py", line 5107, in create_connection
    yield from auth_waiter
  File "/usr/lib64/python3.6/site-packages/asyncssh/connection.py", line 582, in connection_made
    self._connection_made()
  File "/usr/lib64/python3.6/site-packages/asyncssh/connection.py", line 2239, in _connection_made
    self._peer_addr, port)
  File "/usr/lib64/python3.6/site-packages/asyncssh/connection.py", line 473, in _match_known_hosts
    match_known_hosts(known_hosts, host, addr, port)
  File "/usr/lib64/python3.6/site-packages/asyncssh/known_hosts.py", line 324, in match_known_hosts
    known_hosts = known_hosts.match(host, addr, port)
  File "/usr/lib64/python3.6/site-packages/asyncssh/known_hosts.py", line 236, in match
    x509_subjects, revoked_subjects = self._match(host, addr, port)
  File "/usr/lib64/python3.6/site-packages/asyncssh/known_hosts.py", line 172, in _match
    ip = ip_address(addr) if addr else None
  File "/usr/lib64/python3.6/site-packages/asyncssh/misc.py", line 121, in ip_address
    return ipaddress.ip_address(_normalize_scoped_ip(addr))
  File "/usr/lib64/python3.6/ipaddress.py", line 54, in ip_address
    address)
ValueError: 'fe80::1298:36ff:fea1:892d%ens224' does not appear to be an IPv4 or IPv6 address

The host in question was specified by name (i.e. thehostname.local), which was resolved by Avahi/libnss_mdns_minimal. The problem is that getpeername returns an IPv6 address including the scope ID for link-local addresses, but the match_known_hosts function does not handle the scope ID correctly. I think the problem is the impedance mismatch between what the ipaddress module considers to be a valid address versus what the socket library needs. I am not sure what the best solution here would be. Since both the raw and parsed values for the address are passed to the match routine, perhaps ignoring the ValueError would be sufficient.

To work around the problem, I had to enable IPv4 link-local addressing on both the client and the server, and disable mDNS resolution to IPv6 addresses on the client.

CentOS Linux release 7.5.1804 (Core)
asyncssh-1.14.0
python36-3.6.6-1.el7.x86_64 (via EPEL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions