Ejemplo n.º 1
0
def getTokenNordVPN():
    # Return a token that can be used on API calls
    token, renew, expiry, _ = getTokens()

    # If the expiry time is passed, renew the token
    if expiry.isdigit() and int(expiry) < now():
        if renewNordVPN(renew):
            token, _, _, _ = getTokens()
            return token
        else:
            # Force an authenticate to happen
            token = ""

    # The authentication call is made during connection validation, which will validate everything and fetch
    # the tokens.  If a reboot happens and the tokens disappear, then we need to force an authenticate again
    if token == "":
        addon = xbmcaddon.Addon(getID())
        if authenticateNordVPN(addon.getSetting("vpn_provider_validated"),
                               addon.getSetting("vpn_username_validated"),
                               addon.getSetting("vpn_password_validated")):
            token, _, _, _ = getTokens()
            return token
        else:
            errorTrace("alternativeNord.py",
                       "Couldn't authenticate or renew the user ID")
            resetTokens()
            raise RuntimeError("Couldn't get a user ID token")

    debugTrace("Using existing user ID token")
    return token
Ejemplo n.º 2
0
def renewNordVPN(renew):
    # Renew a user with the API and store the tokens returned
    response = ""
    try:        
        download_url = "https://api.nordvpn.com/v1/users/tokens/renew"
        download_data = "renewToken=" + renew
        if ifHTTPTrace(): infoTrace("alternativeNord.py", "Renewing authentication using " + download_url + ", " + download_data)
        else: debugTrace("Renewing authentication")
        req = Request(download_url, download_data)
        t_before = now()
        response = urlopen(req, timeout=10)
        user_data = json.load(response)
        t_after = now()
        response.close()
        if ifJSONTrace(): infoTrace("alternativeNord.py", "JSON received is \n" + json.dumps(user_data, indent=4))
        if t_after - t_before > TIME_WARN: infoTrace("alternativeNord.py", "Renewing authentication took " + str(t_after - t_before) + " seconds")
        setTokens(user_data["token"], user_data["renew_token"], None)
        return True
    except HTTPError as e:
        errorTrace("alternativeNord.py", "Couldn't renew user token")
        errorTrace("alternativeNord.py", "API call was " + download_url + ", " + download_data[:download_data.index("renewToken")+11] + "********")
        errorTrace("alternativeNord.py", "Response was " + str(e.code) + " " + e.reason)
        errorTrace("alternativeNord.py", e.read())
    except Exception as e:
        errorTrace("alternativeNord.py", "Couldn't renew user token")
        errorTrace("alternativeNord.py", "API call was " + download_url + ", " + download_data[:download_data.index("renewToken")+11] + "********")
        errorTrace("alternativeNord.py", "Response was " + str(type(e)) + " " + str(e))
    resetTokens()
    return False 
Ejemplo n.º 3
0
def authenticateLogin(vpn_provider, userid, password):
    # Authenticate to get token
    resetTokens()
    rc, api_data = sendAPI("?action=login", "Authenticating with VPN", '{"email":"' + userid + '", "password":"******"}', True)
    if not rc: return None
        
    # Return the token to use for this user on future API calls
    return api_data["data"]["token"]
Ejemplo n.º 4
0
def authenticateNordVPN(vpn_provider, userid, password):
    # Authenticate with the API and store the tokens returned

    # If the same credentials have been used before, don't bother authenticating
    _, _, _, creds = getTokens()
    if creds == vpn_provider + userid + password:
        debugTrace("Previous authentication was good")
        return True

    response = ""
    try:
        download_url = "https://api.nordvpn.com/v1/users/tokens"
        download_data = urllib.urlencode({
            'username': userid,
            'password': password
        })
        if ifHTTPTrace():
            infoTrace(
                "alternativeNord.py", "Authenticating with VPN using " +
                download_url + ", " + download_data)
        else:
            debugTrace("Authenticating with VPN for user " + userid)
        req = urllib2.Request(download_url, download_data)
        t_before = now()
        response = urllib2.urlopen(req, timeout=10)
        user_data = json.load(response)
        t_after = now()
        response.close()
        if ifJSONTrace():
            infoTrace("alternativeNord.py",
                      "JSON received is \n" + json.dumps(user_data, indent=4))
        if t_after - t_before > TIME_WARN:
            infoTrace(
                "alternativeNord.py", "Authenticating with VPN for " + userid +
                " took " + str(t_after - t_before) + " seconds")
        setTokens(user_data["token"], user_data["renew_token"], None)
        setTokens(user_data["token"], user_data["renew_token"],
                  vpn_provider + userid + password)
        return True
    except urllib2.HTTPError as e:
        errorTrace("alternativeNord.py",
                   "Couldn't authenticate with " + vpn_provider)
        errorTrace(
            "alternativeNord.py", "API call was " + download_url + ", " +
            download_data[:download_data.index("&password") + 10] + "********")
        errorTrace("alternativeNord.py",
                   "Response was " + str(e.code) + " " + e.reason)
        errorTrace("alternativeNord.py", e.read())
    except Exception as e:
        errorTrace("alternativeNord.py",
                   "Couldn't authenticate with " + vpn_provider)
        errorTrace(
            "alternativeNord.py", "API call was " + download_url + ", " +
            download_data[:download_data.index("&password") + 10] + "********")
        errorTrace("alternativeNord.py",
                   "Response was " + str(type(e)) + " " + str(e))
    resetTokens()
    return False
def authenticateLogin(vpn_provider, userid, password):
    # Authenticate to get token
    resetTokens()
    rc, api_data = sendAPI(
        "?action=login", "Authenticating with VPN",
        '{"email":"' + userid + '", "password":"******"}', True)
    if not rc: return None

    # Return the token to use for this user on future API calls
    return api_data["data"]["token"]
Ejemplo n.º 6
0
def authenticateShellfire(vpn_provider, userid, password):
    # Authenticate with the API and store the tokens returned

    # If the same credentials have been used before, don't bother authenticating
    _,_,_, creds = getTokens()
    if creds == vpn_provider + userid + password: 
        debugTrace("Previous authentication was good")
        return True
    
    # Get the authentication token to use on future calls
    resetTokens()
    rc, api_data = sendAPI("?action=login", "Authenticating with VPN", '{"email":"' + userid + '", "password":"******"}', True)
    if not rc: return False
        
    # Extract the auth token and store it
    auth_token = api_data["data"]["token"]
    if not auth_token == None: 
        setTokens(auth_token, "", vpn_provider + userid + password)
        return True

    return False
def authenticateShellfire(vpn_provider, userid, password):
    # Authenticate with the API and store the tokens returned

    # If the same credentials have been used before, don't bother authenticating
    _, _, _, creds = getTokens()
    if creds == vpn_provider + userid + password:
        debugTrace("Previous authentication was good")
        return True

    # Get the authentication token to use on future calls
    resetTokens()
    rc, api_data = sendAPI(
        "?action=login", "Authenticating with VPN",
        '{"email":"' + userid + '", "password":"******"}', True)
    if not rc: return False

    # Extract the auth token and store it
    auth_token = api_data["data"]["token"]
    if not auth_token == None:
        setTokens(auth_token, "", vpn_provider + userid + password)
        return True

    return False
Ejemplo n.º 8
0
def resetNordVPN(vpn_provider):
    # Clear out logon info to force authentication to happen again
    # Elsewhere the ovpn and location downloads will be deleted
    resetTokens()
    return True