public void Can_generate_floating_license()
        {
            const string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<floating-license>
  <license-server-public-key>&lt;RSAKeyValue&gt;&lt;Modulus&gt;tOAa81fDkKAIcmBx5SybBQM34OG12Qsbm0V8H10Q5iL3bFIco1S6BFyKRK84LKitSPczY3z62imwNkanDVfXhnhl2UFTS0MTkhXM+yG9xFRGc3QwIcNE1j7UFAENo7RS1eguVQaYm26uaqgYXWHJn352CzddV7Lv4M3lAe6oh2M=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;</license-server-public-key>
  <name>ayende</name>
  <Signature xmlns=""http://www.w3.org/2000/09/xmldsig#"">
    <SignedInfo>
      <CanonicalizationMethod Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315"" />
      <SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#rsa-sha1"" />
      <Reference URI="""">
        <Transforms>
          <Transform Algorithm=""http://www.w3.org/2000/09/xmldsig#enveloped-signature"" />
        </Transforms>
        <DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" />
        <DigestValue>t7E+c2Q3ZU6/H6su57vpC7zTxC0=</DigestValue>
      </Reference>
    </SignedInfo>
    <SignatureValue>CoC8WI7WyfPwJGY3jHC4/OJZ2QrJD38YHC+IsivD2p0LwiOmMv+BuwwznPk+MEKQGQxWKzVFJwFXYhmbdDnYoX1ad0xb9q93kKLVu1HTts2682SOpvUhBC9JDXUPdYKPuA+eZNNAaLmfjwsYNzMDlwZlFLOV4S8bPAnnnk1cy01pRPT9nWZS89S86fpN0ws+XPuaS6yj9luv5DCNMYKa18loDnuKuD6hAyby3HWVDcRdyjd8yDCCHH090hubjUubSIFFRSR2CLiK0aQ5fqDJEEdxiI9F7s/r+qz2Ou5aAo2jOEAua+jLdzX/bUzFlUadw8daTEYf82hnDCmFO/BbnQ==</SignatureValue>
  </Signature>
</floating-license>";

            var generator = new LicenseGenerator(public_and_private);
            var license   = generator.GenerateFloatingLicense("ayende", floating_public);

            Assert.Equal(expected, license);
        }
        public void Gen_and_validate_with_attributes()
        {
            var guid       = Guid.NewGuid();
            var generator  = new LicenseGenerator(public_and_private);
            var expiration = DateTime.Now.AddDays(30);
            var key        = generator.Generate("Oren Eini", guid, expiration,
                                                new Dictionary <string, string>
            {
                { "prof", "llb" },
                { "reporting", "on" }
            }, LicenseType.Trial);

            var path = Path.GetTempFileName();

            File.WriteAllText(path, key);

            var validator = new LicenseValidator(public_only, path);

            validator.AssertValidLicense();

            Assert.Equal("llb", validator.LicenseAttributes["prof"]);
            Assert.Equal("on", validator.LicenseAttributes["reporting"]);
            Assert.Equal(guid, validator.UserId);
            Assert.Equal(expiration, validator.ExpirationDate);
            Assert.Equal("Oren Eini", validator.Name);
            Assert.Equal(LicenseType.Trial, validator.LicenseType);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var cryptoKeyProvider = new CryptoKeyProvider();

            var privateKey = cryptoKeyProvider.GenerateKey();
            var publicKey  = cryptoKeyProvider.ExtractPublicKey(privateKey);

            Console.WriteLine("Public Key:");
            Console.WriteLine(publicKey.Contents);
            Console.WriteLine();

            var licenseCriteria = new LicenseCriteria
            {
                ExpirationDate = DateTimeOffset.UtcNow.AddDays(30),
                IssueDate      = DateTimeOffset.UtcNow,
                Id             = Guid.NewGuid(),
                MetaData       = new Dictionary <string, string> {
                    { "LicensedCores", "2" }
                },
                Type = "Subscription"
            };

            var license = new LicenseGenerator().Generate(privateKey, licenseCriteria);

            Console.WriteLine(license.Document);
            Console.WriteLine();

            Console.ReadKey();
        }
Esempio n. 4
0
        private void generateKeys(bool isLoad = false)
        {
            if (File.Exists("privateKey.xml") || File.Exists("publicKey.xml"))
            {
                if (isLoad == false)
                {
                    var result = MessageBox.Show("The key is existed, override it?", "Warning", MessageBoxButtons.YesNo);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            var privateKey = "";
            var publicKey  = "";

            LicenseGenerator.GenerateLicenseKey(out privateKey, out publicKey);

            File.WriteAllText("privateKey.xml", privateKey);
            File.WriteAllText("publicKey.xml", publicKey);

            ResultText.AppendText("The Key is created, please backup it.\n");
        }
Esempio n. 5
0
        public void ExceptionThrownWhenNullLicenseDetailsPassedIn()
        {
            var key       = new RSACryptoServiceProvider();
            var generator = new LicenseGenerator(key);

            generator.GenerateSignedXml(null);
        }
Esempio n. 6
0
        public virtual void testMakeLicense1()
        {
            LicenseGenerator lg      = new LicenseGenerator(getResource("privkey.pem"));
            string           license = lg.makeLicense(new LicenseData(null, "username", null));

            Assert.IsTrue(license.Length > 0);
        }
Esempio n. 7
0
        public virtual void testMakeLicense()
        {
            LicenseGenerator lg      = new LicenseGenerator(getResource("privkey.pem"));
            string           license = lg.makeLicense(new LicenseData("Test", "Karl", "*****@*****.**"));

            Assert.IsTrue(license.Length > 0);
        }
Esempio n. 8
0
        public virtual void testPublicKey()
        {
            LicenseGenerator lg = new LicenseGenerator(getResource("pubkey.pem"));

            Assert.IsFalse(lg.CanMakeLicenses);
            Assert.IsTrue(lg.CanVerifyLicenses);
        }
Esempio n. 9
0
        private void btnGenerateLicenseKey_Click(object sender, RoutedEventArgs e)
        {
            // var assembly = AppDomain.CurrentDomain.BaseDirectory;
            var privateKeyPath = GetWorkDirFile("privateKey.xml");
            var publicKeyPath  = GetWorkDirFile("publicKey.xml");

            if (File.Exists(privateKeyPath) || File.Exists(publicKeyPath))
            {
                var result = MessageBox.Show("The key is existed, override it?", "Warning", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            var privateKey = "";
            var publicKey  = "";

            LicenseGenerator.GenerateLicenseKey(out privateKey, out publicKey);

            File.WriteAllText(privateKeyPath, privateKey);
            File.WriteAllText(publicKeyPath, publicKey);

            MessageBox.Show("The Key is created, please backup it.");
        }
        public void Can_validate_expired_subscription_license_when_service_returns_new_one()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                             DateTime.UtcNow.AddDays(-1),
                                             new Dictionary<string, string> { { "version", "2.0" } }, LicenseType.Subscription);


            var path = Path.GetTempFileName();
            File.WriteAllText(path, license);

            var host = new ServiceHost(typeof(DummySubscriptionLicensingService));
            const string address = "http://localhost:19292/license";
            host.AddServiceEndpoint(typeof(ISubscriptionLicensingService), new BasicHttpBinding(), address);

            host.Open();

            Assert.DoesNotThrow(() => new LicenseValidator(public_only, path)
            {
                SubscriptionEndpoint = address
            }.AssertValidLicense());


            host.Close();
        }
        public void Gen_and_validate_with_attributes()
        {
            var guid = Guid.NewGuid();
            var generator = new LicenseGenerator(public_and_private);
            var expiration = DateTime.Now.AddDays(30);
            var key = generator.Generate("Oren Eini", guid, expiration,
                                         new Dictionary<string, string>
                                         {
                                            {"prof", "llb"},
                                            {"reporting", "on"}
                                         }, LicenseType.Trial);

            var path = Path.GetTempFileName();
            File.WriteAllText(path, key);

            var validator = new LicenseValidator(public_only, path);
            validator.AssertValidLicense();

            Assert.Equal("llb", validator.LicenseAttributes["prof"]);
            Assert.Equal("on", validator.LicenseAttributes["reporting"]);
            Assert.Equal(guid, validator.UserId);
            Assert.Equal(expiration, validator.ExpirationDate);
            Assert.Equal("Oren Eini", validator.Name);
            Assert.Equal(LicenseType.Trial, validator.LicenseType);
        }
Esempio n. 12
0
        public void Can_validate_expired_subscription_license_when_service_returns_new_one()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license   = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                               DateTime.UtcNow.AddDays(-1),
                                               new Dictionary <string, string> {
                { "version", "2.0" }
            }, LicenseType.Subscription);


            var path = Path.GetTempFileName();

            File.WriteAllText(path, license);

            var          host    = new ServiceHost(typeof(DummySubscriptionLicensingService));
            const string address = "http://localhost:19292/license";

            host.AddServiceEndpoint(typeof(ISubscriptionLicensingService), new BasicHttpBinding(), address);

            host.Open();

            Assert.DoesNotThrow(() => new LicenseValidator(new DebugLogService(), public_only, path)
            {
                SubscriptionEndpoint = address
            }.AssertValidLicense());


            host.Close();
        }
        public void Can_generate_floating_license()
        {
            const string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
            <floating-license>
              <license-server-public-key>&lt;RSAKeyValue&gt;&lt;Modulus&gt;tOAa81fDkKAIcmBx5SybBQM34OG12Qsbm0V8H10Q5iL3bFIco1S6BFyKRK84LKitSPczY3z62imwNkanDVfXhnhl2UFTS0MTkhXM+yG9xFRGc3QwIcNE1j7UFAENo7RS1eguVQaYm26uaqgYXWHJn352CzddV7Lv4M3lAe6oh2M=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;</license-server-public-key>
              <name>ayende</name>
              <Signature xmlns=""http://www.w3.org/2000/09/xmldsig#"">
            <SignedInfo>
              <CanonicalizationMethod Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315"" />
              <SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#rsa-sha1"" />
              <Reference URI="""">
            <Transforms>
              <Transform Algorithm=""http://www.w3.org/2000/09/xmldsig#enveloped-signature"" />
            </Transforms>
            <DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" />
            <DigestValue>t7E+c2Q3ZU6/H6su57vpC7zTxC0=</DigestValue>
              </Reference>
            </SignedInfo>
            <SignatureValue>CoC8WI7WyfPwJGY3jHC4/OJZ2QrJD38YHC+IsivD2p0LwiOmMv+BuwwznPk+MEKQGQxWKzVFJwFXYhmbdDnYoX1ad0xb9q93kKLVu1HTts2682SOpvUhBC9JDXUPdYKPuA+eZNNAaLmfjwsYNzMDlwZlFLOV4S8bPAnnnk1cy01pRPT9nWZS89S86fpN0ws+XPuaS6yj9luv5DCNMYKa18loDnuKuD6hAyby3HWVDcRdyjd8yDCCHH090hubjUubSIFFRSR2CLiK0aQ5fqDJEEdxiI9F7s/r+qz2Ou5aAo2jOEAua+jLdzX/bUzFlUadw8daTEYf82hnDCmFO/BbnQ==</SignatureValue>
              </Signature>
            </floating-license>";

            var generator = new LicenseGenerator(public_and_private);
            var license = generator.GenerateFloatingLicense("ayende", floating_public);
            Assert.Equal(expected, license);
        }
		public void Will_detect_duplicate_license()
		{
			var guid = Guid.NewGuid();
			var generator = new LicenseGenerator(public_and_private);
			var expiration = DateTime.Now.AddDays(30);
			var key = generator.Generate("Oren Eini", guid, expiration, LicenseType.Trial);

			var path = Path.GetTempFileName();
			File.WriteAllText(path, key);

			var wait = new ManualResetEvent(false);

			var validator = new LicenseValidator(public_only, path)
			{
				LeaseTimeout = TimeSpan.FromSeconds(1)
			};
			InvalidationType? invalidation = null;
			validator.LicenseInvalidated += type => invalidation = type;
			validator.MultipleLicensesWereDiscovered += (sender, args) => wait.Set();
			validator.AssertValidLicense();

			var validator2 = new LicenseValidator(public_only, path);
			validator2.AssertValidLicense();

      //todo: marked this out  for now
		  //	Assert.True(wait.WaitOne(TimeSpan.FromSeconds(100)));
			//Assert.Equal(invalidation.Value, InvalidationType.TimeExpired);
		}
