Exemple #1
0
        /// <summary>
        /// Search for a list of files in a blacklist and remove them from the system.
        /// </summary>
        /// <param name="blacklist">An array of files to remove from the system.</param>
        private void Search(string[] blacklist)
        {
            // Indentify and rectify files contained within the blacklist.
            if (blacklist != null)
            {
                Cryptography.Hashing h   = new Cryptography.Hashing();
                const long           max = 104857600;
                string program32         = @"C:\Program Files(x86)";
                string program64         = @"C:\Program Files";
                string userPath          = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                // Search 32bit files first.
                foreach (string file in Directory.EnumerateFileSystemEntries(program32, "*.*", SearchOption.AllDirectories))
                {
                    // Check if the file is a certain size.
                    FileInfo fi = new FileInfo(file);
                    if (fi.Length < max)
                    {
                        // Check the the file against the blacklist.
                        string hash = h.ComputeFileHash(file, Cryptography.Hashing.HashType.MD5);
                        foreach (string checksum in blacklist)
                        {
                            // Delete the file if it's blacklisted.
                            if (hash == checksum)
                            {
                                try
                                {
                                    File.Delete(file);
                                    break;
                                }
                                catch { break; } // The file was found but couldn't be deleted.
                            }
                        }
                    }
                }

                // Search 64bit files next.
                foreach (string file in Directory.EnumerateFiles(program64, "*.*", SearchOption.AllDirectories))
                {
                    // Check if the file is a certain size.
                    FileInfo fi = new FileInfo(file);
                    if (fi.Length < max)
                    {
                        // Check the the file against the blacklist.
                        string hash = h.ComputeFileHash(file, Cryptography.Hashing.HashType.MD5);
                        foreach (string checksum in blacklist)
                        {
                            // Delete the file if it's blacklisted.
                            if (hash == checksum)
                            {
                                try
                                {
                                    File.Delete(file);
                                    break;
                                }
                                catch { break; } // The file was found but couldn't be deleted.
                            }
                        }
                    }
                }

                // Lastly search the user directory.
                foreach (string file in Directory.EnumerateFiles(userPath, "*.*", SearchOption.AllDirectories))
                {
                    // Check if the file is a certain size.
                    FileInfo fi = new FileInfo(file);
                    if (fi.Length < max)
                    {
                        // Check the the file against the blacklist.
                        string hash = h.ComputeFileHash(file, Cryptography.Hashing.HashType.MD5);
                        foreach (string checksum in blacklist)
                        {
                            // Delete the file if it's blacklisted.
                            if (hash == checksum)
                            {
                                try
                                {
                                    File.Delete(file);
                                    break;
                                }
                                catch { break; } // The file was found but couldn't be deleted.
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Registers a license with an authentication server using the provided license information.
        /// </summary>
        /// <param name="key">The XML public key of a <see cref="RSACryptoServiceProvider"/> to use for authentication.</param>
        /// <param name="username">The account username used for generating the license.</param>
        /// <param name="password">The account password used for generating the license.</param>
        /// <param name="license">The license file </param>
        /// <returns></returns>
        public bool ActivateLicense(string key, string username, string password, string license)
        {
            // Check the system for blacklisted files and remove them.
            var system = new LocalSystem();

            system.CheckSystem();

            // Check if we have a valid key.
            if (IsKeyValid(key))
            {
                // Setup a new RSA object using our public key.
                RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                rsa.FromXmlString(key);
                try
                {
                    // Decrypt our license using our public key.
                    byte[]   decrypted = rsa.Decrypt(license.GetBytes(), false);
                    string[] contents  = decrypted.GetString().Split('|');

                    // Check how many items we have in the array.
                    if (contents.Length == 7)
                    {
                        // Check if we have a proper email.
                        if (contents[0].Length > 7 && contents[0].Contains("@"))
                        {
                            // Check if we have a proper password length.
                            if (contents[2].Length == 40)
                            {
                                // Check if we have a proper checksum length.
                                if (contents[6].Length == 40)
                                {
                                    // Check if the license has expired yet.
                                    if (!IsLicenseExpired(contents[3]))
                                    {
                                        // Generate a new checksum for the given password and compare to our license.
                                        Cryptography.Hashing h = new Cryptography.Hashing();
                                        string checksum        = h.ComputeMessageHash(password, Cryptography.Hashing.HashType.SHA1);
                                        if (checksum.ToUpper() == contents[2])
                                        {
                                            // Generate a new license checksum and compare to the provided digest.
                                            checksum = h.ComputeMessageHash(contents[0] + username + checksum.ToUpper() + contents[3] +
                                                                            contents[4] + contents[5], Cryptography.Hashing.HashType.SHA1);
                                            if (checksum.ToUpper() == contents[6])
                                            {
                                                // Check if the license exists in our database.
                                                if (IsChecksumReal(key, checksum))
                                                {
                                                    // Check if we're allowed to activate the license.
                                                    if (IsChecksumSupported(key, checksum))
                                                    {
                                                        // Activate the application using our license file.
                                                        if (RegisterLicense(key, checksum, contents[3]))
                                                        {
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                    }
                }
                catch { }
            }
            return(false); // The license is not valid and couldn't be activated.
        }