Can't create SSTP VPN connection using Python 3 dbus
Russell-Jones-OxPhys opened this issue · comments
e.g. Try the following to create a VPN entry. Should I use different APIs, or are these not implemented/exposed? Do you have any idea what would need to change in the C source to make them work as they are if it's a matter of them not being implemented? Would org.freedesktop.NetworkManager.Settings (at least .AddConnection()) need to be implemented explicitly?
The properties used are those in /etc/NetworkManager/system-connections/Example\ VPN (if created via the NM GUI), which are also listed at https://github.com/enaess/network-manager-sstp/blob/master/src/nm-sstp-service.c#L88
There's a direct mapping between the config file and the dbus settings for wifi connections. Is this untrue for the SSTP and PPTP plugins?
#!/usr/bin/env python3
import dbus
import os
import uuid
bus = dbus.SystemBus()
ssn = "org.freedesktop.NetworkManager"
sysproxy = bus.get_object(ssn, "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(sysproxy, ssn + ".Settings")
s_vpn = dbus.Dictionary({
'ca-cert' : '/usr/local/share/ca-certificates/my-cert-chain.pem',
'user' : 'username',
'refuse-eap': True,
'refuse-chap': True,
'gateway' : 'vpn.example.com',
'domain' : 'EXAMPLE',
'refuse-pap' : True,
'password-flags' : '0',
'proxy-password-flags' : '0',
'service-type' : 'org.freedesktop.NetworkManager.sstp'
})
# Only service-type is allowed, all others raise org.freedesktop.NetworkManager.Settings.Connection.InvalidProperty: vpn.xyz: unknown property
s_secs = dbus.Dictionary({
'password' : 'password',
})
# nmcli con modify 'Example SSTP' vpn.secrets 'password = xxx'
# works, this doesn't
s_con = dbus.Dictionary({
'id': 'Example SSTP',
'type': 'vpn',
'uuid': str(uuid.uuid4()),
'permissions': ['user:'+os.environ['USER']],
'autoconnect' : False,
})
s_ip4 = dbus.Dictionary({'method' : 'auto'})
s_ip6 = dbus.Dictionary({
'method' : 'ignore',
'ip6-privacy' : False,
'addr-gen-mode' : 1, # 'stable-privacy' ?
})
con = dbus.Dictionary({
'connection': s_con,
'vpn': s_vpn,
'ipv4': s_ip4,
'ipv6': s_ip6,
'vpn-secrets' : s_secs,
})
settings.AddConnection(con)
OK, I figured it out using
import dbus
from pprint import pprint
bus = dbus.SystemBus()
ssn = "org.freedesktop.NetworkManager"
sysproxy = bus.get_object(ssn, "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(sysproxy, ssn + ".Settings")
c = settings.ListConnections()[0]
#pprint(settings.ListConnections())
for conn in settings.ListConnections():
connproxy = bus.get_object(ssn, conn)
conn = dbus.Interface(connproxy, ssn+'.Settings.Connection')
pprint(conn.GetSettings())
print()
The connection object has a different form for VPN connections from WiFi connections. So I had to do
import dbus
import uuid
import os
bus = dbus.SystemBus()
ssn = "org.freedesktop.NetworkManager"
sysproxy = bus.get_object(ssn, "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(sysproxy, ssn + ".Settings")
s_vpn = dbus.Dictionary({
'ca-cert' : '/usr/local/share/ca-certificates/my-cert-chain.pem',
'user' : 'usernmae',
'refuse-eap': 'yes',
'refuse-chap': 'yes',
'gateway' : 'vpn.example.com',
'domain' : 'EXAMPLE',
'refuse-pap' : 'yes',
'password-flags' : '0',
'proxy-password-flags' : '0',
})
s_secs = dbus.Dictionary({
'password' : 'password',
})
s_con = dbus.Dictionary({
'id': 'Example SSTP',
'type': 'vpn',
'uuid': str(uuid.uuid4()),
'permissions': ['user:'+os.environ['USER']],
'autoconnect' : False,
})
s_ip4 = dbus.Dictionary({'method' : 'auto'})
s_ip6 = dbus.Dictionary({
'method' : 'ignore',
'ip6-privacy' : False,
'addr-gen-mode' : 1, # 'stable-privacy' ?
})
con = dbus.Dictionary({
'connection': s_con,
'vpn': dbus.Dictionary({
'data': s_vpn,
'service-type' : ('org.freedesktop.'
'NetworkManager.sstp'),
'secrets' : s_secs,
}),
'ipv4': s_ip4,
'ipv6': s_ip6,
})
settings.AddConnection(con)