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); }
public static int ActivateFromServer(string productId, string licenseKey, string publicKey, ActivationPayload activationPayload, List <ActivationMeterAttribute> meterAttributes, bool serverSync = false) { var metadata = new List <ActivationMetadata>(); string jsonBody = GetActivationRequest(licenseKey, productId, metadata, meterAttributes); var httpService = new LexHttpService(); HttpResponseMessage httpResponse; try { if (serverSync) { httpResponse = httpService.UpdateActivation(activationPayload.Id, jsonBody); } else { httpResponse = httpService.CreateActivation(jsonBody); } } catch (Exception exception) { System.Console.WriteLine(exception.Message); return(LexStatusCodes.LA_E_INET); } // if (serverSync && LexThread.ActivationValidity.count(activationPayload.id) && LexThread.ActivationValidity[activationPayload.id] == false) // { // # ifdef LEX_DEBUG // LexLogger.LogDebug("Ignore the response as user deactivated the key."); // #endif // return LexStatusCodes.LA_FAIL; // } if (!httpResponse.IsSuccessStatusCode) { return(ActivationErrorHandler(productId, httpResponse)); } var json = httpResponse.Content.ReadAsStringAsync().Result; var activationResponse = JsonConvert.DeserializeObject <ActivationResponse>(json); string jwt = activationResponse.ActivationToken; return(LexValidator.ValidateActivation(jwt, publicKey, licenseKey, productId, activationPayload)); }