Ejemplo n.º 1
0
        public static bool ValidateSystemTime(string productId)
        {
            var now = GetUtcTimestamp();
            var lastRecordedTimeStr = LexDataStore.GetValue(productId, LexConstants.KEY_LAST_RECORDED_TIME);

            if (ValidateTime((long)Int32.Parse(lastRecordedTimeStr), LexConstants.ALLOWED_CLOCK_OFFSET))
            {
                LexDataStore.SaveValue(productId, LexConstants.KEY_LAST_RECORDED_TIME, now.ToString());
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static int ValidateActivation(string jwt, string publicKey, string licenseKey, string productId, ActivationPayload activationPayload)
        {
            string payload = LexJwtService.VerifyToken(jwt, publicKey);

            if (String.IsNullOrEmpty(payload))
            {
                return(LexStatusCodes.LA_FAIL);
            }
            var tempActivationPayload = JsonConvert.DeserializeObject <ActivationPayload>(payload);

            activationPayload.CopyProperties(tempActivationPayload);
            activationPayload.IsValid = true;
            int status;

            if (licenseKey != activationPayload.Key)
            {
                status = LexStatusCodes.LA_FAIL;
            }
            else if (productId != activationPayload.ProductId)
            {
                status = LexStatusCodes.LA_FAIL;
            }
            else if (activationPayload.Fingerprint != LexSystemInfo.GetFingerPrint())
            {
                status = LexStatusCodes.LA_E_MACHINE_FINGERPRINT;
            }
            else if (!ValidateTime(activationPayload.IssuedAt, activationPayload.AllowedClockOffset))
            {
                status = LexStatusCodes.LA_E_TIME;
            }
            else
            {
                status = LexValidator.ValidateActivationStatus(productId, activationPayload);
            }
            if (status == LexStatusCodes.LA_OK || status == LexStatusCodes.LA_EXPIRED || status == LexStatusCodes.LA_SUSPENDED || status == LexStatusCodes.LA_GRACE_PERIOD_OVER)
            {
                var now = GetUtcTimestamp();
                LexDataStore.SaveValue(productId, LexConstants.KEY_LAST_RECORDED_TIME, now.ToString());
                LexDataStore.SaveValue(productId, LexConstants.KEY_ACTIVATION_JWT, jwt);
            }
            else
            {
                LexDataStore.SaveValue(productId, LexConstants.KEY_LAST_RECORDED_TIME, activationPayload.IssuedAt.ToString());
            }
            return(status);
        }