diff --git a/CHANGELOG.md b/CHANGELOG.md index 386e2ad..a9fe33d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `uninstall_package()` already does (#4). It used to search the output for words like "failed": an install whose postinst merely mentioned a failure read as failed, and a failure that used none of the words read as success. +- `get_vpn_tunnels()` makes the public-key prefix in a WireGuard peer's key URL-safe + (`+` becomes `-`, `/` becomes `_`), as napalm-opnsense does (#43). A key with `/` + could not be used as a URL path segment, so such a tunnel could not be edited in + netOrk. The key of a peer whose first eight key characters hold `+` or `/` changes + once; `public_key` is reported unchanged. ## [0.15.1] - 2026-10-23 diff --git a/napalm_linux/linux.py b/napalm_linux/linux.py index 3cf3de4..25a95a1 100644 --- a/napalm_linux/linux.py +++ b/napalm_linux/linux.py @@ -2112,8 +2112,8 @@ class LinuxDriver( Falls back to interface-level data from ``ip link`` + ``/proc/net/dev`` when root access is unavailable. - Full data keyed by ``wireguard--`` (one entry per peer). - Fallback keyed by ``wireguard-`` (one entry per WireGuard interface). + Full data keyed by ``wireguard--``, one per peer, URL-safe + (``+`` → ``-``, ``/`` → ``_``); the fallback by ``wireguard-``, one per interface. """ import time as _time @@ -2190,7 +2190,7 @@ class LinuxDriver( local_port = listen_ports.get(iface, "") local_ep = f":{local_port}" if local_port and local_port != "0" else "" - key = f"wireguard-{iface}-{pubkey[:8]}" + key = f"wireguard-{iface}-{pubkey[:8].replace('+', '-').replace('/', '_')}" tunnels[key] = { "type": "WireGuard", "local_endpoint": local_ep, diff --git a/tests/test_linux.py b/tests/test_linux.py index dda30af..b68f1da 100644 --- a/tests/test_linux.py +++ b/tests/test_linux.py @@ -2040,3 +2040,28 @@ class TestHardensItsSshServer: with patch.object(driver, "run_command", return_value=CommandResult(out, "", 0)) as run: assert driver.get_ssh_server_algorithms()["mac"] == ["d"] assert run.call_args.kwargs["privileged"] is True + + +class TestWireGuardTunnelKeys: + """A tunnel's key is a URL path segment for its consumer (#43): the public + key's base64 prefix is made URL-safe, as napalm-opnsense does.""" + + _DUMP = ( + "wg0\tPRIVKEY\tSERVERPUBKEY=\t51820\toff\n" + "wg0\tab/c+d9EfGhIjKlMnOpQrStUvWxYz0123456789AB=\t(none)\t" + "198.51.100.7:51820\t10.8.0.2/32\t0\t1024\t2048\toff\n" + ) + + def test_a_slash_or_plus_in_the_key_prefix_is_url_safe(self, driver): + _mock_send(driver, self._DUMP) + + tunnels = driver.get_vpn_tunnels() + + assert list(tunnels) == ["wireguard-wg0-ab_c-d9E"] + + def test_the_public_key_itself_is_reported_unchanged(self, driver): + _mock_send(driver, self._DUMP) + + (tunnel,) = driver.get_vpn_tunnels().values() + + assert tunnel["public_key"] == "ab/c+d9EfGhIjKlMnOpQrStUvWxYz0123456789AB="