public static Task <WebProductLicense> ActivateLicense(ProductLicenseInfo productLicenseInfo) { var apiClient = DependencyResolver.Current.GetService <IAPIHttpClient>(); dynamic param = new ExpandoObject(); param.productLicenseInfo = productLicenseInfo; return(apiClient.ServiceAsync <WebProductLicense>(KL2_Server.API, "LicenseService", "ActivateLicense", param)); }
public void SaveLicense(string productName, ProductLicenseInfo licenseInfo) { using (StreamWriter writer = new StreamWriter(productName, false)) { XmlSerializer serializer = new XmlSerializer(typeof(ProductLicenseInfo)); serializer.Serialize(writer, licenseInfo); } }
public ProductLicenseInfo ActivateProduct(string productKey, string machineHash) { try { ProductKeyPublisher keyPublisher = new ProductKeyPublisher(_cryptoService); ProductKeyInfo productInfo = keyPublisher.ValidateProductKey(productKey); byte[] proid = BitConverter.GetBytes(productInfo.ProductID); byte[] pinfo = BitConverter.GetBytes(productInfo.ProductFeatures); byte[] xinfo = BitConverter.GetBytes(productInfo.TrialDays); byte[] ticks = BitConverter.GetBytes(productInfo.GeneratedDate.Ticks); byte[] clientID = Encoding.Unicode.GetBytes(productInfo.ClientID); byte[] usernameHash = Encoding.ASCII.GetBytes(productInfo.UsernameHash); byte[] companyHash = Encoding.ASCII.GetBytes(productInfo.CompanyHash); byte[] userEmailHash = Encoding.ASCII.GetBytes(productInfo.UserEmailHash); byte[] activ = BitConverter.GetBytes(DateTimeOffset.Now.Ticks); byte[] mhash = Convert.FromBase64String(machineHash); byte[] infoBytes; using (MemoryStream memStream = new MemoryStream()) { memStream.Write(proid, 0, 2); memStream.Write(pinfo, 0, 2); memStream.Write(xinfo, 0, 2); memStream.Write(ticks, 0, 8); memStream.Write(clientID, 0, 12); memStream.Write(usernameHash, 0, 20); memStream.Write(companyHash, 0, 20); memStream.Write(userEmailHash, 0, 20); memStream.Write(activ, 0, 8); memStream.Write(mhash, 0, mhash.Length); infoBytes = memStream.ToArray(); } byte[] signBytes = _cryptoService.SignData(infoBytes, new SHA1CryptoServiceProvider()); ProductLicenseInfo licenseInfo = new ProductLicenseInfo() { ActivationInfo = Convert.ToBase64String(infoBytes), Signature = Convert.ToBase64String(signBytes) }; return(licenseInfo); } catch (Exception ex) { return(new ProductLicenseInfo() { ActivationInfo = ex.Message, Signature = null }); } }
public IHttpActionResult ActivateLicense([DynamicBody] dynamic param) { try { ProductLicenseInfo productLicenseInfo = (ProductLicenseInfo)param.productLicenseInfo; XmlDocument doc = new XmlDocument(); doc.Load("Files/PublicKey.xml"); ProductLicenseManager.Initialize(_traceManager, doc.OuterXml); var license = ProductLicenseManager.Current.ActivateWebProduct(productLicenseInfo); return(Ok(license)); } catch (Exception ex) { _traceManager.TraceError(ex, ex.Message); return(InternalServerError(ex)); } }
public async Task <ActionResult> SaveDefault() { if (Request.Cookies.AllKeys.Contains("token")) { _apiHttpClient.Token = Request.Cookies["token"].Value; } HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; var uploadedLicenseFile = System.Web.HttpContext.Current.Request.Files["uploadLicense"]; var name = System.Web.HttpContext.Current.Request.Headers["name"]; var company = System.Web.HttpContext.Current.Request.Headers["company"]; var email = System.Web.HttpContext.Current.Request.Headers["email"]; await LicenseMapper.SetUserInformation(name, company, email); ProductLicenseInfo licenseInfo = null; try { using (System.IO.StreamReader reader = new System.IO.StreamReader(uploadedLicenseFile.InputStream)) { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ProductLicenseInfo)); licenseInfo = (ProductLicenseInfo)serializer.Deserialize(reader); } } catch (Exception e) { _traceManager.TraceError(e, e.Message); HttpContext.Response.StatusDescription = $"{HttpStatusCode.BadRequest}"; return(Content(LocalizedStrings.GetString("Web_Controller_License_CantCheckLicense"))); } try { WebProductLicense license = await LicenseMapper.ActivateLicense(licenseInfo); if (license.Status == WebLicenseStatus.OverageOfUsers) { HttpContext.Response.StatusDescription = $"{HttpStatusCode.ExpectationFailed}"; return(Content(LocalizedStrings.GetStringFormat(license.StatusReason, license.StatusReasonParams?.Select(_ => _.ToString()).ToArray()))); } // Comment this part if you want to be able to save a expired license if (license.Status != WebLicenseStatus.Licensed && license.Status != WebLicenseStatus.TrialVersion) { HttpContext.Response.StatusDescription = $"{HttpStatusCode.Forbidden}"; return(Content(LocalizedStrings.GetStringFormat(license.StatusReason, license.StatusReasonParams?.Select(_ => _.ToString()).ToArray()))); } //First initialize of license, set UserPool to current Admin if (license.UsersPool.Count == 0) { //Get current user id - Admin var adminId = int.Parse(System.Web.HttpContext.Current.User.Identity.GetUserId()); license.UsersPool.Add(adminId); } await LicenseMapper.SetLicense(license); // TODO : Update license infos from the secured storage } catch (Exception e) { _traceManager.TraceError(e, e.Message); HttpContext.Response.StatusDescription = $"{HttpStatusCode.BadRequest}"; return(Content(LocalizedStrings.GetString("Web_Controller_License_LicenseInvalid"))); } HttpContext.Response.StatusDescription = $"{HttpStatusCode.OK}"; return(Content($"{HttpStatusCode.OK}")); }
public void SaveLicense(string productName, ProductLicenseInfo licenseInfo) { _license = licenseInfo; }