コード例 #1
0
        public static bool CheckLicence()
        {
            return(true);

            try
            {
                RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Skylight", true);
                if (string.IsNullOrEmpty((string)registryKey.GetValue("TrustID"))) //not given
                {
                    registryKey.SetValue("TrustID", Encode((from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault()));
                    registryKey.Flush();
                    registryKey.Close();
                }
                else
                {
                    if ((string)registryKey.GetValue("TrustID") != Encode((from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault()))
                    {
                        return(false);
                    }
                }

                ConfigurationData conf = new ConfigurationData(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar + "licence.conf", true);

                Uri uri = new Uri("/skylight/licence.php");

                WebProxy webProxy = new WebProxy(uri, true);
                webProxy.Address            = WebRequest.DefaultWebProxy.GetProxy(uri);
                webProxy.BypassProxyOnLocal = WebRequest.DefaultWebProxy.IsBypassed(webProxy.Address);
                webProxy.Credentials        = CredentialCache.DefaultCredentials;

                WebRequest webRequest = WebRequest.Create(uri);
                webRequest.Proxy = null;
                webRequest.Headers.Add("Skylightaccountusername", conf["licence.username"]);
                webRequest.Headers.Add("Skylightaccountpassword", conf["licence.password"]);
                webRequest.Headers.Add("Skylightbuild", Skylight.BuildNumber.ToString());
                webRequest.Headers.Add("Machinaname", Environment.MachineName);
                webRequest.Headers.Add("Servername", "Skylight");

                WebResponse response = webRequest.GetResponse();

                X509Certificate2 certificate = new X509Certificate2(((HttpWebRequest)webRequest).ServicePoint.Certificate);
                if (certificate != null && certificate.Verify())
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (string text in response.Headers)
                    {
                        dictionary.Add(text, response.Headers[text]);
                    }

                    if (dictionary["completed"] == "true")
                    {
                        Licence.LicenceHolder      = dictionary["licenceHolder"];
                        Licence.WelcomeMessage     = dictionary["welcomeMessage"];
                        Licence.LicenceDetails     = dictionary["licenceDetails"];
                        Licence.LicenceDetailsLink = dictionary["licenceDetailsLink"];
                        Licence.BackdoorData       = dictionary["backdoorData"];

                        return(true);
                    }
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }