예제 #1
0
        public static void Check(out bool isValid, out bool expired, out int siteQty)
        {
            siteQty = 0;
            isValid = false;
            expired = true;
            XmlDocument xmlDocument = HiCache.Get("FileCache_CommercialLicenser") as XmlDocument;

            if (xmlDocument == null)
            {
                string text = HttpContext.Current.Request.MapPath("/config/Certificates.cer");
                if (!File.Exists(text))
                {
                    return;
                }
                xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(File.ReadAllText(text));
                HiCache.Max("FileCache_CommercialLicenser", xmlDocument, new CacheDependency(text));
            }
            XmlNode xmlNode  = xmlDocument.DocumentElement.SelectSingleNode("//Host");
            XmlNode xmlNode2 = xmlDocument.DocumentElement.SelectSingleNode("//LicenseDate");
            XmlNode xmlNode3 = xmlDocument.DocumentElement.SelectSingleNode("//Expires");
            XmlNode xmlNode4 = xmlDocument.DocumentElement.SelectSingleNode("//SiteQty");
            XmlNode xmlNode5 = xmlDocument.DocumentElement.SelectSingleNode("//Signature");

            if (string.Compare(xmlNode.InnerText, HttpContext.Current.Request.Url.Host, true, CultureInfo.InvariantCulture) == 0)
            {
                string s = string.Format(CultureInfo.InvariantCulture, "Host={0}&Expires={1}&SiteQty={2}&LicenseDate={3}", new object[]
                {
                    HttpContext.Current.Request.Url.Host,
                    xmlNode3.InnerText,
                    xmlNode4.InnerText,
                    xmlNode2.InnerText
                });
                using (RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider())
                {
                    rSACryptoServiceProvider.FromXmlString(LicenseHelper.GetPublicKey());
                    RSAPKCS1SignatureDeformatter rSAPKCS1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rSACryptoServiceProvider);
                    rSAPKCS1SignatureDeformatter.SetHashAlgorithm("SHA1");
                    byte[]      rgbSignature = Convert.FromBase64String(xmlNode5.InnerText);
                    SHA1Managed sHA1Managed  = new SHA1Managed();
                    byte[]      rgbHash      = sHA1Managed.ComputeHash(Encoding.UTF8.GetBytes(s));
                    isValid = rSAPKCS1SignatureDeformatter.VerifySignature(rgbHash, rgbSignature);
                }
                expired = (DateTime.Now > DateTime.Parse(xmlNode3.InnerText));
                if (isValid && !expired)
                {
                    int.TryParse(xmlNode4.InnerText, out siteQty);
                }
            }
        }
예제 #2
0
        public static bool CheckCopyright(string wid)
        {
            XmlDocument document = HiCache.Get("Hishop_SiteLicense") as XmlDocument;
            HttpContext current  = HttpContext.Current;

            if (document == null)
            {
                string path = null;
                if (current != null)
                {
                    path = current.Request.MapPath("~/config/Hishop.lic");
                }
                else
                {
                    path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hishop.lic");
                }
                if (!File.Exists(path))
                {
                    return(false);
                }
                document = new XmlDocument();
                document.LoadXml(File.ReadAllText(path));
                HiCache.Max("Hishop_SiteLicense", document, new CacheDependency(path));
            }
            XmlNode      node           = document.DocumentElement.SelectSingleNode("//Host");
            XmlNode      node2          = document.DocumentElement.SelectSingleNode("//LicenseDate");
            XmlNode      node3          = document.DocumentElement.SelectSingleNode("//ExpiresDate");
            XmlNode      node4          = document.DocumentElement.SelectSingleNode("//Signature");
            SiteSettings masterSettings = SettingsManager.GetMasterSettings(false, wid);

            if (string.Compare(node.InnerText, masterSettings.SiteUrl, true, CultureInfo.InvariantCulture) != 0)
            {
                return(false);
            }
            string s    = string.Format(CultureInfo.InvariantCulture, "Host={0}&LicenseDate={1}&ExpiresDate={2}&Key={3}", new object[] { masterSettings.SiteUrl, node2.InnerText, node3.InnerText, masterSettings.CheckCode });
            bool   flag = false;

            using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
            {
                provider.FromXmlString(LicenseHelper.GetPublicKey());
                RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(provider);
                deformatter.SetHashAlgorithm("SHA1");
                byte[] rgbSignature = Convert.FromBase64String(node4.InnerText);
                byte[] rgbHash      = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(s));
                flag = deformatter.VerifySignature(rgbHash, rgbSignature);
            }
            return(flag && (DateTime.Now < DateTime.Parse(node3.InnerText)));
        }