def __getQueueITTokenValidationResult(self, targetUrl, eventId, config,
                                          queueParams, customerId, secretKey):
        calculatedHash = QueueitHelpers.hmacSha256Encode(
            queueParams.queueITTokenWithoutHash, secretKey)

        if (calculatedHash.upper() != queueParams.hashCode.upper()):
            return self.__getVaidationErrorResult(customerId, targetUrl,
                                                  config, queueParams, "hash")

        if (queueParams.eventId.upper() != eventId.upper()):
            return self.__getVaidationErrorResult(
                customerId, targetUrl, config, queueParams, "eventid")

        if (queueParams.timeStamp <
                QueueitHelpers.getCurrentTime()):
            return self.__getVaidationErrorResult(
                customerId, targetUrl, config, queueParams, "timestamp")

        cookieDomain = ""
        if (not Utils.isNilOrEmpty(config.cookieDomain)):
            cookieDomain = config.cookieDomain

        self.userInQueueStateRepository.store(
            config.eventId, queueParams.queueId,
            queueParams.cookieValidityMinutes, cookieDomain,
            queueParams.redirectType, secretKey)
        return RequestValidationResult(ActionTypes.QUEUE, config.eventId,
                                       queueParams.queueId, None,
                                       queueParams.redirectType)
    def verify(customer_id, secret_key, queueit_token):
        diagnostics = ConnectorDiagnostics()
        q_params = QueueUrlParams.extractQueueParams(queueit_token)

        if q_params is None:
            return diagnostics

        if q_params.redirectType is None:
            return diagnostics

        if q_params.redirectType != "debug":
            return diagnostics

        if Utils.isNilOrEmpty(customer_id) or Utils.isNilOrEmpty(secret_key):
            diagnostics.__setStateWithSetupError()
            return diagnostics

        expected_hash = QueueitHelpers.hmacSha256Encode(
            q_params.queueITTokenWithoutHash, secret_key)
        if q_params.hashCode != expected_hash:
            diagnostics.__setStateWithTokenError(customer_id, "hash")
            return diagnostics

        if q_params.timeStamp < QueueitHelpers.getCurrentTime():
            diagnostics.__setStateWithTokenError(customer_id, "timestamp")
            return diagnostics

        diagnostics.isEnabled = True
        return diagnostics
    def __createCookieValue(eventId, queueId, fixedCookieValidityMinutes,
                            redirectType, secretKey):
        issueTime = Utils.toString(QueueitHelpers.getCurrentTime())
        hashValue = UserInQueueStateCookieRepository.__generateHash(
            eventId, queueId, fixedCookieValidityMinutes, redirectType,
            issueTime, secretKey)

        fixedCookieValidityMinutesPart = ""
        if (not Utils.isNilOrEmpty(fixedCookieValidityMinutes)):
            fixedCookieValidityMinutesPart = "&FixedValidityMins=" + fixedCookieValidityMinutes

        cookieValue = "EventId=" + eventId + "&QueueId=" + queueId + fixedCookieValidityMinutesPart + "&RedirectType=" + redirectType + "&IssueTime=" + issueTime + "&Hash=" + hashValue
        return cookieValue
예제 #4
0
    def __validateToken(self, config, queue_params, secret_key):
        calculated_hash = QueueitHelpers.hmacSha256Encode(
            queue_params.queueITTokenWithoutHash, secret_key)

        if calculated_hash.upper() != queue_params.hashCode.upper():
            return TokenValidationResult(False, "hash")

        if queue_params.eventId.upper() != config.eventId.upper():
            return TokenValidationResult(False, "eventid")

        if queue_params.timeStamp < QueueitHelpers.getCurrentTime():
            return TokenValidationResult(False, "timestamp")

        return TokenValidationResult(True, None)
    def __isCookieValid(secretKey, cookieNameValueMap, eventId,
                        cookieValidityMinutes, validateTime):
        try:
            if ("EventId" not in cookieNameValueMap):
                return False

            if ("QueueId" not in cookieNameValueMap):
                return False

            if ("RedirectType" not in cookieNameValueMap):
                return False

            if ("IssueTime" not in cookieNameValueMap):
                return False

            if ("Hash" not in cookieNameValueMap):
                return False

            fixedCookieValidityMinutes = ""
            if ("FixedValidityMins" in cookieNameValueMap):
                fixedCookieValidityMinutes = cookieNameValueMap[
                    "FixedValidityMins"]

            hashValue = UserInQueueStateCookieRepository.__generateHash(
                cookieNameValueMap["EventId"], cookieNameValueMap["QueueId"],
                fixedCookieValidityMinutes, cookieNameValueMap["RedirectType"],
                cookieNameValueMap["IssueTime"], secretKey)

            if (hashValue != cookieNameValueMap["Hash"]):
                return False

            if (eventId.upper() != cookieNameValueMap["EventId"].upper()):
                return False

            if (validateTime):
                validity = cookieValidityMinutes
                if (not Utils.isNilOrEmpty(fixedCookieValidityMinutes)):
                    validity = int(fixedCookieValidityMinutes)

                expirationTime = int(
                    cookieNameValueMap["IssueTime"]) + (validity * 60)
                if (expirationTime < QueueitHelpers.getCurrentTime()):
                    return False

            return True
        except:
            return False