Esempio n. 15
0
        /// <summary>
        /// 生成license
        /// </summary>
        static void GenerateLicense()
        {
            Console.Write("确定要生成许可吗(Y/N):");
            var k = Console.ReadKey();

            if (k.Key == ConsoleKey.Y)
            {
                var privateKey = File.ReadAllText("privateKey.xml");

                var id        = Guid.NewGuid();
                var generator = new LicenseGenerator(privateKey);

                Console.WriteLine();
                Console.Write("许可名称: ");
                var name = Console.ReadLine();

                //Console.Write("Date: ");
                //var expirationDate = DateTime.Parse(Console.ReadLine());

                //Console.Write("Type: ");
                //LicenseType licenseType = (LicenseType)Enum.Parse(typeof(LicenseType), Console.ReadLine());

                // generate the license
                var license = generator.Generate(name, id, new DateTime(2020, 12, 31), LicenseType.Standard);

                Console.WriteLine();
                Console.WriteLine(license);
                File.WriteAllText("license.lic", license);
            }
            Console.ReadKey();
        }
Esempio n. 16
0
 public string ParseLicenseKey(string text64)
 {
     //LicenseKey is:
     // During trial periods, it contains an expiry date.
     // After payment honored, it changes to GUID. So,...
     try{
         Guid guid = new Guid(text64);
         foreach (KeyValuePair <string, ActivationSet> item in actCache)
         {
             if (guid == item.Value.Id)
             {
                 string xml = ActivationSet.ToXmlString(item.Value);
                 return(xml);
             }
         }
     }catch (Exception) {}
     using (LicenseGenerator Lg = new LicenseGenerator()) {
         string   text = Lg.ParseLicenseKey(text64);
         DateTime trialExpiry;
         bool     isDateTime = DateTime.TryParse(text, out trialExpiry);
         if (isDateTime)
         {
             return(text);
         }
     }
     return(String.Empty);
 }
