Example #1
0
        public static void Check(out bool isValid, out bool expired, out int siteQty)
        {
            siteQty = 0;
            isValid = false;
            expired = true;
            HttpContext current     = HttpContext.Current;
            XmlDocument xmlDocument = EcCache.Get("FileCache_CommercialLicenser") as XmlDocument;

            if (xmlDocument == null)
            {
                string text = (current != null) ? current.Request.MapPath("~/config/Certificates.cer") : System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "config\\Certificates.cer");
                if (!System.IO.File.Exists(text))
                {
                    return;
                }
                xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(System.IO.File.ReadAllText(text));
                EcCache.Max("FileCache_CommercialLicenser", xmlDocument, new CacheDependency(text));
            }
            XmlNode hostNode        = xmlDocument.DocumentElement.SelectSingleNode("//Host");
            XmlNode licenseDateNode = xmlDocument.DocumentElement.SelectSingleNode("//LicenseDate");
            XmlNode expiresNode     = xmlDocument.DocumentElement.SelectSingleNode("//Expires");
            XmlNode siteQtyNode     = xmlDocument.DocumentElement.SelectSingleNode("//SiteQty");
            XmlNode signNode        = xmlDocument.DocumentElement.SelectSingleNode("//Signature");

            if (string.Compare(hostNode.InnerText, HttpContext.Current.Request.Url.Host, true, System.Globalization.CultureInfo.InvariantCulture) == 0)
            {
                string s = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Host={0}&Expires={1}&SiteQty={2}&LicenseDate={3}", new object[]
                {
                    HttpContext.Current.Request.Url.Host,
                    expiresNode.InnerText,
                    siteQtyNode.InnerText,
                    licenseDateNode.InnerText
                });
                using (RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider())
                {
                    rSACryptoServiceProvider.FromXmlString(LicenseHelper.GetPublicKey());
                    RSAPKCS1SignatureDeformatter rSAPKCS1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rSACryptoServiceProvider);
                    rSAPKCS1SignatureDeformatter.SetHashAlgorithm("SHA1");
                    byte[]      rgbSignature = System.Convert.FromBase64String(signNode.InnerText);
                    SHA1Managed sHA1Managed  = new SHA1Managed();
                    byte[]      rgbHash      = sHA1Managed.ComputeHash(System.Text.Encoding.UTF8.GetBytes(s));
                    isValid = rSAPKCS1SignatureDeformatter.VerifySignature(rgbHash, rgbSignature);
                }
                expired = (System.DateTime.Now > System.DateTime.Parse(expiresNode.InnerText));
                if (isValid && !expired)
                {
                    int.TryParse(siteQtyNode.InnerText, out siteQty);
                }
            }
        }
Example #2
0
        public static string GetPublicKey()
        {
            string text = EcCache.Get(CachePublicKey) as string;

            if (string.IsNullOrEmpty(text))
            {
                HttpContext current = HttpContext.Current;
                string      text2;
                if (current != null)
                {
                    text2 = current.Request.MapPath("~/config/publickey.xml");
                }
                else
                {
                    text2 = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "/config/publickey.xml");
                }
                text = System.IO.File.ReadAllText(text2);
                EcCache.Max(CachePublicKey, text, new CacheDependency(text2));
            }
            return(text);
        }
Example #3
0
 public static void Insert(string key, object obj, int seconds, CacheItemPriority priority)
 {
     EcCache.Insert(key, obj, null, seconds, priority);
 }
Example #4
0
 public static void Insert(string key, object obj, CacheDependency dep, int seconds)
 {
     EcCache.Insert(key, obj, dep, seconds, CacheItemPriority.Normal);
 }
Example #5
0
 public static void Insert(string key, object obj, int seconds)
 {
     EcCache.Insert(key, obj, null, seconds);
 }
Example #6
0
 public static void Insert(string key, object obj, CacheDependency dep)
 {
     EcCache.Insert(key, obj, dep, 8640);
 }
Example #7
0
 public static void Insert(string key, object obj)
 {
     EcCache.Insert(key, obj, null, 1);
 }
