Skip to content

Commit d74fa86

Browse files
masapnemesifier
authored andcommitted
[feature] OpenWrt: Added support for WPA3/WPA2 Personal Mixed #194
This patch is tested on these. - OpenWrt: latest (4b587f25614f3f7215360f96807ce760fa4ef3aa) - hardware: TP-Link Archer C6 v2 Related to #194 Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
1 parent cfd8ba7 commit d74fa86

3 files changed

Lines changed: 133 additions & 3 deletions

File tree

netjsonconfig/backends/openwrt/converters/wireless.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __intermediate_encryption(self, wireless):
9595
'wpa2_personal': 'psk2',
9696
'wpa3_personal': 'sae',
9797
'wpa_personal_mixed': 'psk-mixed',
98+
'wpa2_personal_mixed': 'sae-mixed',
9899
'wpa_enterprise': 'wpa',
99100
'wpa2_enterprise': 'wpa2',
100101
'wpa3_enterprise': 'wpa3',
@@ -123,7 +124,11 @@ def __intermediate_encryption(self, wireless):
123124
uci['key'] = encryption['key']
124125
# add ciphers
125126
cipher = encryption.get('cipher')
126-
if protocol == 'wpa3_personal' or protocol == 'wpa3_enterprise':
127+
if (
128+
protocol == 'wpa3_personal'
129+
or protocol == 'wpa3_enterprise'
130+
or protocol == 'wpa2_personal_mixed'
131+
):
127132
cipher = 'ccmp'
128133
if cipher and protocol.startswith('wpa') and cipher != 'auto':
129134
uci['encryption'] += '+{0}'.format(cipher)
@@ -260,6 +265,7 @@ def __netjson_encryption(self, wifi):
260265
'psk2': 'wpa2_personal',
261266
'sae': 'wpa3_personal',
262267
'psk-mixed': 'wpa_personal_mixed',
268+
'sae-mixed': 'wpa2_personal_mixed',
263269
'wpa': 'wpa_enterprise',
264270
'wpa2': 'wpa2_enterprise',
265271
'wpa3': 'wpa3_enterprise',

