def store_provider(meta): """Store the eduVPN configuration""" logger.info("storing profile with name {} using NetworkManager".format(meta.display_name)) meta.uuid = make_unique_id() ovpn_text = format_like_ovpn(meta.config, meta.cert, meta.key) config_dict = parse_ovpn(ovpn_text) cert_path = write_cert(meta.cert, 'cert', meta.uuid) key_path = write_cert(meta.key, 'key', meta.uuid) ca_path = write_cert(config_dict.pop('ca'), 'ca', meta.uuid) ta_path = write_cert(config_dict.pop('tls-auth'), 'ta', meta.uuid) nm_config = ovpn_to_nm(config_dict, uuid=meta.uuid, display_name=meta.display_name, username=meta.username) nm_config['vpn']['data'].update({'cert': cert_path, 'key': key_path, 'ca': ca_path, 'ta': ta_path}) insert_config(nm_config) meta.write() return meta.uuid
def update_config_provider(meta, config_dict): """ Update an existing network manager configuration args: uuid (str): the unique ID of the network manager configuration display_name (str): The new display name of the configuration config (str): The new OpenVPN configuration """ logger.info("updating config for {} ({})".format(meta.display_name, meta.uuid)) nm_config = ovpn_to_nm(config_dict, meta=meta, display_name=meta.display_name, username=meta.username) if have_dbus(): connection = NetworkManager.Settings.GetConnectionByUuid(meta.uuid) old_settings = connection.GetSettings() nm_config['vpn']['data'].update({'cert': old_settings['vpn']['data']['cert'], 'key': old_settings['vpn']['data']['key']}) connection.Update(nm_config)
def store_provider(meta, config_dict): """Store the eduVPN configuration""" logger.info("storing profile with name {} using NetworkManager".format(meta.display_name)) new = False if not meta.uuid: meta.uuid = make_unique_id() new = True cert_path = write_cert(meta.cert, 'cert', meta.uuid) key_path = write_cert(meta.key, 'key', meta.uuid) nm_config = ovpn_to_nm(config_dict, meta=meta, display_name=meta.display_name, username=meta.username) nm_config['vpn']['data'].update({'cert': cert_path, 'key': key_path}) if new: insert_config(nm_config) else: update_config_provider(meta, config_dict) meta.write() return meta.uuid
def update_config_provider(meta): """ Update an existing network manager configuration args: uuid (str): the unique ID of the network manager configuration display_name (str): The new display name of the configuration config (str): The new OpenVPN configuration """ logger.info("updating config for {} ({})".format(meta.display_name, meta.uuid)) config_dict = parse_ovpn(meta.config) ca_path = write_cert(config_dict.pop('ca'), 'ca', meta.uuid) ta_path = write_cert(config_dict.pop('tls-auth'), 'ta', meta.uuid) if have_dbus(): nm_config = ovpn_to_nm(config_dict, uuid=meta.uuid, display_name=meta.display_name, username=meta.username) old_conn = NetworkManager.Settings.GetConnectionByUuid(meta.uuid) old_settings = old_conn.GetSettings() nm_config['vpn']['data'].update({'cert': old_settings['vpn']['data']['cert'], 'key': old_settings['vpn']['data']['key'], 'ca': ca_path, 'ta': ta_path}) old_conn.Delete() insert_config(nm_config)
def test_ovpn_to_nm_tls_crypt(self): config = parse_ovpn(mock_config) config['tls-crypt'] = "bla" _ = ovpn_to_nm(config=config, meta=self.meta, display_name='test name')
def test_ovpn_to_nm_2fa(self): config = parse_ovpn(mock_config) config['auth-user-pass'] = True username = '******' nm_dict = ovpn_to_nm(config=config, meta=self.meta, display_name='test name', username=username) self.assertEqual(username, nm_dict['vpn']['data']['username'], username)
def test_ovpn_to_nm(self): config = parse_ovpn(mock_config) _ = ovpn_to_nm(config=config, meta=self.meta, display_name='test name')