Example #8
0
 public static void Max(string key, object obj)
 {
     EcCache.Max(key, obj, null);
 }
Example #9
0
        public static bool CheckCopyright()
        {
            HttpContext current     = HttpContext.Current;
            XmlDocument xmlDocument = EcCache.Get(CacheCopyrightKey) as XmlDocument;

            bool result;

            if (xmlDocument == null)
            {
                string licenseFile;

                if (current != null)
                {
                    licenseFile = current.Request.MapPath("~/config/ecshop.lics");
                }
                else
                {
                    licenseFile = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ecshop.lics");
                }

                if (!File.Exists(licenseFile))
                {
                    result = false;
                    return(result);
                }

                string license = "";

                try
                {
                    string text = File.ReadAllText(licenseFile);

                    license = EcCryptographer.Decrypt(text);
                }
                catch
                {
                    return(false);
                }

                if (string.IsNullOrWhiteSpace(license))
                {
                    return(false);
                }

                xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(license);

                EcCache.Max(CacheCopyrightKey, xmlDocument, new CacheDependency(license));
            }

            XmlNode hostNode        = xmlDocument.DocumentElement.SelectSingleNode("//Host");
            XmlNode licenseDateNode = xmlDocument.DocumentElement.SelectSingleNode("//LicenseDate");
            XmlNode expireDateNode  = xmlDocument.DocumentElement.SelectSingleNode("//ExpiresDate");
            XmlNode signNode        = xmlDocument.DocumentElement.SelectSingleNode("//Signature");
            XmlNode openPCNode      = xmlDocument.DocumentElement.SelectSingleNode("//OpenPC");
            XmlNode openWeixinNode  = xmlDocument.DocumentElement.SelectSingleNode("//OpenWeixin");
            XmlNode openAppNode     = xmlDocument.DocumentElement.SelectSingleNode("//OpenApp");
            XmlNode openWapNode     = xmlDocument.DocumentElement.SelectSingleNode("//OpenWap");
            XmlNode openAliohNode   = xmlDocument.DocumentElement.SelectSingleNode("//OpenAliOH");

            string host = current.Request.Url.Host;

            if (host.EndsWith(hostNode.InnerText))
            //if (string.Compare(hostNode.InnerText, host, true, System.Globalization.CultureInfo.InvariantCulture) != 0)
            {
                result = false;
            }
            else
            {
                string data = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                            "Host={0}&LicenseDate={1:yyyy-MM-dd}&ExpiresDate={2:yyyy-MM-dd}&Key={3}&OpenPC={4}&OpenWeixin={5}&OpenApp={6}&OpenWap={7}&OpenAliOH={8}",
                                            hostNode.InnerText, licenseDateNode.InnerText, expireDateNode.InnerText, LicenseHelper.GetSiteHash(),
                                            openPCNode.InnerText, openWeixinNode.InnerText, openAppNode.InnerText, openWapNode.InnerText, openAliohNode.InnerText);

                bool flag = false;
                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
                {
                    rsa.FromXmlString(LicenseHelper.GetPublicKey());

                    RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(rsa);
                    deformatter.SetHashAlgorithm("SHA1");

                    byte[]      rgbSignature = System.Convert.FromBase64String(signNode.InnerText);
                    SHA1Managed sHA1Managed  = new SHA1Managed();

                    byte[] rgbHash = sHA1Managed.ComputeHash(System.Text.Encoding.UTF8.GetBytes(data));
                    flag = deformatter.VerifySignature(rgbHash, rgbSignature);
                }

                result = (flag && System.DateTime.Now < DateTime.Parse(expireDateNode.InnerText));

                if (result)
                {
                    ServiceStatus = true;

                    OpenPC     = openPCNode.InnerText.Equals("1");
                    OpenApp    = openAppNode.InnerText.Equals("1");
                    OpenWeixin = openWeixinNode.InnerText.Equals("1");
                    OpenWap    = openWapNode.InnerText.Equals("1");
                    OpenAliOH  = openAliohNode.InnerText.Equals("1");
                }
            }

            return(result);
        }