예제 #6
0
    def __isCookieValid(secret_key, cookie_name_value_map, event_id,
                        cookie_validity_minutes, validate_time):
        try:
            if "EventId" not in cookie_name_value_map:
                return False

            if "QueueId" not in cookie_name_value_map:
                return False

            if "RedirectType" not in cookie_name_value_map:
                return False

            if "IssueTime" not in cookie_name_value_map:
                return False

            if "Hash" not in cookie_name_value_map:
                return False

            fixed_cookie_validity_minutes = ""
            if "FixedValidityMins" in cookie_name_value_map:
                fixed_cookie_validity_minutes = cookie_name_value_map["FixedValidityMins"]

            hash_value = UserInQueueStateCookieRepository.__generateHash(
                cookie_name_value_map["EventId"], cookie_name_value_map["QueueId"],
                fixed_cookie_validity_minutes, cookie_name_value_map["RedirectType"],
                cookie_name_value_map["IssueTime"], secret_key)

            if hash_value != cookie_name_value_map["Hash"]:
                return False

            if event_id.upper() != cookie_name_value_map["EventId"].upper():
                return False

            if validate_time:
                validity = cookie_validity_minutes
                if not Utils.isNilOrEmpty(fixed_cookie_validity_minutes):
                    validity = int(fixed_cookie_validity_minutes)

                expiration_time = int(cookie_name_value_map["IssueTime"]) + (validity * 60)
                if expiration_time < QueueitHelpers.getCurrentTime():
                    return False

            return True
        except:
            return False
예제 #7
0
    def __getErrorResult(self, customer_id, target_url, config, q_params,
                         error_code):
        time_stamp = str(QueueitHelpers.getCurrentTime())
        target_url_param = ""
        if not Utils.isNilOrEmpty(target_url):
            target_url_param = "&t={}".format(
                QueueitHelpers.urlEncode(target_url))

        query_string = self.__getQueryString(customer_id, config.eventId,
                                             config.version, config.actionName,
                                             config.culture, config.layoutName)
        query = "{}&queueittoken={}&ts={}{}".format(query_string,
                                                    q_params.queueITToken,
                                                    time_stamp,
                                                    target_url_param)
        redirect_url = self.__generateRedirectUrl(
            config.queueDomain, "error/{}/".format(error_code), query)

        return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None,
                                       redirect_url, None, config.actionName)
    def __getVaidationErrorResult(self, customerId, targetUrl, config, qParams,
                                  errorCode):
        targetUrlParam = ""
        if (not Utils.isNilOrEmpty(targetUrl)):
            targetUrlParam = "&t=" + QueueitHelpers.urlEncode(
                targetUrl)

        query = self.__getQueryString(
            customerId, config.eventId, config.version, config.culture,
            config.layoutName
        ) + "&queueittoken=" + qParams.queueITToken + "&ts=" + str(
            QueueitHelpers.getCurrentTime()) + targetUrlParam

        domainAlias = config.queueDomain
        if (not domainAlias.endswith("/")):
            domainAlias = domainAlias + "/"

        redirectUrl = "https://" + domainAlias + "error/" + errorCode + "/?" + query
        return RequestValidationResult(ActionTypes.QUEUE, config.eventId, None,
                                       redirectUrl, None)