fix(dal): decrypt the DAL's answer before reading it (#25)

A GET of the DAL answers sealed ({"content", "iv"}), like a PUT does.
_read_dal_or_page parsed the envelope as it came, so hosts, the ARP
table, port forwards and the Wi-Fi getters found nothing on every
gateway, and since nothing raised the HTML fallback never ran either.

Every DAL GET now goes through one helper that decrypts the answer,
checks for ZCFG_SUCCESS and returns its Object list; the status page
and the System page share the decryption. Hosts are read from
lanhosts and port forwards from nat, the names the gateway's web
interface uses: LAN_HOSTS and NAT_PORTMAP are answered like any
unknown name, with an empty Object. The new parsers live in
napalm_zyxel/parsers.py, under strict mypy.

Tests seal recorded, anonymised answers of a VMG4005-B50A
(V5.17(ABQA.3.1)C0) with a real ZyxelCrypto, so the driver decrypts
them. The Wi-Fi DAL names stay unverified: that gateway has no Wi-Fi.

Closes #25
This commit is contained in:
Christian Manivong committed 2026-11-12 19:03:40 +01:00
1 parent e05101f282
commit a47f9c3970
13 files changed
+675 -180

No files matched your search

+23 -66
View File
@@ -333,61 +333,20 @@ class TestZyxelVMGDriver:
with pytest.raises(ConnectionClosedException):
self.driver._dal_query("PINGTEST", {})
def test_parse_port_forwards_dal(self):
self._setup_mocked_http()
data = {
"NATPortMap": [
{
"Description": "Web Server",
"Protocol": "TCP",
"ExternalPort": 80,
"InternalIP": "192.168.1.10",
"InternalPort": 8080,
"Enabled": True,
}
]
}
result = self.driver._parse_port_forwards_dal(data)
assert len(result) == 1
assert result[0]["name"] == "Web Server"
assert result[0]["external_port"] == 80
assert result[0]["internal_ip"] == "192.168.1.10"
def test_parse_hosts_dal(self):
self._setup_mocked_http()
data = {
"LANHosts": [
{
"MACAddress": "aa:bb:cc:dd:ee:ff",
"IPAddress": "192.168.1.100",
"HostName": "laptop",
"InterfaceType": "lan",
"Active": True,
}
]
}
result = self.driver._parse_hosts_dal(data)
assert len(result) == 1
assert result[0]["mac"] == "aa:bb:cc:dd:ee:ff"
assert result[0]["ip"] == "192.168.1.100"
assert result[0]["hostname"] == "laptop"
def test_parse_wireless_clients_dal(self):
self._setup_mocked_http()
data = {
"assoc": [
{
"MACAddress": "11:22:33:44:55:66",
"SSID": "MyWiFi",
"Radio": "wlan0",
"Signal": -45,
"TxRate": 300.0,
"RxRate": 150.0,
"Uptime": 3600,
"IPAddress": "192.168.1.50",
}
]
}
data = [
{
"MACAddress": "11:22:33:44:55:66",
"SSID": "MyWiFi",
"Radio": "wlan0",
"Signal": -45,
"TxRate": 300.0,
"RxRate": 150.0,
"Uptime": 3600,
"IPAddress": "192.168.1.50",
}
]
result = self.driver._parse_wireless_clients_dal(data)
assert len(result) == 1
assert result[0]["mac"] == "11:22:33:44:55:66"
@@ -396,19 +355,17 @@ class TestZyxelVMGDriver:
def test_parse_ssids_dal(self):
self._setup_mocked_http()
data = {
"ssids": [
{
"SSID": "MyWiFi",
"Radio": "wlan0",
"BSSID": "00:1a:2b:3c:4d:5e",
"Encryption": "WPA2",
"Enabled": True,
"Hidden": False,
"Clients": 3,
}
]
}
data = [
{
"SSID": "MyWiFi",
"Radio": "wlan0",
"BSSID": "00:1a:2b:3c:4d:5e",
"Encryption": "WPA2",
"Enabled": True,
"Hidden": False,
"Clients": 3,
}
]
result = self.driver._parse_ssids_dal(data)
assert "MyWiFi" in result
assert result["MyWiFi"]["encryption"] == "WPA2"