fix(vpn): make the WireGuard peer key's prefix URL-safe
get_vpn_tunnels keyed a peer as wireguard-<iface>-<pubkey[:8]>. Base64 uses "/" and "+", and the key is used as a URL path segment; a "/" breaks the route even percent-encoded. The prefix now maps "+" to "-" and "/" to "_", as napalm-opnsense does (NAPALM/napalm-opnsense#32). Affected peers change their key once. Closes #43
This commit is contained in:
1 parent
eaa08ae7e3
commit
df4f4b0e4d
3 files changed
+33
-3
No files matched your search
@@ -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="
|
||||
Reference in new issue
Block a user