Esempio n. 17
0
        public void Will_detect_duplicate_license()
        {
            var guid       = Guid.NewGuid();
            var generator  = new LicenseGenerator(public_and_private);
            var expiration = DateTime.Now.AddDays(30);
            var key        = generator.Generate("Oren Eini", guid, expiration, LicenseType.Trial);

            var path = Path.GetTempFileName();

            File.WriteAllText(path, key);

            var wait = new ManualResetEvent(false);

            var validator = new LicenseValidator(public_only, path)
            {
                LeaseTimeout = TimeSpan.FromSeconds(1)
            };
            InvalidationType?invalidation = null;

            validator.LicenseInvalidated             += type => invalidation = type;
            validator.MultipleLicensesWereDiscovered += (sender, args) => wait.Set();
            validator.AssertValidLicense();

            var validator2 = new LicenseValidator(public_only, path);

            validator2.AssertValidLicense();

            //todo: marked this out  for now
            //	Assert.True(wait.WaitOne(TimeSpan.FromSeconds(100)));
            //Assert.Equal(invalidation.Value, InvalidationType.TimeExpired);
        }
Esempio n. 18
0
        private void GenerateLicense()
        {
            if (!File.Exists("privateKey.xml"))
            {
                MessageBox.Show("Please create a license key first");
                return;
            }

            if (string.IsNullOrWhiteSpace(txtName.Text) || string.IsNullOrWhiteSpace(txtComputerKey.Text))
            {
                MessageBox.Show("Some field is missing");
                return;
            }

            var privateKey = File.ReadAllText(@"privateKey.xml");
            var generator  = new LicenseGenerator(privateKey);

            var dict = new Dictionary <string, string>();

            dict["name"] = txtName.Text;
            dict["key"]  = txtComputerKey.Text;

            // generate the license
            var license = generator.Generate("EasyLicense", Guid.NewGuid(), DateTime.UtcNow.AddYears(1), dict,
                                             LicenseType.Standard);

            txtLicense.Text = license;
            File.WriteAllText("license.lic", license);

            File.AppendAllText("license.log", $"License to {dict["name"]}, key is {dict["key"]}, Date is {DateTime.Now}");
        }
        public void Export(Product product, License license, FileInfo path)
        {
            var generator  = new LicenseGenerator(product.PrivateKey);
            var expiration = license.ExpirationDate.GetValueOrDefault(DateTime.MaxValue);
            var key        = generator.Generate(license.OwnerName, license.ID, expiration, license.Data.ToDictionary(userData => userData.Key, userData => userData.Value), license.LicenseType);

            File.WriteAllText(path.FullName, key);
        }
