Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions netjsonconfig/backends/openwrt/converters/openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def __intermediate_vpn(self, vpn):
"enabled": not vpn.pop("disabled", False),
}
)
if (cipher := vpn.get("tls_cipher")) and isinstance(cipher, str):
vpn["tls_cipher"] = [cipher]
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we will need to split the value in tls_cipher with :, but we will need to ensure that :@SECLEVEL should stay intact.

E.g.:

TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0

should become

  • TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256
  • TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0

return super().__intermediate_vpn(vpn, remove=[""])

def __netjson_vpn(self, vpn):
Expand All @@ -24,4 +26,6 @@ def __netjson_vpn(self, vpn):
vpn["disabled"] = vpn.pop("enabled", "0") == "0"
vpn["name"] = vpn.pop(".name")
del vpn[".type"]
if (cipher := vpn.get("tls_cipher")) and isinstance(cipher, list) and cipher:
vpn["tls_cipher"] = cipher[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is possible to have more than one cipher suite present in tls_cipher, it may be possible that there are more than 1 item in the list.

I think we should combine all the items in the list to one string instead of just using the first one.

return super().__netjson_vpn(vpn)
2 changes: 2 additions & 0 deletions tests/openvpn/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def test_client_mode(self):
"status_version": 1,
"tls_client": True,
"tls_auth": "tls_auth.key 1",
"tls_cipher": "TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0",
"topology": "p2p",
"tun_ipv6": True,
"up": "/home/user/up-command.sh",
Expand Down Expand Up @@ -302,6 +303,7 @@ def test_client_mode(self):
status /var/log/openvpn.status 30
status-version 1
tls-auth tls_auth.key 1
tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0
tls-client
topology p2p
tun-ipv6
Expand Down
2 changes: 2 additions & 0 deletions tests/openvpn/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_parse_server(self):
script-security 0
status /var/log/openvpn.status 10
status-version 1
tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0
tls-server
user nobody
verb 3
Expand Down Expand Up @@ -110,6 +111,7 @@ def test_parse_server(self):
"script_security": 0,
"status": "/var/log/openvpn.status 10",
"status_version": 1,
"tls_cipher": "TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0",
"tls_server": True,
"user": "nobody",
"verb": 3,
Expand Down
2 changes: 2 additions & 0 deletions tests/openwrt/test_openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def test_parse_server_mode_data_ciphers(self):
"script_security": 1,
"status": "/var/log/openvpn.status 30",
"status_version": 1,
"tls_cipher": "TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update this test to have multiple ciphers.

"tls_client": True,
"tun_ipv6": True,
"up": "/home/user/up-command.sh",
Expand Down Expand Up @@ -254,6 +255,7 @@ def test_parse_server_mode_data_ciphers(self):
option script_security '1'
option status '/var/log/openvpn.status 30'
option status_version '1'
list tls_cipher 'TLS-DHE-RSA-WITH-AES-256-CBC-SHA:@SECLEVEL=0'
option tls_client '1'
option tun_ipv6 '1'
option up '/home/user/up-command.sh'
Expand Down