Skip to content

Commit 91ab536

Browse files
committed
Properly escape certificates/keys when sending them to NetworkManager
1 parent 769e3fb commit 91ab536

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

NetworkManager.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ def to_dbus(klass, method, arg, val, signature):
471471
settings[key]['cloned-mac-address'] = fixups.mac_to_dbus(settings[key]['cloned-mac-address'])
472472
if 'bssid' in settings[key]:
473473
settings[key]['bssid'] = fixups.mac_to_dbus(settings[key]['bssid'])
474+
for cert in ['ca-cert', 'client-cert', 'phase2-ca-cert', 'phase2-client-cert', 'private-key']:
475+
if cert in settings[key]:
476+
settings[key][cert] = fixups.cert_to_dbus(settings[key][cert])
474477
if 'ssid' in settings.get('802-11-wireless', {}):
475478
settings['802-11-wireless']['ssid'] = fixups.ssid_to_dbus(settings['802-11-wireless']['ssid'])
476479
if 'ipv4' in settings:
@@ -687,6 +690,14 @@ def route_to_dbus(route,family):
687690
metric
688691
]
689692

693+
@staticmethod
694+
def cert_to_dbus(cert):
695+
if not isinstance(cert, bytes):
696+
if not cert.startswith('file://'):
697+
cert = 'file://' + cert
698+
cert = cert.encode('utf-8') + b'\0'
699+
return [dbus.Byte(x) for x in cert]
700+
690701
# Turn NetworkManager and Settings into singleton objects
691702
NetworkManager = NetworkManager()
692703
Settings = Settings()

0 commit comments

Comments
 (0)