Esempio n. 20
0
        public string Export(Product product, License license)
        {
            var generator  = new LicenseGenerator(product.PrivateKey);
            var expiration = license.ExpirationDate.GetValueOrDefault(DateTime.MaxValue);

            return(generator.Generate(license.OwnerName, license.ID, expiration,
                                      license.Data.ToDictionary(userData => userData.Key, userData => userData.Value), license.LicenseType));
        }
Esempio n. 21
0
        public void Export(Product product, License license, FileInfo path)
        {
            var generator = new LicenseGenerator(product.PrivateKey);
            var expiration = license.ExpirationDate.GetValueOrDefault(DateTime.MaxValue);
            var key = generator.Generate(license.OwnerName, license.ID, expiration, license.Data.ToDictionary(userData => userData.Key, userData => userData.Value), license.LicenseType);

            File.WriteAllText(path.FullName, key);
        }
 private void GenerateLicenseFileInLicensesDirectory()
 {
     var generator = new LicenseGenerator(public_and_private);
     var generate = generator.Generate("ayende", Guid.NewGuid(), DateTime.MaxValue, LicenseType.Standard);
     var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Licenses");
     if (Directory.Exists(dir) == false)
         Directory.CreateDirectory(dir);
     File.WriteAllText(Path.Combine(dir, "ayende.xml"), generate);
 }
        private string WriteFloatingLicenseFile()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license   = generator.GenerateFloatingLicense("ayende", floating_public);
            var fileName  = Path.GetTempFileName();

            File.WriteAllText(fileName, license);
            return(fileName);
        }
Esempio n. 24
0
        public virtual void testFailedVerifyLicense()
        {
            LicenseGenerator lg          = new LicenseGenerator(getResource("privkey.pem"));
            LicenseData      licenseData = new LicenseData("Test", "Karl");

            Assert.IsTrue(lg.verifyLicense(licenseData, "GAWQE-F9AVF-8YSF3-NBDUH-C6M2J-JYAYC-X692H-H65KR-A9KAQ-R9SB7-A374H-T6AH3-87TAB-CVV6K-SKUGG-A"));
            //Assert.IsTrue(lg.verifyLicense(licenseData, "GAWQE-F9AVF-8YSF3-NBDUH-C6M2J-JYAYC-X692H-H65KR-A9KAQ-R9SB7-A374H-T6AH3-87TAB-CVV6K-SKAGG-A"));
            //Assert.IsTrue(lg.verifyLicense(licenseData, "GAWQE-F9AVF-8YSF3-NBDUH-C6M2J-JYAYC-X692H-H65KR-A9KAQ-R9SB7-A374H-T6AH3-87TAB-DVV6K-SKUGG-A"));
        }
Esempio n. 25
0
        public virtual void testVerifyLicense2()
        {
            LicenseGenerator lg          = new LicenseGenerator(getResource("privkey.pem"));
            LicenseData      licenseData = new LicenseData("Test", "Karl");
            string           license     = lg.makeLicense(licenseData);
            bool             verified    = lg.verifyLicense(licenseData, license);

            Assert.IsTrue(verified);
        }
Esempio n. 26
0
        /// <summary>
        /// 生成key
        /// </summary>
        /// <returns>返回 privatekey</returns>
        private static string GenerateLicenseKey()
        {
            string publicKey  = string.Empty;
            string privateKey = string.Empty;

            LicenseGenerator.GenerateLicenseKey(out privateKey, out publicKey);
            File.WriteAllText(_path_pub, publicKey);

            return(privateKey);
        }
Esempio n. 27
0
 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
     if (Session.MachineId == 0)
     {
         Session.MachineId = LicenseGenerator.GenerateLicense();
     }
     
     request.Headers.Add(MessageHeader.CreateHeader(HeaderKey, string.Empty, Session.MachineId));
     return null;
 }
Esempio n. 28
0
        static void GenerateTrialLicenseKey(double days)
        {
            string         seed = DateTime.Today.Add(TimeSpan.FromDays(days)).ToLongDateString();
            LicenseService Bob  = new LicenseService();

            using (LicenseGenerator Alice = new LicenseGenerator()) {
                string text64 = Bob.EncryptSessionKeyByRSA(seed, Alice.Public_KeyUsed);
                byte[] buff   = Convert.FromBase64String(text64);
                Report("Trial License until {1}:\n{0}", text64, Alice.DecryptSessionKeyByRSA(text64));
            }
        }
        public void Can_generate_floating_license()
        {
            var server_public_key = @"<license-server-public-key>&lt;RSAKeyValue&gt;&lt;Modulus&gt;tOAa81fDkKAIcmBx5SybBQM34OG12Qsbm0V8H10Q5iL3bFIco1S6BFyKRK84LKitSPczY3z62imwNkanDVfXhnhl2UFTS0MTkhXM+yG9xFRGc3QwIcNE1j7UFAENo7RS1eguVQaYm26uaqgYXWHJn352CzddV7Lv4M3lAe6oh2M=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;</license-server-public-key>";
            var owner_name        = "<name>ayende</name>";

            var generator = new LicenseGenerator(public_and_private);
            var license   = generator.GenerateFloatingLicense("ayende", floating_public);

            Assert.Contains(server_public_key, license);
            Assert.Contains(owner_name, license);
        }
        public void Can_generate_floating_license()
        {
            var server_public_key = @"<license-server-public-key>&lt;RSAKeyValue&gt;&lt;Modulus&gt;tOAa81fDkKAIcmBx5SybBQM34OG12Qsbm0V8H10Q5iL3bFIco1S6BFyKRK84LKitSPczY3z62imwNkanDVfXhnhl2UFTS0MTkhXM+yG9xFRGc3QwIcNE1j7UFAENo7RS1eguVQaYm26uaqgYXWHJn352CzddV7Lv4M3lAe6oh2M=&lt;/Modulus&gt;&lt;Exponent&gt;AQAB&lt;/Exponent&gt;&lt;/RSAKeyValue&gt;</license-server-public-key>";
            var owner_name = "<name>ayende</name>";

            var generator = new LicenseGenerator(public_and_private);
            var license = generator.GenerateFloatingLicense("ayende", floating_public);

            Assert.Contains(server_public_key, license);
            Assert.Contains(owner_name, license);
        }
        private void GenerateLicenseFileInLicensesDirectory()
        {
            var generator = new LicenseGenerator(public_and_private);
            var generate  = generator.Generate("ayende", Guid.NewGuid(), DateTime.MaxValue, LicenseType.Standard);
            var dir       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Licenses");

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }
            File.WriteAllText(Path.Combine(dir, "ayende.xml"), generate);
        }
