Skip to content

Commit a36757a

Browse files
committed
[fix] Convert parameter tls_cipher to a list #349
Fixes #349 Signed-off-by: Oliver Kraitschy <[email protected]>
1 parent 21c5797 commit a36757a

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

netjsonconfig/backends/openwrt/converters/openvpn.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def __intermediate_vpn(self, vpn):
1515
"enabled": not vpn.pop("disabled", False),
1616
}
1717
)
18+
if (ciphers := vpn.get("tls_cipher")) and isinstance(ciphers, str):
19+
vpn["tls_cipher"] = []
20+
# only add non empty strings
21+
for part in ciphers.split(":"):
22+
if part:
23+
vpn["tls_cipher"].append(part)
1824
return super().__intermediate_vpn(vpn, remove=[""])
1925

2026
def __netjson_vpn(self, vpn):
@@ -24,4 +30,6 @@ def __netjson_vpn(self, vpn):
2430
vpn["disabled"] = vpn.pop("enabled", "0") == "0"
2531
vpn["name"] = vpn.pop(".name")
2632
del vpn[".type"]
33+
if (ciphers := vpn.get("tls_cipher")) and isinstance(ciphers, list) and ciphers:
34+
vpn["tls_cipher"] = ":".join(ciphers)
2735
return super().__netjson_vpn(vpn)

tests/openvpn/test_backend.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ def test_client_mode(self):
257257
"status_version": 1,
258258
"tls_client": True,
259259
"tls_auth": "tls_auth.key 1",
260+
"tls_cipher": (
261+
"TLS-DHE-RSA-WITH-AES-256-CBC-SHA:"
262+
"TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:"
263+
"@SECLEVEL=0"
264+
),
260265
"topology": "p2p",
261266
"tun_ipv6": True,
262267
"up": "/home/user/up-command.sh",
@@ -302,6 +307,7 @@ def test_client_mode(self):
302307
status /var/log/openvpn.status 30
303308
status-version 1
304309
tls-auth tls_auth.key 1
310+
tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0
305311
tls-client
306312
topology p2p
307313
tun-ipv6

tests/openvpn/test_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def test_parse_server(self):
7474
script-security 0
7575
status /var/log/openvpn.status 10
7676
status-version 1
77+
tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0
7778
tls-server
7879
user nobody
7980
verb 3
@@ -110,6 +111,11 @@ def test_parse_server(self):
110111
"script_security": 0,
111112
"status": "/var/log/openvpn.status 10",
112113
"status_version": 1,
114+
"tls_cipher": (
115+
"TLS-DHE-RSA-WITH-AES-256-CBC-SHA:"
116+
"TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:"
117+
"@SECLEVEL=0"
118+
),
113119
"tls_server": True,
114120
"user": "nobody",
115121
"verb": 3,

tests/openwrt/test_openvpn.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ def test_parse_server_mode_data_ciphers(self):
211211
"script_security": 1,
212212
"status": "/var/log/openvpn.status 30",
213213
"status_version": 1,
214+
"tls_cipher": (
215+
"TLS-DHE-RSA-WITH-AES-256-CBC-SHA:"
216+
"TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:"
217+
"@SECLEVEL=0"
218+
),
214219
"tls_client": True,
215220
"tun_ipv6": True,
216221
"up": "/home/user/up-command.sh",
@@ -254,6 +259,9 @@ def test_parse_server_mode_data_ciphers(self):
254259
option script_security '1'
255260
option status '/var/log/openvpn.status 30'
256261
option status_version '1'
262+
list tls_cipher 'TLS-DHE-RSA-WITH-AES-256-CBC-SHA'
263+
list tls_cipher 'TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA'
264+
list tls_cipher '@SECLEVEL=0'
257265
option tls_client '1'
258266
option tun_ipv6 '1'
259267
option up '/home/user/up-command.sh'

0 commit comments

Comments
 (0)