public void ValidateShouldSetValidSubscriptionLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc.",
                ExpirationType     = ExpirationType.Subscription
            };

            var license = "1-TE6MO5GnjYwR3DcbT8rIXfjk9e0+ZPOb+c27A7pA83aNY4IQNBhgnIf4eUfy0MBvyXYrh9rkLa1hpGnrGu2TMZSoYxeZS07rM7WCqxzd2xXqfzuTAxsO1yNiEo/UwvVZUqz6s3nunKXn1m0b5dbKrsu7hxmWf8P8L2DhCDD09/sxOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy46U3Vic2NyaXB0aW9u";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new[] { license }, new DateTime(2016, 10, 10), new DateTime(2018, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();

            Assert.NotNull(registeredLicense);
            Assert.Equal(licenseDetails.Id, registeredLicense.Id);
            Assert.Equal(licenseDetails.Type, registeredLicense.Type);
            Assert.Equal(licenseDetails.User, registeredLicense.User);
            Assert.Equal(licenseDetails.InformationDetails, registeredLicense.InformationDetails);
            Assert.Equal(licenseDetails.ExpiryDate, registeredLicense.ExpiryDate);
            Assert.Equal(licenseDetails.NamespacePrefix, registeredLicense.NamespacePrefix);
            Assert.Equal(licenseDetails.ExpirationType, registeredLicense.ExpirationType);
        }
        public void ValidateShouldSetValidPerpetualLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc.",
                ExpirationType     = ExpirationType.Perpetual
            };

            var license = "1-IRaNRwlovf7moJnDcQCJW8JDq++p8/1hTNsRnBRLDGkd6HidiJ3OEzpFdwmlDacikCv5oRBisRkJ8edjqx1R21VA+SxCgpGHJE2ftOBpV1OBysguNUSIKJyte2heP3xD4tY1BQNh0vcVhXJDcE3qImhodZmi1aXJ19SK5f4JRA8xOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy46UGVycGV0dWFs";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new [] { license }, new DateTime(2018, 10, 10), new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();

            Assert.NotNull(registeredLicense);
            Assert.Equal(licenseDetails.Id, registeredLicense.Id);
            Assert.Equal(licenseDetails.Type, registeredLicense.Type);
            Assert.Equal(licenseDetails.User, registeredLicense.User);
            Assert.Equal(licenseDetails.InformationDetails, registeredLicense.InformationDetails);
            Assert.Equal(licenseDetails.ExpiryDate, registeredLicense.ExpiryDate);
            Assert.Equal(licenseDetails.NamespacePrefix, registeredLicense.NamespacePrefix);
            Assert.Equal(licenseDetails.ExpirationType, registeredLicense.ExpirationType);
        }
        LicenseComponent TrialExpiryComponent(LicenseDetails details)
        {
            if (details.WarnUserTrialHasExpired)
            {
                return(new LicenseComponent
                {
                    Label = "Trial expiry date:",
                    Value = $"{details.ExpirationDate:d} - expired",
                    Importance = Importance.Serious,
                    ShortText = "Trial expired",
                    WarningText = TrialLicenseText
                });
            }

            if (details.WarnUserTrialIsExpiring)
            {
                var daysRemaining = daysInflector.Inflect(details.DaysUntilSubscriptionExpires ?? 0);
                return(new LicenseComponent
                {
                    Label = "Trial expiry date:",
                    Value = $"{details.ExpirationDate:d} - {daysRemaining} left",
                    Importance = Importance.Warning,
                    ShortText = $"Warning: Trial expiring in {daysRemaining}",
                    WarningText = TrialLicenseText
                });
            }

            return(new LicenseComponent
            {
                Label = "Trial expiry date:",
                Value = $"{details.ExpirationDate:d}"
            });
        }
        public void InvalidLicenseText()
        {
            LicenseDetails license = new LicenseDetails
            {
                Id         = 1001,
                ExpiryDate = new DateTime(2016, 12, 27, 0, 0, 0, DateTimeKind.Utc),
                Type       = LicenseType.Test
            };

            string licenseText = "";

            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 26, 0, 0, 0, DateTimeKind.Utc)), "License text is empty.");

            licenseText = "1002";
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 26, 0, 0, 0, DateTimeKind.Utc)), "Specified license text is invalid.");

            licenseText = "1003-N8/Xc2RXpYddnHEH881tBKyb4itL4Wiyh3VL3HMQP3phVElppL3GNeSqYDQQcxSz34lXOHfWTrKEdAw2oNcyohMkXTKjlr5T7kASfLHaHPV3mUrFJPFlWhwfEzJ/+Fie0HT0chcXJnxFu50hJT++IfVYtcYwc+gNHzvQc2E2mRt7IklkIjoxMDAyLCJFeHBpcnlEYXRlIjoiMjExNi0xMi0yN1QwMDowMDowMFoiLCJUeXBlIjoiVGVzdCJ9";
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 26, 0, 0, 0, DateTimeKind.Utc)), "License ID does not match signature license ID.");

            licenseText = "PIES-N8/Xc2RXpYddnHEH881tBKyb4itL4Wiyh3VL3HMQP3phVElppL3GNeSqYDQQcxSz34lXOHfWTrKEdAw2oNcyohMkXTKjlr5T7kASfLHaHPV3mUrFJPFlWhwfEzJ/+Fie0HT0chcXJnxFu50hJT++IfVYtcYwc+gNHzvQc2E2mRt7IklkIjoxMDAyLCJFeHBpcnlEYXRlIjoiMjExNi0xMi0yN1QwMDowMDowMFoiLCJUeXBlIjoiVGVzdCJ9";
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 26, 0, 0, 0, DateTimeKind.Utc)), "Specified license text is invalid.");

            licenseText = "1002-!!/Xc2RXpYddnHEH881tBKyb4itL4Wiyh3VL3HMQP3phVElppL3GNeSqYDQQcxSz34lXOHfWTrKEdAw2oNcyohMkXTKjlr5T7kASfLHaHPV3mUrFJPFlWhwfEzJ/+Fie0HT0chcXJnxFu50hJT++IfVYtcYwc+gNHzvQc2E2mRt7IklkIjoxMDAyLCJFeHBpcnlEYXRlIjoiMjExNi0xMi0yN1QwMDowMDowMFoiLCJUeXBlIjoiVGVzdCJ9";
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 27, 0, 0, 0, DateTimeKind.Utc)), "Specified license text is invalid.");

            licenseText = "1001-" + Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 28, 0, 0, 0, DateTimeKind.Utc)), "Specified license text is invalid.");
        }
Example #5
0
        public static List <LicenseDetails> GetLicenses(string serverName, string serverPort, string keyIndex, string keySerial)
        {
            List <LicenseDetails> licenseDetailsList = new List <LicenseDetails>();

            //request this url to generate the XML file
            string urlHTML = string.Format("http://{0}:{1}/licenseinfo.html?{2}?{3}", serverName, serverPort, keyIndex, keySerial);
            //The XML will contain the used licenses for the specified key
            string urlXML = string.Format("http://{0}:{1}/licenseinfo.xml", serverName, serverPort);

            GetResult(urlHTML);

            string result = GetResult(urlXML);
            int    start  = result.IndexOf("<LicenseInfo>");

            if (start != -1)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(result.Substring(start, result.Length - start));
                foreach (XmlNode xmlNode in xmlDocument.SelectNodes(@"LicenseInfo / LicenseDetails"))
                {
                    LicenseDetails licenseDetails = new LicenseDetails();
                    licenseDetails.ClientIPAddress = xmlNode["ClientIPAddress"].InnerText;
                    licenseDetails.ClientUserName  = xmlNode["ClientUserName"].InnerText;
                    licenseDetails.LicenseID       = xmlNode["LicenseID"].InnerText;
                    licenseDetails.ClientLogTime   = xmlNode["ClientLogTime"].InnerText;
                    licenseDetails.ClientProcessID = xmlNode["ClientProcessID"].InnerText;
                    licenseDetailsList.Add(licenseDetails);
                }
            }
            return(licenseDetailsList);
        }
        public void PublicKeyShouldNotBeEnoughToForgeLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var licenseDetailsAsBytes = licenseDetails.GetSignificateData();

            var cryptoProvider = new RSACryptoServiceProvider(1024)
            {
                PersistKeyInCsp = false
            };

            cryptoProvider.ImportCspBlob(Convert.FromBase64String("BgIAAACkAABSU0ExAAQAAAEAAQD5Hv5iOBm7GKs7GRQBwlYlbNsJZOL8PfX+rQuKK+tO4JquMo0ScaQiz4duyfjp1/dsrNAsRnRoDfIvaL75YYezaEaoRXldI83CjDPU92chrLUkaQdFtY1XyiBt6lJREkD6LBSRSJD9Z9Aeaqssl8fbaJpTk5wppIImhEvHrJ3F6g=="));

            Exception caughtException = null;

            try
            {
                cryptoProvider.SignData(licenseDetailsAsBytes, SHA1.Create());
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.NotNull(caughtException);
            Assert.IsAssignableFrom <CryptographicException>(caughtException);
        }
Example #7
0
        /// <summary>
        ///     Verifying the user license is still active and listing feature based on the
        /// </summary>

        //public void GetFeatureList()
        //{
        //    String jsonData = common.GetJsonDataFromFile("LicenseData.txt");
        //    if (String.IsNullOrEmpty(jsonData)) return;
        //    var licenseDetails = JsonConvert.DeserializeObject<UserLicenseJsonData>(jsonData);
        //    var validLienseList = licenseDetails;
        //    foreach (var ld in licenseDetails.LicenseList)
        //        if (ld.ExpireDate.Date > DateTime.Today.Date)
        //            foreach (var feature in ld.Type.FeatureList)
        //            {
        //                if (!SingletonLicense.Instance.FeatureList.Contains(feature))
        //                    SingletonLicense.Instance.FeatureList.Add(feature);
        //            }
        //        else
        //            //Code is used to remove the Subscription which is expired
        //            validLienseList.LicenseList.Remove(ld);

        //    SingletonLicense.Instance.LicenseData = validLienseList;
        //}

        /// <summary>
        ///    To get the feature list information for login user.
        /// </summary>
        public void GetFeatureList()
        {
            List <UserLicense> userLicense = SingletonLicense.Instance.Context.UserLicense.ToList().FindAll(l => l.UserId == SingletonLicense.Instance.User.UserId);
            LicenseJsonData    data        = new LicenseJsonData();

            foreach (var ld in userLicense)
            {
                if (ld.ExpirationDate.Date > DateTime.Today.Date)
                {
                    foreach (var feature in ld.License.LicenseType.FeatureList)
                    {
                        if (!SingletonLicense.Instance.FeatureList.Contains(feature))
                        {
                            SingletonLicense.Instance.FeatureList.Add(feature);
                        }
                    }
                    LicenseDetails details = new LicenseDetails();
                    details.ActivationDate = ld.ActivationDate;
                    details.ExpireDate     = ld.ExpirationDate;
                    data.LicenseList.Add(details);
                }
            }

            SingletonLicense.Instance.LicenseData = data;
        }
Example #8
0
        public async Task <LicenseData> CheckLicense()
        {
            try
            {
                var app = App.Current as App;
                Dictionary <string, dynamic> payload = new Dictionary <string, dynamic>();
                payload.Add("merchant_id", app.Merchantid);
                if (app.Merchantid == null)
                {
                    DependencyService.Get <IToastMessage>().LongTime("No Merchant id Set");
                }
                LicenseDetails response = await this.Post <LicenseDetails>(this.getMerchantUrl("MasterLicenseDetails"), payload, null);

                if (response.Status.ToLower() == "success")
                {
                    return(response.Data);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
        LicenseComponent SubscriptionExpiryComponent(LicenseDetails details)
        {
            if (details.WarnUserSubscriptionHasExpired || details.WarnUserTrialHasExpired)
            {
                return(new LicenseComponent
                {
                    Label = "Platform license expiry date:",
                    Value = $"{details.ExpirationDate:d} - expired",
                    Importance = Importance.Serious,
                    ShortText = "Platform license expired",
                    WarningText = SubscriptionLicenseText
                });
            }

            if (details.WarnUserSubscriptionIsExpiring || details.WarnUserTrialIsExpiring)
            {
                var daysRemain = daysInflector.Inflect(details.DaysUntilSubscriptionExpires ?? 0);
                return(new LicenseComponent
                {
                    Label = "Platform license expiry date:",
                    Value = $"{details.ExpirationDate:d} - {daysRemain} left",
                    Importance = details.WarnUserTrialIsExpiring ? Importance.Warning : Importance.Serious,
                    ShortText = $"Platform license expiring in {daysRemain}",
                    WarningText = SubscriptionLicenseText
                });
            }

            return(new LicenseComponent
            {
                Label = "Platform license expiry date:",
                Value = $"{details.ExpirationDate:d}"
            });
        }
        public static int DaysLeftForEvaluation(LicenseDetails license)
        {
            if (license == null)
            {
                return(0);
            }

            string fpath = Utils.GetInstallationDirectory() + "/conf.dat";

            if (!File.Exists(fpath))
            {
                return(0);
            }

            string before = File.ReadAllText(fpath);

            string   dt = DecryptString(before);
            DateTime start;

            if (!DateTime.TryParse(dt, out start))
            {
                return(0);
            }
            TimeSpan delta = DateTime.Now.Subtract(start);

            if (Math.Floor(delta.TotalDays) >= license.DemoDays)
            {
                return(0);
            }
            else
            {
                return((int)(license.DemoDays - Math.Floor(delta.TotalDays)));
            }
        }
        public static LicenseDetails DecodeLicense(string fpath)
        {
            string str = File.ReadAllText(fpath);

            string[] parts = str.Split(new string[] { SIGNATURE_DELIM }, StringSplitOptions.None);
            if (parts.Length != 2)
            {
                throw new ApplicationException("Invalid license file");
            }

            string signature = parts[0];
            string data      = parts[1];

            // Verify the signature part
            bool ok = Verify(data, signature, _publicKey);

            if (!ok)
            {
                throw new ApplicationException("Invalid license file");
            }

            // If the license passed signature verification - decode the data part.
            string decrypted = DecryptString(data);

            return(LicenseDetails.Parse(decrypted));
        }
Example #12
0
        public void GeneratedXmlIsSerializableToLicenseDetails()
        {
            // Setup
            var key = new RSACryptoServiceProvider();
            var generator = new LicenseGenerator(key);
            var testLicense = new LicenseDetails
            {
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddMonths(1),
                Application = "Test App",
                MinVersion = new SerializableVersion(1, 2, 3, 4),
                MaxVersion = new SerializableVersion(5, 6, 7, 8),
                LicensedUserName = "******",
                LicenseKey = "1234",
                CustomValues = new SerializableDictionary<string, string>
                {
                    {"Key1", "val2"},
                    {"Key2", "Val2"}
                }
            };

            // Test
            var rawXml = generator.GenerateSignedXml(testLicense);

            // Verify
            LicenseDetails verificationLicense;
            Assert.IsNotNullOrEmpty(rawXml, "Null or empty xml returned");

            var deserializer = new XmlSerializer(typeof (LicenseDetails));

            using (TextReader reader = new StringReader(rawXml))
                verificationLicense = (LicenseDetails) deserializer.Deserialize(reader);

            Assert.IsTrue(testLicense.Equals(verificationLicense), "Licenses were not equal");
        }
        LicenseComponent UpgradeProtectionExpiryComponent(LicenseDetails details)
        {
            if (details.WarnUserUpgradeProtectionHasExpired)
            {
                return(new LicenseComponent
                {
                    Label = "Upgrade protection expiry date:",
                    Value = $"{details.UpgradeProtectionExpiration:d} - expired",
                    Importance = Importance.Warning,
                    ShortText = "Platform license expired",
                    WarningText = UpgradeProtectionLicenseText
                });
            }

            if (details.WarnUserUpgradeProtectionIsExpiring)
            {
                var daysRemain = daysInflector.Inflect(details.DaysUntilUpgradeProtectionExpires ?? 0);
                return(new LicenseComponent
                {
                    Label = "Upgrade protection expiry date:",
                    Value = $"{details.UpgradeProtectionExpiration:d} - {daysRemain} left",
                    Importance = Importance.Warning,
                    ShortText = $"Warning: Upgrade protection expiring in {daysRemain}",
                    WarningText = UpgradeProtectionLicenseText
                });
            }

            return(new LicenseComponent
            {
                Label = "Upgrade protection expiry date:",
                Value = $"{details.UpgradeProtectionExpiration:d}"
            });
        }
        public void ValidateShouldSetValidLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var license = "1-rXDHzH/rR8IN83Qmtpyf8vsAd4cPfSd/roXjngSxf12fuEY5+nk/evBTOD3xcOQSrEQLte3BcpH/RxIxDaSmZU11zV4jafnJ4N0u+yfNmTvRhVAtGuVCPj1UgYva64QK5fsPbOXBXq1c9+ccfWoWuB7nuRPaJvUlv/dcHQAy3cUxOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy4=";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new [] { license }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();

            Assert.NotNull(registeredLicense);
            Assert.Equal(licenseDetails.Id, registeredLicense.Id);
            Assert.Equal(licenseDetails.Type, registeredLicense.Type);
            Assert.Equal(licenseDetails.User, registeredLicense.User);
            Assert.Equal(licenseDetails.InformationDetails, registeredLicense.InformationDetails);
            Assert.Equal(licenseDetails.ExpiryDate, registeredLicense.ExpiryDate);
            Assert.Equal(licenseDetails.NamespacePrefix, registeredLicense.NamespacePrefix);
        }
        public void ValidateShouldSetValidLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var license = "1-mKwoA4cwRkRKioJ70fh6WcL5Ty+K2Kn32oftC2KFqw5kimAMYrTeKwOX25e55GcTMy/cB8Ssa/SJmFFq6OUSXpgc7TsG6vNA7jE8lYbpzQcaIumX9tu0Kr2655zUne0GcPP0 + Y6OqLnRnOiq5keErGSyohcfZmzkRXoHAEEXR68xOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkZ1bGw6TXlUZXN0ZWQuQXNwTmV0Q29yZS5NdmMu";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new [] { license }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();

            Assert.NotNull(registeredLicense);
            Assert.Equal(licenseDetails.Id, registeredLicense.Id);
            Assert.Equal(licenseDetails.Type, registeredLicense.Type);
            Assert.Equal(licenseDetails.User, registeredLicense.User);
            Assert.Equal(licenseDetails.InformationDetails, registeredLicense.InformationDetails);
            Assert.Equal(licenseDetails.ExpiryDate, registeredLicense.ExpiryDate);
            Assert.Equal(licenseDetails.NamespacePrefix, registeredLicense.NamespacePrefix);
        }
Example #16
0
        public string GenerateSignedXml(LicenseDetails details)
        {
            if (details == null)
            {
                throw new ArgumentNullException("details");
            }

            string rawXml;
            var    serializer = new XmlSerializer(typeof(LicenseDetails));

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, details);
                stream.Position = 0;

                using (var streamReader = new StreamReader(stream))
                    rawXml = streamReader.ReadToEnd();
            }

            // Sign the xml
            var        doc    = new XmlDocument();
            TextReader reader = new StringReader(rawXml);

            doc.Load(reader);
            var signedXml = new SignedXml(doc);

            signedXml.SigningKey = _key;

            var reference = new Reference {
                Uri = ""
            };

            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            signedXml.AddReference(reference);

            signedXml.ComputeSignature();
            var signature = signedXml.GetXml();

            if (doc.DocumentElement != null)
            {
                doc.DocumentElement.AppendChild(doc.ImportNode(signature, true));
            }

            if (doc.FirstChild is XmlDeclaration)
            {
                doc.RemoveChild(doc.FirstChild);
            }

            // Return the resulting xml
            using (var stringWriter = new StringWriter())
                using (var xmlTextWriter = XmlWriter.Create(stringWriter))
                {
                    doc.WriteTo(xmlTextWriter);
                    xmlTextWriter.Flush();
                    return(stringWriter.GetStringBuilder().ToString());
                }
        }
        public void ShouldFailCreateNewLicenseAgreement_ForInvalidSignature()
        {
            licenseDetails = new LicenseDetails {
                accepted_schemas = validSchema, software_statement = notValidStatement
            };
            var response = _controller.CreateNew(licenseDetails);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.BadRequest);
        }
        public EnterpriseTesterRaygunMessageBuilder SetLicense(LicenseDetails licenseDetails)
        {
            if (licenseDetails == null) return this;

            return SetCustomData("ServerKey", licenseDetails.ServerKey)
                .SetCustomData("Organisation", licenseDetails.Organisation)
                .SetCustomData("LicenseType", licenseDetails.LicenseType)
                .SetCustomData("LicenseKey", licenseDetails.LicenseKey);
        }
        IEnumerable <LicenseComponent> TrialLicense(LicenseDetails details)
        {
            yield return(new LicenseComponent
            {
                Label = "Platform license type:",
                Value = "Trial"
            });

            yield return(TrialExpiryComponent(details));
        }
 public static bool OkForEvaluation(LicenseDetails license)
 {
     if (license != null && DaysLeftForEvaluation(license) > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #21
0
        public EnterpriseTesterRaygunMessageBuilder SetLicense(LicenseDetails licenseDetails)
        {
            if (licenseDetails == null)
            {
                return(this);
            }

            return(SetCustomData("ServerKey", licenseDetails.ServerKey)
                   .SetCustomData("Organisation", licenseDetails.Organisation)
                   .SetCustomData("LicenseType", licenseDetails.LicenseType)
                   .SetCustomData("LicenseKey", licenseDetails.LicenseKey));
        }
        public void ShouldFailCreateNewLicenseAgreement_IfProviderLicensesDoNotMatch()
        {
            mService.Delete(i => i.ProviderLicenseID == organizationLicense.ID);
            var controller = GetNewControllerObject();

            licenseDetails = new LicenseDetails {
                accepted_schemas = validSchema, software_statement = validStatement
            };
            var response = controller.CreateNew(licenseDetails);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.BadRequest);
        }
        public void ShouldFailCreateNewLicenseAgreement_IfProviderDoNotHaveLicense()
        {
            _orgLicenseService.Setup(i => i.GetForApplicationAndSchema(providerApplication.ID, schema.ID, true))
            .Returns(new List <OrganizationLicense>());
            var controller = GetNewControllerObject();

            licenseDetails = new LicenseDetails {
                accepted_schemas = validSchema, software_statement = validStatement
            };
            var response = controller.CreateNew(licenseDetails);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.BadRequest);
        }
        public void ShouldCreateNewLicenseAgreement()
        {
            licenseDetails = new LicenseDetails {
                accepted_schemas = validSchema, software_statement = validStatement
            };
            var response = _controller.CreateNew(licenseDetails);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
            _agreementService.Verify(i => i.Add(It.IsAny <LicenseAgreement>()));
            _schemaFileService.Verify(i => i.Get(It.IsAny <Expression <Func <SchemaFile, bool> > >()));
            _legalOfficerNotificationService.Verify(
                i => i.LicenseAgreementCreatedInBackground(0, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));
        }
        public void ShouldFailCreateNewLicenseAgreement_ForInvalidConsumer()
        {
            _applicationService.Setup(i => i.Get(It.IsAny <Expression <Func <Application, bool> > >()))
            .Returns(new List <Application>());
            var controller = GetNewControllerObject();

            licenseDetails = new LicenseDetails {
                accepted_schemas = validSchema, software_statement = validStatement
            };
            var response = controller.CreateNew(licenseDetails);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.BadRequest);
        }
        public void ValidateShouldSetValidLicenses()
        {
            var firstLicenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var secondLicenseDetails = new LicenseDetails
            {
                Id   = 2,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var firstLicense  = "1-mKwoA4cwRkRKioJ70fh6WcL5Ty+K2Kn32oftC2KFqw5kimAMYrTeKwOX25e55GcTMy/cB8Ssa/SJmFFq6OUSXpgc7TsG6vNA7jE8lYbpzQcaIumX9tu0Kr2655zUne0GcPP0 + Y6OqLnRnOiq5keErGSyohcfZmzkRXoHAEEXR68xOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkZ1bGw6TXlUZXN0ZWQuQXNwTmV0Q29yZS5NdmMu";
            var secondLicense = "2-dO7yyeqUFb2FRmtqqZbB+fYAThKkGftht8Ky7PB0Gi1GxW2ZlROg1a+fZjJnzBxEgBSup0rSxt4n73zKmcTv4SYrR9r0DtnWxX8DN8BLDk9hX1 + whB5UMYiQmf / uxDizUWn9pxdbMRrq9JXfxyRhOS4vxVhGIEPgH03vZsCWLOwyOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkZ1bGw6TXlUZXN0ZWQuQXNwTmV0Q29yZS5NdmMu";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new[] { firstLicense, secondLicense }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredFirstLicense  = LicenseValidator.GetLicenseDetails().FirstOrDefault();
            var registeredSecondLicense = LicenseValidator.GetLicenseDetails().LastOrDefault();

            Assert.NotNull(registeredFirstLicense);
            Assert.Equal(firstLicenseDetails.Id, registeredFirstLicense.Id);
            Assert.Equal(firstLicenseDetails.Type, registeredFirstLicense.Type);
            Assert.Equal(firstLicenseDetails.User, registeredFirstLicense.User);
            Assert.Equal(firstLicenseDetails.InformationDetails, registeredFirstLicense.InformationDetails);
            Assert.Equal(firstLicenseDetails.ExpiryDate, registeredFirstLicense.ExpiryDate);
            Assert.Equal(firstLicenseDetails.NamespacePrefix, registeredFirstLicense.NamespacePrefix);

            Assert.NotNull(registeredSecondLicense);
            Assert.Equal(secondLicenseDetails.Id, registeredSecondLicense.Id);
            Assert.Equal(secondLicenseDetails.Type, registeredSecondLicense.Type);
            Assert.Equal(secondLicenseDetails.User, registeredSecondLicense.User);
            Assert.Equal(secondLicenseDetails.InformationDetails, registeredSecondLicense.InformationDetails);
            Assert.Equal(secondLicenseDetails.ExpiryDate, registeredSecondLicense.ExpiryDate);
            Assert.Equal(secondLicenseDetails.NamespacePrefix, registeredSecondLicense.NamespacePrefix);
        }
        public void ValidateShouldSetValidLicenses()
        {
            var firstLicenseDetails = new LicenseDetails
            {
                Id   = 1,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var secondLicenseDetails = new LicenseDetails
            {
                Id   = 2,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate         = new DateTime(2017, 10, 15),
                NamespacePrefix    = "MyTested.AspNetCore.Mvc."
            };

            var firstLicense  = "1-rXDHzH/rR8IN83Qmtpyf8vsAd4cPfSd/roXjngSxf12fuEY5+nk/evBTOD3xcOQSrEQLte3BcpH/RxIxDaSmZU11zV4jafnJ4N0u+yfNmTvRhVAtGuVCPj1UgYva64QK5fsPbOXBXq1c9+ccfWoWuB7nuRPaJvUlv/dcHQAy3cUxOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy4=";
            var secondLicense = "2-3Fok2mhB7/S/wX7fpMi0PlwWUzaxWKbfy+EGlDE16wZJPOystX0e5xG3JYkVLuUT5uNw6+D+WhTJNjuHAXilFR/rr9lkOdei/9AVhnH5OeARQ1Ekr0ZM+sPjy/SwCpBEU48GLdSWH7V1MBK290XZHGa0c51YDZMjbA6IeBVRPlAyOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy4=";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new[] { firstLicense, secondLicense }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredFirstLicense  = LicenseValidator.GetLicenseDetails().FirstOrDefault();
            var registeredSecondLicense = LicenseValidator.GetLicenseDetails().LastOrDefault();

            Assert.NotNull(registeredFirstLicense);
            Assert.Equal(firstLicenseDetails.Id, registeredFirstLicense.Id);
            Assert.Equal(firstLicenseDetails.Type, registeredFirstLicense.Type);
            Assert.Equal(firstLicenseDetails.User, registeredFirstLicense.User);
            Assert.Equal(firstLicenseDetails.InformationDetails, registeredFirstLicense.InformationDetails);
            Assert.Equal(firstLicenseDetails.ExpiryDate, registeredFirstLicense.ExpiryDate);
            Assert.Equal(firstLicenseDetails.NamespacePrefix, registeredFirstLicense.NamespacePrefix);

            Assert.NotNull(registeredSecondLicense);
            Assert.Equal(secondLicenseDetails.Id, registeredSecondLicense.Id);
            Assert.Equal(secondLicenseDetails.Type, registeredSecondLicense.Type);
            Assert.Equal(secondLicenseDetails.User, registeredSecondLicense.User);
            Assert.Equal(secondLicenseDetails.InformationDetails, registeredSecondLicense.InformationDetails);
            Assert.Equal(secondLicenseDetails.ExpiryDate, registeredSecondLicense.ExpiryDate);
            Assert.Equal(secondLicenseDetails.NamespacePrefix, registeredSecondLicense.NamespacePrefix);
        }
        public void LicenseValidation()
        {
            LicenseDetails license = new LicenseDetails
            {
                Id         = 1001,
                ExpiryDate = new DateTime(2016, 12, 27, 0, 0, 0, DateTimeKind.Utc),
                Type       = LicenseType.Test
            };

            string licenseText = "1001-N70qM5lisTgmXINQXrhM7jfbLxMs0Rkq8nF5V10yf4OMjSZQyI/IR8Oz9hfIyEs5hSzI8eX8dFb1KcKsMySTuQ/wHU6EKX6SzsBHzbOSxHhjR5XuBFUznGM+u1FyK7hGOxsyRZgBDS2rClcD/9bfn7SgitQU4nd1fGXnnQK1s5h7IklkIjoxMDAxLCJFeHBpcnlEYXRlIjoiMjAxNi0xMi0yN1QwMDowMDowMFoiLCJUeXBlIjoiVGVzdCJ9";

            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 26, 0, 0, 0, DateTimeKind.Utc)), "Specified license is for testing only.");
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 27, 0, 0, 0, DateTimeKind.Utc)), "Specified license is for testing only.");
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 28, 0, 0, 0, DateTimeKind.Utc)), "License is not valid for this version of Json.NET Schema. License expired on 2016-12-27. This version of Json.NET Schema was released on 2016-12-28.");

            licenseText = "1001-BADqM5lisTgmXINQXrhM7jfbLxMs0Rkq8nF5V10yf4OMjSZQyI/IR8Oz9hfIyEs5hSzI8eX8dFb1KcKsMySTuQ/wHU6EKX6SzsBHzbOSxHhjR5XuBFUznGM+u1FyK7hGOxsyRZgBDS2rClcD/9bfn7SgitQU4nd1fGXnnQK1s5h7IklkIjoxMDAxLCJFeHBpcnlEYXRlIjoiMjAxNi0xMi0yN1QwMDowMDowMFoiLCJUeXBlIjoiVGVzdCJ9";
            ExceptionAssert.Throws <JSchemaException>(() => LicenseHelpers.RegisterLicense(licenseText, new DateTime(2016, 12, 27, 0, 0, 0, DateTimeKind.Utc)), "License text does not match signature.");
        }
        public void ShouldNotCreateNewLicenseAgreement_IfAlreadyExists()
        {
            _agreementService.Setup(
                i => i.GetAgreementsForLicenseAndSchema(schema.ID, organizationLicense.ID, organizationLicense.ID))
            .Returns(new List <LicenseAgreement> {
                new LicenseAgreement()
            });
            var controller = GetNewControllerObject();

            licenseDetails = new LicenseDetails {
                accepted_schemas = validSchema, software_statement = validStatement
            };
            var response = controller.CreateNew(licenseDetails);

            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);
            _agreementService.Verify(
                i => i.GetAgreementsForLicenseAndSchema(schema.ID, organizationLicense.ID, organizationLicense.ID));
        }
Example #30
0
        public string GenerateSignedXml(LicenseDetails details)
        {
            if (details == null)
                throw new ArgumentNullException("details");

            string rawXml;
            var serializer = new XmlSerializer(typeof (LicenseDetails));
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, details);
                stream.Position = 0;

                using (var streamReader = new StreamReader(stream))
                    rawXml = streamReader.ReadToEnd();
            }

            // Sign the xml
            var doc = new XmlDocument();
            TextReader reader = new StringReader(rawXml);
            doc.Load(reader);
            var signedXml = new SignedXml(doc);
            signedXml.SigningKey = _key;

            var reference = new Reference { Uri = "" };
            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            signedXml.AddReference(reference);

            signedXml.ComputeSignature();
            var signature = signedXml.GetXml();
            if (doc.DocumentElement != null)
                doc.DocumentElement.AppendChild(doc.ImportNode(signature, true));

            if (doc.FirstChild is XmlDeclaration)
                doc.RemoveChild(doc.FirstChild);

            // Return the resulting xml
            using (var stringWriter = new StringWriter())
            using (var xmlTextWriter = XmlWriter.Create(stringWriter))
            {
                doc.WriteTo(xmlTextWriter);
                xmlTextWriter.Flush();
                return stringWriter.GetStringBuilder().ToString();
            }
        }
        /// <summary>
        /// Install the license file
        /// </summary>
        /// <param name="fpath">The path to the license file to install</param>
        public static void InstallLicense(string fpath)
        {
            LicenseDetails lic = null;

            try
            {
                lic = DecodeLicense(fpath);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("license string is invalid");
            } // catch

            // In case we are dealing with an evaluation license - make sure that we can
            // evaluate
            if (lic.Usage == LicenseUsage.Demo && !OkForEvaluation(lic))
            {
                throw new ApplicationException("evaluation license has expired");
            }

            string lpath = Utils.GetLicenseFilePath();

            if (Path.GetFullPath(lpath) != Path.GetFullPath(fpath))
            {
                // Rename the old license file (if exists)
                if (File.Exists(lpath))
                {
                    int index = 1;
                    while (File.Exists(lpath + "_" + index + ".bak"))
                    {
                        index++;
                    }
                    File.Move(lpath, lpath + "_" + index + ".bak");
                }

                // Copy the new license file to its location
                File.Copy(fpath, lpath);
            } // if

            // Read the license file
            _license = DecodeLicense(lpath);
        }
Example #32
0
        private LicenseAgreement CreateAgreementIfNotExists(LicenseDetails licenseDetails, Application consumerApp,
                                                            DataSchema schema, string schemaPublicId, Application providerApp)
        {
            // Get published provider license
            var publishedProviderLicense =
                _organisationLicenses.Where(i => i.ApplicationID == providerApp.ID).Where(i => i.DataSchemaID == schema.ID && i.Status == (int)PublishStatus.Published).FirstOrDefault();

            if (publishedProviderLicense == null)
            {
                // Return error if provider does not have published license
                throw new BaseApiException($"Published data agreement from provider for schema '{schemaPublicId}' not found");
            }
            // Get published consumer license
            var consumerRequests = _consumerRegistrationRequests.Where(i => i.ConsumerApplicationID == consumerApp.ID)
                                   .Where(i => i.Status == (int)ConsumerProviderRegistrationStatus.Approved);

            var consumerProviderRequest = GetRequestThatForProvider(consumerRequests, schema.ID, providerApp.ID);

            if (consumerProviderRequest == null)
            {
                // Return error if consumer does not have approved request
                var errorMessage = $" {consumerApp.Name} has not been approved by {providerApp.Name} to access {schema.PublicID}.";
            }

            // Check if this record already exists - try to get license agreement
            var existingAgreement = _licenseAgreements.FirstOrDefault(i => i.ConsumerProviderRegistrationId == consumerProviderRequest.ID);

            // If agreement with these licenses already exists - do not create
            if (existingAgreement != null)
            {
                return(null);
            }
            // Setup new details for license agreement
            var agreement = new LicenseAgreement
            {
                ConsumerProviderRegistrationId = consumerProviderRequest.ID,
                CreatedAt         = GetDate,
                SoftwareStatement = licenseDetails.software_statement
            };

            return(agreement);
        }
        public HttpResponseMessage CreateNew([FromBody] LicenseDetails licenseDetails)
        {
            try
            {
                Log.Info($"Create license agreement [Begin]: licenseDetails - {JsonConvert.SerializeObject(licenseDetails)}");
                _softwareStatementService.CreateLicenseAgreement(licenseDetails, LoggedInApplication);

                Log.Info("Create license agreement [End]");
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (BaseApiException ex)
            {
                Log.Info(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        public void ValidateShouldSetValidLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id = 1,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var license = "1-rXDHzH/rR8IN83Qmtpyf8vsAd4cPfSd/roXjngSxf12fuEY5+nk/evBTOD3xcOQSrEQLte3BcpH/RxIxDaSmZU11zV4jafnJ4N0u+yfNmTvRhVAtGuVCPj1UgYva64QK5fsPbOXBXq1c9+ccfWoWuB7nuRPaJvUlv/dcHQAy3cUxOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy4=";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new []{ license }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();

            Assert.NotNull(registeredLicense);
            Assert.Equal(licenseDetails.Id, registeredLicense.Id);
            Assert.Equal(licenseDetails.Type, registeredLicense.Type);
            Assert.Equal(licenseDetails.User, registeredLicense.User);
            Assert.Equal(licenseDetails.InformationDetails, registeredLicense.InformationDetails);
            Assert.Equal(licenseDetails.ExpiryDate, registeredLicense.ExpiryDate);
            Assert.Equal(licenseDetails.NamespacePrefix, registeredLicense.NamespacePrefix);
        }
        public void ValidateShouldSetValidLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id = 1,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var license = "1-mKwoA4cwRkRKioJ70fh6WcL5Ty+K2Kn32oftC2KFqw5kimAMYrTeKwOX25e55GcTMy/cB8Ssa/SJmFFq6OUSXpgc7TsG6vNA7jE8lYbpzQcaIumX9tu0Kr2655zUne0GcPP0 + Y6OqLnRnOiq5keErGSyohcfZmzkRXoHAEEXR68xOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkZ1bGw6TXlUZXN0ZWQuQXNwTmV0Q29yZS5NdmMu";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new []{ license }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();

            Assert.NotNull(registeredLicense);
            Assert.Equal(licenseDetails.Id, registeredLicense.Id);
            Assert.Equal(licenseDetails.Type, registeredLicense.Type);
            Assert.Equal(licenseDetails.User, registeredLicense.User);
            Assert.Equal(licenseDetails.InformationDetails, registeredLicense.InformationDetails);
            Assert.Equal(licenseDetails.ExpiryDate, registeredLicense.ExpiryDate);
            Assert.Equal(licenseDetails.NamespacePrefix, registeredLicense.NamespacePrefix);
        }
        public void ValidateShouldSetValidLicenses()
        {
            var firstLicenseDetails = new LicenseDetails
            {
                Id = 1,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var secondLicenseDetails = new LicenseDetails
            {
                Id = 2,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var firstLicense = "1-mKwoA4cwRkRKioJ70fh6WcL5Ty+K2Kn32oftC2KFqw5kimAMYrTeKwOX25e55GcTMy/cB8Ssa/SJmFFq6OUSXpgc7TsG6vNA7jE8lYbpzQcaIumX9tu0Kr2655zUne0GcPP0 + Y6OqLnRnOiq5keErGSyohcfZmzkRXoHAEEXR68xOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkZ1bGw6TXlUZXN0ZWQuQXNwTmV0Q29yZS5NdmMu";
            var secondLicense = "2-dO7yyeqUFb2FRmtqqZbB+fYAThKkGftht8Ky7PB0Gi1GxW2ZlROg1a+fZjJnzBxEgBSup0rSxt4n73zKmcTv4SYrR9r0DtnWxX8DN8BLDk9hX1 + whB5UMYiQmf / uxDizUWn9pxdbMRrq9JXfxyRhOS4vxVhGIEPgH03vZsCWLOwyOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkZ1bGw6TXlUZXN0ZWQuQXNwTmV0Q29yZS5NdmMu";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new[] { firstLicense, secondLicense }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredFirstLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();
            var registeredSecondLicense = LicenseValidator.GetLicenseDetails().LastOrDefault();

            Assert.NotNull(registeredFirstLicense);
            Assert.Equal(firstLicenseDetails.Id, registeredFirstLicense.Id);
            Assert.Equal(firstLicenseDetails.Type, registeredFirstLicense.Type);
            Assert.Equal(firstLicenseDetails.User, registeredFirstLicense.User);
            Assert.Equal(firstLicenseDetails.InformationDetails, registeredFirstLicense.InformationDetails);
            Assert.Equal(firstLicenseDetails.ExpiryDate, registeredFirstLicense.ExpiryDate);
            Assert.Equal(firstLicenseDetails.NamespacePrefix, registeredFirstLicense.NamespacePrefix);

            Assert.NotNull(registeredSecondLicense);
            Assert.Equal(secondLicenseDetails.Id, registeredSecondLicense.Id);
            Assert.Equal(secondLicenseDetails.Type, registeredSecondLicense.Type);
            Assert.Equal(secondLicenseDetails.User, registeredSecondLicense.User);
            Assert.Equal(secondLicenseDetails.InformationDetails, registeredSecondLicense.InformationDetails);
            Assert.Equal(secondLicenseDetails.ExpiryDate, registeredSecondLicense.ExpiryDate);
            Assert.Equal(secondLicenseDetails.NamespacePrefix, registeredSecondLicense.NamespacePrefix);
        }
        public void PublicKeyShouldNotBeEnoughToForgeLicense()
        {
            var licenseDetails = new LicenseDetails
            {
                Id = 1,
                Type = LicenseType.Full,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var licenseDetailsAsBytes = licenseDetails.GetSignificateData();

            var cryptoProvider = new RSACryptoServiceProvider(1024)
            {
                PersistKeyInCsp = false
            };

            cryptoProvider.ImportCspBlob(Convert.FromBase64String("BgIAAACkAABSU0ExAAQAAAEAAQD5Hv5iOBm7GKs7GRQBwlYlbNsJZOL8PfX+rQuKK+tO4JquMo0ScaQiz4duyfjp1/dsrNAsRnRoDfIvaL75YYezaEaoRXldI83CjDPU92chrLUkaQdFtY1XyiBt6lJREkD6LBSRSJD9Z9Aeaqssl8fbaJpTk5wppIImhEvHrJ3F6g=="));

            Exception caughtException = null;

            try
            {
                cryptoProvider.SignData(licenseDetailsAsBytes, SHA1.Create());
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.NotNull(caughtException);
            Assert.IsAssignableFrom<CryptographicException>(caughtException);
        }
        public void ValidateShouldSetValidLicenses()
        {
            var firstLicenseDetails = new LicenseDetails
            {
                Id = 1,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var secondLicenseDetails = new LicenseDetails
            {
                Id = 2,
                Type = LicenseType.Developer,
                User = "******",
                InformationDetails = "MyTested.AspNetCore.Mvc Tests",
                ExpiryDate = new DateTime(2017, 10, 15),
                NamespacePrefix = "MyTested.AspNetCore.Mvc."
            };

            var firstLicense = "1-rXDHzH/rR8IN83Qmtpyf8vsAd4cPfSd/roXjngSxf12fuEY5+nk/evBTOD3xcOQSrEQLte3BcpH/RxIxDaSmZU11zV4jafnJ4N0u+yfNmTvRhVAtGuVCPj1UgYva64QK5fsPbOXBXq1c9+ccfWoWuB7nuRPaJvUlv/dcHQAy3cUxOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy4=";
            var secondLicense = "2-3Fok2mhB7/S/wX7fpMi0PlwWUzaxWKbfy+EGlDE16wZJPOystX0e5xG3JYkVLuUT5uNw6+D+WhTJNjuHAXilFR/rr9lkOdei/9AVhnH5OeARQ1Ekr0ZM+sPjy/SwCpBEU48GLdSWH7V1MBK290XZHGa0c51YDZMjbA6IeBVRPlAyOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok15VGVzdGVkLkFzcE5ldENvcmUuTXZjIFRlc3RzOkRldmVsb3BlcjpNeVRlc3RlZC5Bc3BOZXRDb3JlLk12Yy4=";

            LicenseValidator.ClearLicenseDetails();
            LicenseValidator.Validate(new[] { firstLicense, secondLicense }, new DateTime(2016, 10, 10), "MyTested.AspNetCore.Mvc.Tests");

            Assert.True(LicenseValidator.HasValidLicense);

            var registeredFirstLicense = LicenseValidator.GetLicenseDetails().FirstOrDefault();
            var registeredSecondLicense = LicenseValidator.GetLicenseDetails().LastOrDefault();

            Assert.NotNull(registeredFirstLicense);
            Assert.Equal(firstLicenseDetails.Id, registeredFirstLicense.Id);
            Assert.Equal(firstLicenseDetails.Type, registeredFirstLicense.Type);
            Assert.Equal(firstLicenseDetails.User, registeredFirstLicense.User);
            Assert.Equal(firstLicenseDetails.InformationDetails, registeredFirstLicense.InformationDetails);
            Assert.Equal(firstLicenseDetails.ExpiryDate, registeredFirstLicense.ExpiryDate);
            Assert.Equal(firstLicenseDetails.NamespacePrefix, registeredFirstLicense.NamespacePrefix);

            Assert.NotNull(registeredSecondLicense);
            Assert.Equal(secondLicenseDetails.Id, registeredSecondLicense.Id);
            Assert.Equal(secondLicenseDetails.Type, registeredSecondLicense.Type);
            Assert.Equal(secondLicenseDetails.User, registeredSecondLicense.User);
            Assert.Equal(secondLicenseDetails.InformationDetails, registeredSecondLicense.InformationDetails);
            Assert.Equal(secondLicenseDetails.ExpiryDate, registeredSecondLicense.ExpiryDate);
            Assert.Equal(secondLicenseDetails.NamespacePrefix, registeredSecondLicense.NamespacePrefix);
        }