Esempio n. 32
0
        public void ThrowsExceptionWhenSignatureIsNotValid()
        {
            // Setup
            var license = CreateLicenseDetail();
            var key     = new RSACryptoServiceProvider(1024);
            var xml     = new LicenseGenerator(key).GenerateSignedXml(license);

            xml = xml.Replace("<LicenseKey>1234</LicenseKey>", "<LicenseKey>12345</LicenseKey>");

            // Test
            new LicenseValidator(key).ValidateLicenseXml(xml);
        }
Esempio n. 33
0
        static void TestMain()
        {
            //試用期限2010年02月21日までのライセンス・キーです。
            string licenseKey = "VfZ0soW2FEBPuTaK9z01vg/732/aG84pvihM3CfvKnW7Zp1dbjCBNNeKQao8UaqlAABJLHo8PQW05xCfpWjQnd0DdzJh8jd78RufH0PnCrC3lQoJrSJMQg6sudTmJ+8jCkFoEGy97lP7+CRTMgnhWEQq7+d8g5klh178R26llpM=";

            using (LicenseGenerator Ls = new LicenseGenerator()) {
                string   text = Ls.ParseLicenseKey(licenseKey);
                DateTime expiry;
                DateTime.TryParse(text, out expiry);
                Report("{0} {1}", expiry.ToLongDateString(), expiry.ToLongTimeString());
            }
        }
Esempio n. 34
0
        public void Can_generate_subscription_license()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                             new DateTime(2010, 10, 10),
                                             new Dictionary<string, string> {{"version", "2.0"}}, LicenseType.Subscription);

            var license_header = @"<license id=""ffd0c62c-b953-403e-8457-e90f1085170d"" expiration=""2010-10-10T00:00:00.0000000"" type=""Subscription"" version=""2.0"">";
            var owner_name = "<name>ayende</name>";

            Assert.Contains(license_header, license);
            Assert.Contains(owner_name, license);
        }
Esempio n. 35
0
 public PaypalLicenseWorkflow(
     LicenseGenerator licenseGenerator,
     EmailSender emailSender,
     UserLicenseEmail userLicenseEmail,
     PaypalIpnValidation paypalIpnValidation,
     ProductProfileSettings productProfileSettings)
 {
     _licenseGenerator       = licenseGenerator;
     _emailSender            = emailSender;
     _userLicenseEmail       = userLicenseEmail;
     _paypalIpnValidation    = paypalIpnValidation;
     _productProfileSettings = productProfileSettings;
 }
        public void Can_generate_subscription_license()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                             new DateTime(2010, 10, 10),
                                             new Dictionary<string, string> {{"version", "2.0"}}, LicenseType.Subscription);

            var license_header = @"<license id=""ffd0c62c-b953-403e-8457-e90f1085170d"" expiration=""2010-10-10T00:00:00.0000000"" type=""Subscription"" version=""2.0"">";
            var owner_name = "<name>ayende</name>";

            Assert.Contains(license_header, license);
            Assert.Contains(owner_name, license);
        }
