Esempio n. 1
0
		private void ReadAvailableLicenses(string licensesDirectory)
		{
			foreach (var license in Directory.GetFiles(licensesDirectory, "*.xml"))
			{
				var set = new HashSet<Guid>();
				var validator = new LicenseValidator(SoftwarePublicKey, license)
				{
					DisableFloatingLicenses = true
				};
				try
				{
					validator.AssertValidLicense();
					Debug.WriteLine("Found license for " + validator.Name + " of type: " + validator.LicenseType);
					if (validator.LicenseType == LicenseType.Standard &&
						// this prevent a simple cheating of simply copying the same
						// license file several times
						set.Add(validator.UserId))
					{
						availableLicenses.Add(validator);
						Debug.WriteLine("Accepting license for: " + validator.Name + " " + validator.UserId);
					}
				}
				catch (Exception)
				{
					continue;
				}
			}
		}
Esempio n. 2
0
        public static ChocolateyLicense validate()
        {
            var chocolateyLicense = new ChocolateyLicense
            {
                LicenseType = ChocolateyLicenseType.Unknown
            };

            string licenseFile = ApplicationParameters.LicenseFileLocation;
            //no file system at this point
            if (File.Exists(licenseFile))
            {
                var license = new LicenseValidator(PUBLIC_KEY, licenseFile);

                try
                {
                    license.AssertValidLicense();
                    chocolateyLicense.IsValid = true;
                }
                catch (Exception e)
                {
                    //license may be invalid
                    chocolateyLicense.IsValid = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
                }

                switch (license.LicenseType)
                {
                    case LicenseType.Professional :
                        chocolateyLicense.LicenseType = ChocolateyLicenseType.Professional;
                        break;
                    case LicenseType.Business :
                        chocolateyLicense.LicenseType = ChocolateyLicenseType.Business;
                        break;
                    case LicenseType.Enterprise :
                        chocolateyLicense.LicenseType = ChocolateyLicenseType.Enterprise;
                        break;
                }

                chocolateyLicense.ExpirationDate = license.ExpirationDate;
                chocolateyLicense.Name = license.Name;
                chocolateyLicense.Id = license.UserId.to_string();

                //todo: if it is expired, provide a warning. 
                // one month after it should stop working
            }
            else
            {
                //free version
                chocolateyLicense.LicenseType = ChocolateyLicenseType.Foss;
            }

            return chocolateyLicense;
        }
Esempio n. 3
0
		public void Execute(DocumentDatabase database)
		{
			docDb = database;
			string publicKey;
			using(var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
			{
				if(stream == null)
					throw new InvalidOperationException("Could not find public key for the license");
				publicKey = new StreamReader(stream).ReadToEnd();
			}
			var fullPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "license.xml"));
			licenseValidator = new LicenseValidator(publicKey, fullPath)
			{
				DisableFloatingLicenses = true,
			};
			licenseValidator.LicenseInvalidated+=LicenseValidatorOnLicenseInvalidated;
			licenseValidator.MultipleLicensesWereDiscovered += LicenseValidatorOnMultipleLicensesWereDiscovered;

			if(File.Exists(fullPath) == false)
			{
				LicensingStatus.Current = new LicensingStatus
				{
					Status = "AGPL - Open Source",
					Error = false,
					Message = "No license file was found at " + fullPath +
					          "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted."
				};
				return;
			}

			try
			{
				licenseValidator.AssertValidLicense();

				LicensingStatus.Current = new LicensingStatus
				{
					Status = "Commercial - " + licenseValidator.LicenseType,
					Error = false,
					Message = "Valid license " + fullPath
				};
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not validate license at " + fullPath, e);

				LicensingStatus.Current = new LicensingStatus
				{
					Status = "AGPL - Open Source",
					Error = true,
					Message = "Could not validate license file at " + fullPath + Environment.NewLine + e
				};
			}
		}
Esempio n. 4
0
		public void Execute(DocumentDatabase database)
		{
			docDb = database;
			string publicKey;
			using(var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
			{
				if(stream == null)
					throw new InvalidOperationException("Could not find public key for the license");
				publicKey = new StreamReader(stream).ReadToEnd();
			}
			var fullPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "license.xml"));
			licenseValidator = new LicenseValidator(publicKey, fullPath)
			{
				DisableFloatingLicenses = true,
			};
			licenseValidator.LicenseInvalidated+=LicenseValidatorOnLicenseInvalidated;
			if (licenseValidator.TryLoadingLicenseValuesFromValidatedXml() == false)
				throw new LicenseNotFoundException("Could not find valid license for RavenDB at: " + fullPath);
			
			if (DateTime.UtcNow < licenseValidator.ExpirationDate)
				return;

			LicenseValidatorOnLicenseInvalidated(InvalidationType.TimeExpired);
		}
Esempio n. 5
0
 private static string GenerateLicense(Guid id, LicenseValidator validator, IDictionary<string, string> attributes)
 {
     var generator = new LicenseGenerator(LicenseServerPrivateKey);
     return generator.Generate(validator.Name, id, SystemTime.UtcNow.AddMinutes(45), attributes, LicenseType.Floating);
 }
Esempio n. 6
0
 private string GenerateLicenseAndRenewLease(string identifier, Guid id, LicenseValidator licenseValidator, IDictionary<string, string> attributes)
 {
     leasedLicenses[identifier] = new KeyValuePair<DateTime, LicenseValidator>(SystemTime.UtcNow.AddMinutes(30), licenseValidator);
     using (var file = new FileStream(state, FileMode.Create, FileAccess.ReadWrite))
     {
         WriteState(file);
     }
     return GenerateLicense(id, licenseValidator, attributes);
 }
 private static string GenerateLicense(Guid id, LicenseValidator validator)
 {
     var generator = new LicenseGenerator(LicenseServerPrivateKey);
     return generator.Generate(validator.Name, id, DateTime.Now.AddMinutes(45), LicenseType.Floating);
 }
Esempio n. 8
0
        private static string GenerateLicense(Guid id, LicenseValidator validator, IDictionary <string, string> attributes)
        {
            var generator = new LicenseGenerator(LicenseServerPrivateKey);

            return(generator.Generate(validator.Name, id, DateTime.UtcNow.AddMinutes(45), attributes, LicenseType.Floating));
        }
Esempio n. 9
0
 internal static License CreateFrom(LicenseValidator validator)
 {
     return new License
     (
         validator.UserId,
         validator.Name,
         new Version(validator.LicenseAttributes[LicenseProperty.CmsVersion]),
         Editions.GetEdition(validator.LicenseAttributes[LicenseProperty.CmsEdition]),
         validator.ExpirationDate,
         validator.LicenseType == LicenseType.Trial,
         validator.LicenseAttributes[LicenseProperty.SupportedDomains]
     );
 }
Esempio n. 10
0
        private static string GenerateLicense(Guid id, LicenseValidator validator)
        {
            var generator = new LicenseGenerator(LicenseServerPrivateKey);

            return(generator.Generate(validator.Name, id, DateTime.Now.AddMinutes(45), LicenseType.Floating));
        }