netjsonconfig/schema.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@
360360
{"$ref": "#/definitions/encryption_none"},
361361
{"$ref": "#/definitions/encryption_wpa3_personal"},
362362
{"$ref": "#/definitions/encryption_wpa3_enterprise_ap"},
363+
{"$ref": "#/definitions/encryption_wpa3_2_personal"},
363364
{"$ref": "#/definitions/encryption_wpa_personal"},
364365
{"$ref": "#/definitions/encryption_wpa_enterprise_ap"},
365366
{"$ref": "#/definitions/encryption_wps"},
@@ -379,6 +380,7 @@
379380
{"$ref": "#/definitions/encryption_none"},
380381
{"$ref": "#/definitions/encryption_wpa3_personal"},
381382
{"$ref": "#/definitions/encryption_wpa3_enterprise_sta"},
383+
{"$ref": "#/definitions/encryption_wpa3_2_personal"},
382384
{"$ref": "#/definitions/encryption_wpa_personal"},
383385
{"$ref": "#/definitions/encryption_wpa_enterprise_sta"},
384386
{"$ref": "#/definitions/encryption_wep"},
@@ -470,6 +472,18 @@
470472
}
471473
},
472474
},
475+
"encryption_mfp_property_optional": {
476+
"required": ["ieee80211w"],
477+
"properties": {
478+
"ieee80211w": {
479+
"type": "string",
480+
"title": "management frame protection",
481+
"enum": ["1", "2"],
482+
"options": {"enum_titles": ["optional", "required"]},
483+
"propertyOrder": 4,
484+
}
485+
},
486+
},
473487
"encryption_wpa3_personal": {
474488
"title": "WPA3 only Personal",
475489
"allOf": [
@@ -487,6 +501,25 @@
487501
},
488502
],
489503
},
504+
"encryption_wpa3_2_personal": {
505+
"title": "WPA3/WPA2 Personal",
506+
"allOf": [
507+
{"$ref": "#/definitions/encryption_base_settings"},
508+
{"$ref": "#/definitions/encryption_cipher_property"},
509+
{"$ref": "#/definitions/encryption_mfp_property_optional"},
510+
{
511+
"properties": {
512+
"protocol": {
513+
"enum": ["wpa2_personal_mixed"],
514+
"options": {
515+
"enum_titles": ["WPA3/WPA2 Personal Mixed Mode"]
516+
},
517+
},
518+
"key": {"minLength": 8},
519+
}
520+
},
521+
],
522+
},
490523
"encryption_wpa_personal": {
491524
"title": "WPA2/WPA Personal",
492525
"allOf": [
@@ -504,7 +537,7 @@
504537
"options": {
505538
"enum_titles": [
506539
"WPA2 Personal",
507-
"WPA Personal Mixed Mode",
540+
"WPA2/WPA Personal Mixed Mode",
508541
"WPA Personal",
509542
]
510543
},
@@ -620,7 +653,7 @@
620653
"options": {
621654
"enum_titles": [
622655
"WPA2 Enterprise",
623-
"WPA Enterprise Mixed Mode",
656+
"WPA2/WPA Enterprise Mixed Mode",
624657
"WPA Enterprise",
625658
]
626659
},

tests/openwrt/test_encryption.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,53 @@ def test_parse_wpa3_personal(self):
5454
o = OpenWrt(native=self._wpa3_personal_uci)
5555
self.assertEqual(o.config, self._wpa3_personal_netjson)
5656

57+
_wpa2_personal_mixed_netjson = {
58+
"interfaces": [
59+
{
60+
"name": "wlan0",
61+
"type": "wireless",
62+
"wireless": {
63+
"radio": "radio0",
64+
"mode": "access_point",
65+
"ssid": "wpa2-3-personal-mixed",
66+
"encryption": {
67+
"protocol": "wpa2_personal_mixed",
68+
"cipher": "ccmp",
69+
"key": "passphrase012345",
70+
"ieee80211w": "1",
71+
},
72+
},
73+
}
74+
]
75+
}
76+
_wpa2_personal_mixed_uci = """package network
77+
78+
config interface 'wlan0'
79+
option ifname 'wlan0'
80+
option proto 'none'
81+
82+
package wireless
83+
84+
config wifi-iface 'wifi_wlan0'
85+
option device 'radio0'
86+
option encryption 'sae-mixed+ccmp'
87+
option ieee80211w '1'
88+
option ifname 'wlan0'
89+
option key 'passphrase012345'
90+
option mode 'ap'
91+
option network 'wlan0'
92+
option ssid 'wpa2-3-personal-mixed'
93+
"""
94+
95+
def test_render_wpa2_personal_mixed(self):
96+
o = OpenWrt(self._wpa2_personal_mixed_netjson)
97+
expected = self._tabs(self._wpa2_personal_mixed_uci)
98+
self.assertEqual(o.render(), expected)
99+
100+
def test_parse_wpa2_personal_mixed(self):
101+
o = OpenWrt(native=self._wpa2_personal_mixed_uci)
102+
self.assertEqual(o.config, self._wpa2_personal_mixed_netjson)
103+
57104
_wpa2_personal_netjson = {
58105
"interfaces": [
59106
{
@@ -921,3 +968,47 @@ def test_render_ieee80211w(self):
921968
OpenWrt(_netjson_wpa3_enterprise_cipher_tkip).render(),
922969
_uci_wpa3_enterprise_cipher_tkip,
923970
)
971+
972+
_netjson_wpa2_personal_mixed_cipher_tkip = {
973+
"interfaces": [
974+
{
975+
"name": "wlan0",
976+
"type": "wireless",
977+
"wireless": {
978+
"radio": "radio0",
979+
"mode": "access_point",
980+
"ssid": "wpa2-3-personal-mixed",
981+
"encryption": {
982+
"protocol": "wpa2_personal_mixed",
983+
"cipher": "tkip",
984+
"key": "passphrase012345",
985+
"ieee80211w": "2",
986+
},
987+
},
988+
}
989+
]
990+
}
991+
_uci_wpa2_personal_mixed_cipher_tkip = self._tabs(
992+
"""package network
993+
994+
config interface 'wlan0'
995+
option ifname 'wlan0'
996+
option proto 'none'
997+
998+
package wireless
999+
1000+
config wifi-iface 'wifi_wlan0'
1001+
option device 'radio0'
1002+
option encryption 'sae-mixed+ccmp'
1003+
option ieee80211w '2'
1004+
option ifname 'wlan0'
1005+
option key 'passphrase012345'
1006+
option mode 'ap'
1007+
option network 'wlan0'
1008+
option ssid 'wpa2-3-personal-mixed'
1009+
"""
1010+
)
1011+
self.assertEqual(
1012+
OpenWrt(_netjson_wpa2_personal_mixed_cipher_tkip).render(),
1013+
_uci_wpa2_personal_mixed_cipher_tkip,
1014+
)

0 commit comments

Comments
 (0)