コード例 #1
0
def _background(meta, oauth, dialog, builder, lets_connect):
    try:
        cert, key = create_keypair(oauth, meta.api_base_uri)
        meta.cert = cert
        meta.key = key
        meta.config = get_profile_config(oauth, meta.api_base_uri,
                                         meta.profile_id)
        ovpn_text = format_like_ovpn(meta.config, meta.cert, meta.key)
        config_dict = parse_ovpn(ovpn_text)
        if meta.two_factor:
            GLib.idle_add(lambda: two_auth_step(builder,
                                                oauth,
                                                meta,
                                                config_dict=config_dict,
                                                lets_connect=lets_connect))
        else:
            GLib.idle_add(lambda: finalizing_step(meta=meta,
                                                  builder=builder,
                                                  config_dict=config_dict,
                                                  lets_connect=lets_connect))
        GLib.idle_add(lambda: dialog.hide())

    except Exception as e:
        error = e
        GLib.idle_add(lambda: error_helper(
            dialog, "can't finalize configuration", "{}: {}".format(
                type(error).__name__, str(error))))
        GLib.idle_add(lambda: dialog.hide())
        raise
コード例 #2
0
def _fetch_updated_config(oauth, meta, builder, info):
    config = get_profile_config(oauth, meta.api_base_uri, meta.profile_id)
    meta.config = config
    config_dict = parse_ovpn(meta.config)
    update_config_provider(meta, config_dict)

    _2fa_check(meta, builder, oauth, config_dict, info)
コード例 #3
0
ファイル: activate.py プロジェクト: efef/python-eduvpn-client
def _fetch_updated_config(oauth, meta, builder, info, lets_connect):
    # type: (str, Metadata, Gtk.builder, dict, bool) -> None
    config = get_profile_config(oauth, meta.api_base_uri, meta.profile_id)
    meta.config = config
    config_dict = parse_ovpn(meta.config)
    update_config_provider(meta, config_dict)

    _2fa_check(meta, builder, oauth, config_dict, info, lets_connect)
コード例 #4
0
def _fetch_updated_config(oauth, meta, builder, info):
    # type : (oauth, Metadata, verifier, Gtk.Builder ) -> None
    config = get_profile_config(oauth, meta.api_base_uri, meta.profile_id)
    meta.config = config
    config_dict = parse_ovpn(meta.config)
    update_config_provider(meta, config_dict)

    _2fa_check(meta, builder, oauth, config_dict, info)
コード例 #5
0
    def test_single_remote(self):
        configtext = """
remote internet.demo.eduvpn.nl 1194 udp
"""
        config = parse_ovpn(configtext)
        settings = ovpn_to_nm(config, meta=self.meta, display_name='test name')
        self.assertEqual(settings['vpn']['data']['remote'],
                         'internet.demo.eduvpn.nl:1194:udp')
コード例 #6
0
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
コード例 #7
0
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)
コード例 #8
0
 def test_parse_ovpn(self):
     parse_ovpn(mock_config)
コード例 #9
0
 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')
コード例 #10
0
 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)
コード例 #11
0
 def test_ovpn_to_nm(self):
     config = parse_ovpn(mock_config)
     _ = ovpn_to_nm(config=config, meta=self.meta, display_name='test name')