Esempio n. 37
0
        public void Can_validate_subscription_license_with_time_to_spare()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                             DateTime.UtcNow.AddDays(15),
                                             new Dictionary<string, string> { { "version", "2.0" } }, LicenseType.Subscription);

            
            var path = Path.GetTempFileName();
            File.WriteAllText(path, license);


            Assert.DoesNotThrow(() => new LicenseValidator(public_only, path).AssertValidLicense());	
        }
        public void Can_validate_subscription_license_with_time_to_spare()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                             DateTime.UtcNow.AddDays(15),
                                             new Dictionary<string, string> { { "version", "2.0" } }, LicenseType.Subscription);

            
            var path = Path.GetTempFileName();
            File.WriteAllText(path, license);


            Assert.DoesNotThrow(() => new LicenseValidator(public_only, path).AssertValidLicense());	
        }
        public void Cannot_validate_expired_subscription_license_when_url_is_not_available()
        {
            var generator = new LicenseGenerator(public_and_private);
            var license = generator.Generate("ayende", new Guid("FFD0C62C-B953-403e-8457-E90F1085170D"),
                                             DateTime.UtcNow.AddDays(-1),
                                             new Dictionary<string, string> { { "version", "2.0" } }, LicenseType.Subscription);

            var path = Path.GetTempFileName();
            File.WriteAllText(path, license);

            Assert.Throws<LicenseExpiredException>(() => new LicenseValidator(public_only, path)
            {
                SubscriptionEndpoint = "http://localhost/" + Guid.NewGuid()
            }.AssertValidLicense());
        }
Esempio n. 40
0
        public void An_not_expired_non_OEM_license_is_valid()
        {
            var rsa = new RSACryptoServiceProvider();
            var licenseGenerator = new LicenseGenerator(rsa.ToXmlString(true));
            var licenseValues    = new Dictionary <string, string>();

            var license          = licenseGenerator.Generate("Foo", Guid.NewGuid(), DateTime.Today.AddDays(1), licenseValues, LicenseType.Subscription);
            var licenseValidator = new StringLicenseValidator(rsa.ToXmlString(false), license)
            {
                DisableFloatingLicenses = true,
                SubscriptionEndpoint    = "http://uberprof.com/Subscriptions.svc"
            };

            licenseValidator.AssertValidLicense();
        }
Esempio n. 41
0
        public void Bug_for_year_over_8000_was_marked_as_expired()
        {
            var guid = Guid.NewGuid();
            var generator = new LicenseGenerator(public_and_private);
            var expiration = new DateTime(9999, 10, 10, 10, 10, 10);
            var key = generator.Generate("User name", guid, expiration, LicenseType.Standard);

            var path = Path.GetTempFileName();
            File.WriteAllText(path, key);

            var validator = new LicenseValidator(public_only, path);
            validator.AssertValidLicense();

            Assert.Equal(guid, validator.UserId);
            Assert.Equal(expiration, validator.ExpirationDate);
            Assert.Equal("User name", validator.Name);
            Assert.Equal(LicenseType.Standard, validator.LicenseType);
        }
        public void Throws_date_exception_when_license_is_expired()
        {
            var guid = Guid.NewGuid();
            var generator = new LicenseGenerator(public_and_private);
            var expiration = DateTime.Now.AddDays(-1);
            var key = generator.Generate("Oren Eini", guid, expiration,
                                         new Dictionary<string, string>
                                         {
                                            {"prof", "llb"},
                                            {"reporting", "on"}
                                         }, LicenseType.Trial);

            var path = Path.GetTempFileName();
            File.WriteAllText(path, key);

            var validator = new LicenseValidator(public_only, path);
            Assert.Throws<LicenseExpiredException>(() => validator.AssertValidLicense());
        }
        public void Gen_and_validate()
        {
            var guid = Guid.NewGuid();
            var generator = new LicenseGenerator(public_and_private);
            var expiration = DateTime.Now.AddDays(30);
            var key = generator.Generate("Oren Eini", guid, expiration, LicenseType.Trial);

            var path = Path.GetTempFileName();
            File.WriteAllText(path, key);

            var validator = new LicenseValidator(public_only, path);
            validator.AssertValidLicense();

            Assert.Equal(guid, validator.UserId);
            Assert.Equal(expiration, validator.ExpirationDate);
            Assert.Equal("Oren Eini", validator.Name);
            Assert.Equal(LicenseType.Trial, validator.LicenseType);
        }
 private string WriteFloatingLicenseFile()
 {
     var generator = new LicenseGenerator(public_and_private);
     var license = generator.GenerateFloatingLicense("ayende", floating_public);
     var fileName = Path.GetTempFileName();
     File.WriteAllText(fileName, license);
     return fileName;
 }