public bool VerifyAndAcceptLicense(Product product, ProductCodeName codeName, string publicKey, XmlDocument doc) { if (!VerifyLicense(publicKey, doc)) { return(false); } PragmaLicense lic = FromXmlDocument(doc); MachineID mId = MachineIdProvider.Retrieve(lic.MachineIdType); return((mId.Key.ToLowerInvariant() == lic.MachineKey.Key.ToLowerInvariant()) && (lic.ProductCodeName == codeName) && (lic.Product == product)); }
public XmlDocument SignRequest(PragmaLicense lic) { XmlDocument requestDoc = lic.ToXmlDoc(); // Get the key pair from the key store. CspParameters parms = new CspParameters(1); // PROV_RSA_FULL parms.Flags = CspProviderFlags.UseMachineKeyStore; // Use Machine store parms.KeyContainerName = "PragmaSQL"; parms.KeyNumber = 2; // AT_SIGNATURE RSACryptoServiceProvider csp = new RSACryptoServiceProvider(parms); // Creating the XML signing object. SignedXml sxml = new SignedXml(requestDoc); sxml.SigningKey = csp; // Set the canonicalization method for the document. sxml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigCanonicalizationUrl; // No comments. // Create an empty reference (not enveloped) for the XPath // transformation. Reference r = new Reference(""); // Create the XPath transform and add it to the reference list. r.AddTransform(new XmlDsigEnvelopedSignatureTransform(false)); // Add the reference to the SignedXml object. sxml.AddReference(r); // Compute the signature. sxml.ComputeSignature(); // Get the signature XML and add it to the document element. XmlElement sig = sxml.GetXml(); requestDoc.DocumentElement.AppendChild(sig); return(requestDoc); }
private PragmaLicense GenerateLicenseRequest(string fileName, bool preview) { txtOutPut.Text = String.Empty; PragmaLicense lic = new PragmaLicense(); lic.Product = (Product)_licUtils.ParseEnum(typeof(Product), cmbProduct.Text); lic.ProductCodeName = (ProductCodeName)_licUtils.ParseEnum(typeof(ProductCodeName), cmbProductCodeName.Text); lic.ActivationKey = txtActivationKey.Text; lic.EMail = txtEMail.Text; lic.PurchaseType = (PurchaseType)_licUtils.ParseEnum(typeof(PurchaseType), cmbPurchaseType.Text); lic.LicType = (LicType)_licUtils.ParseEnum(typeof(LicType), cmbLicType.Text); if (lic.PurchaseType == PurchaseType.Demo) { lic.ValidFrom = DateTime.Now; lic.ValidTo = lic.ValidFrom.Value.AddDays(30); } else if (lic.PurchaseType == PurchaseType.Purchase) { lic.ValidFrom = null; lic.ValidTo = null; } lic.MachineKey = new MachineID(txtMachineKey.Text); if (!String.IsNullOrEmpty(fileName)) { lic.ToFile(fileName); statInfo.Text = "Saved license request from: " + fileName; } else { statInfo.Text = "Generated license request."; } if (preview) { txtOutPut.Text = lic.ToXmlString(); } return(lic); }
public XmlDocument SignRequest(string fileName) { PragmaLicense lic = FromXmlFile(fileName); return(SignRequest(lic)); }
public PragmaLicense FromXmlString(string xml) { PragmaLicense result = new PragmaLicense(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlElement docEl = doc.DocumentElement; if (docEl.Name.ToLowerInvariant() != "pragmalicense") { throw new Exception("XML document is not a PragmaLicense"); } DateTimeFormatInfo fi = new DateTimeFormatInfo(); fi.SetAllDateTimePatterns(new string[1] { "dd.MM.yyyy" }, 'd'); foreach (XmlElement e in docEl.ChildNodes) { switch (e.Name.ToLowerInvariant()) { case "product": result.Product = (Product)ParseEnum(typeof(Product), e.InnerText); break; case "productcodename": result.ProductCodeName = (ProductCodeName)ParseEnum(typeof(ProductCodeName), e.InnerText); break; case "activationkey": result.ActivationKey = e.InnerText; break; case "email": result.EMail = e.InnerText; break; case "purchasetype": result.PurchaseType = (PurchaseType)ParseEnum(typeof(PurchaseType), e.InnerText); break; case "lictype": result.LicType = (LicType)ParseEnum(typeof(LicType), e.InnerText); break; case "validfrom": result.ValidFrom = String.IsNullOrEmpty(e.InnerText) ? null : (DateTime?)DateTime.Parse(e.InnerText, fi); break; case "validto": result.ValidTo = String.IsNullOrEmpty(e.InnerText) ? null : (DateTime?)DateTime.Parse(e.InnerText, fi); break; case "machinekey": result.MachineKey = new MachineID(e.InnerText); break; case "machineidtype": if (String.IsNullOrEmpty(e.InnerText)) { result.MachineIdType = MachineIdType.Simple; } else { result.MachineIdType = (MachineIdType)ParseEnum(typeof(MachineIdType), e.InnerText); } break; default: break; } } return(result); }