Exemple #1
0
        public void ValidateProductKey()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);

            keyPublisher = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);

            var shaHasher     = new SHA1CryptoServiceProvider();
            var usernameHash  = Encoding.ASCII.GetString(shaHasher.ComputeHash(Encoding.ASCII.GetBytes("toto")));
            var companyHash   = Encoding.ASCII.GetString(shaHasher.ComputeHash(Encoding.ASCII.GetBytes("Company")));
            var userEmailHash = Encoding.ASCII.GetString(shaHasher.ComputeHash(Encoding.ASCII.GetBytes("*****@*****.**")));

            Assert.AreEqual(123, result.ProductID);
            Assert.AreEqual(456, result.ProductFeatures);
            Assert.AreEqual(789, result.TrialDays);
            Assert.AreEqual(usernameHash, result.UsernameHash);
            Assert.AreEqual(companyHash, result.CompanyHash);
            Assert.AreEqual(userEmailHash, result.UserEmailHash);
            Assert.AreEqual(DateTime.Now.Date, result.GeneratedDate.Date);
        }
Exemple #2
0
        public void TryRandomKeyGeneration()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(0, 0, 0, "", "", "", "");

            Console.WriteLine(productKey);

            keyPublisher.ValidateProductKey(productKey);

            for (int n = 1; n < 0x100; n++)
            {
                byte[] bytes       = BitConverter.GetBytes(n);
                string fakeSegment = Convert.ToBase64String(new byte[] { bytes[2], bytes[1], bytes[0] });
                if (productKey.Length > 6 && fakeSegment != productKey.Substring(6))
                {
                    productKey = String.Format("{0}{1}", fakeSegment, productKey.Substring(5));
                    try
                    {
                        keyPublisher.ValidateProductKey(productKey);
                        Assert.Fail("This should raise an InvalidProductKeyException");
                    }
                    catch (InvalidProductKeyException)
                    {
                        // OK. We are expecting this exception.
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
Exemple #3
0
        private string GenerateProductKey(short productID, short productFeatures, short trialDays, string clientID, string username, string company, string email)
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            return(keyPublisher.GenerateProductKey(productID, productFeatures, trialDays, clientID, username, company, email));
        }
Exemple #4
0
        public void TryValidateWithFakeCryptProvider()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);

            privateXmlKey = (new RSACryptoServiceProvider()).ToXmlString(true);
            keyPublisher  = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);
        }
Exemple #5
0
        public void TryValidateWithPublicKey()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);

            privateXmlKey = KeyHelpers.GetPublicKey();
            keyPublisher  = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);
        }
Exemple #6
0
        public void ActivateProductTest()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            var activator   = new ProductActivation(privateXmlKey);
            var licenseInfo = activator.ActivateProduct(productKey, Convert.ToBase64String(new MachineIdentifierProviderMock().MachineHash));

            Assert.IsNotNull(licenseInfo);
            Assert.IsNotNull(licenseInfo.ActivationInfo);
            Assert.IsNotNull(licenseInfo.Signature);
        }
Exemple #7
0
        public void ValidateFakeProductKey()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey = keyPublisher.GenerateProductKey(123, 456, 789, "C", "toto", "Company", "*****@*****.**");

            Console.WriteLine(productKey);
            productKey = productKey.Replace('1', '8');
            productKey = productKey.Replace('2', '7');
            productKey = productKey.Replace('3', '6');
            productKey = productKey.Replace('4', '5');
            Console.WriteLine(productKey);

            keyPublisher = new ProductKeyPublisher(privateXmlKey);
            ProductKeyInfo result = keyPublisher.ValidateProductKey(productKey);
        }
Exemple #8
0
        public void GenerateProductKeyTest()
        {
            string privateXmlKey             = KeyHelpers.GetPrivateKey();
            ProductKeyPublisher keyPublisher = new ProductKeyPublisher(privateXmlKey);

            string productKey1 = keyPublisher.GenerateProductKey(0, 0, 0, "C", "toto", "Company", "*****@*****.**");

            System.Threading.Thread.Sleep(1);
            string productKey2 = keyPublisher.GenerateProductKey(0, 0, 0, "C", "toto", "Company", "*****@*****.**");

            System.Threading.Thread.Sleep(1);
            string productKey3 = keyPublisher.GenerateProductKey(0, 0, 0, "C", "toto", "Company", "*****@*****.**");

            System.Threading.Thread.Sleep(1);
            string productKey4 = keyPublisher.GenerateProductKey(0, 0, 0, "C", "toto", "Company", "*****@*****.**");

            Assert.AreNotEqual(productKey1, productKey2);
            Assert.AreNotEqual(productKey1, productKey3);
            Assert.AreNotEqual(productKey1, productKey4);
            Assert.AreNotEqual(productKey2, productKey3);
            Assert.AreNotEqual(productKey2, productKey4);
            Assert.AreNotEqual(productKey3, productKey4);
        }