Esempio n. 1
0
def activate_connection(
        meta, builder, verifier,
        lets_connect):  # type: (Metadata, Gtk.builder, str, bool) -> None
    """do the actual connecting action"""
    logger.info("Connecting to {}".format(meta.display_name))
    disconnect_all()
    _, name = get_brand(lets_connect)
    notification = init_notify(lets_connect)
    notify(notification, "{} connecting...".format(name),
           "Connecting to '{}'".format(meta.display_name))
    try:
        if not meta.token:
            logger.error("metadata for {} doesn't contain oauth2 token".format(
                meta.uuid))
            connect_provider(meta.uuid)

        else:
            oauth = oauth_from_token(meta=meta, lets_connect=lets_connect)
            thread_helper(lambda: _auth_check(
                oauth, meta, verifier, builder, lets_connect=lets_connect))

    except Exception as e:
        switch = builder.get_object('connect-switch')
        GLib.idle_add(switch.set_active, False)
        window = builder.get_object('eduvpn-window')
        error_helper(window, "can't enable connection",
                     "{}: {}".format(type(e).__name__, str(e)))
        raise
Esempio n. 2
0
def _2fa_check(meta, builder, oauth, config_dict, info, lets_connect):
    # type: (Metadata, Gtk.builder, str, dict, dict, bool) -> None
    if meta.two_factor and not info['two_factor_enrolled']:
        # 2fa is required, but the user is not enroled anymore
        two_auth_step(builder, oauth, meta, config_dict, lets_connect)
    else:
        connect_provider(meta.uuid)
def activate_connection(meta, builder):
    """do the actual connecting action"""
    logger.info("Connecting to {}".format(meta.display_name))
    notify("eduVPN connecting...", "Connecting to '{}'".format(meta.display_name))
    try:
        if not meta.token:
            logger.error("metadata for {} doesn't contain oauth2 token".format(meta.uuid))
        else:
            oauth = oauth_from_token(meta=meta)
            config = get_profile_config(oauth, meta.api_base_uri, meta.profile_id)
            meta.config = config
            update_config_provider(meta)

            if datetime.now() > datetime.fromtimestamp(meta.token['expires_at']):
                logger.info("key pair is expired")
                cert, key = create_keypair(oauth, meta.api_base_uri)
                update_keys_provider(meta.uuid, cert, key)

        connect_provider(meta.uuid)

    except Exception as e:
        switch = builder.get_object('connect-switch')
        GLib.idle_add(switch.set_active, False)
        window = builder.get_object('eduvpn-window')
        error_helper(window, "can't enable connection", "{}: {}".format(type(e).__name__, str(e)))
        raise
 def test_connect_provider(self):
     with self.assertRaises(EduvpnException):
         connect_provider(self.meta.uuid)
def _2fa_check(meta, builder, oauth, config_dict, info):
    if meta.two_factor and not info['two_factor_enrolled']:
        # 2fa is required, but the user is not enroled anymore
        two_auth_step(builder, oauth, meta, config_dict)
    else:
        connect_provider(meta.uuid)