Exemplo n.º 1
0
        public void TestInitialization_WithProperties()
        {
            var file = new SignedLicense("HardwareID", "SerialNumber", DateTime.Now, DateTime.Now + TimeSpan.FromDays(10), CreateProperties());

            AssertDefaultPropertiesAreValid(file);
            AssertPropertiesAreValid(file);
        }
        SignedLicense IBuilder_Properties.SignAndCreate()
        {
            var license = new SignedLicense(myHardwareIdentifier, mySerialNumber, DateTime.Now, myExpirationDate, myProperties);

            license.Sign(mySigner);
            return(license);
        }
Exemplo n.º 3
0
        public void TestInitialization()
        {
            var file = new SignedLicense("HardwareID", "SerialNumber", DateTime.Now, DateTime.Now + TimeSpan.FromDays(10), null);

            AssertDefaultPropertiesAreValid(file);
            Assert.AreEqual(0, file.Properties.Count);
        }
Exemplo n.º 4
0
        public void TestInitialization_WithProperties_WithColone()
        {
            var properties = new Dictionary <string, string>();

            properties.Add("Pro:p1", "Val1");
            properties.Add("Prop2", "Val2");
            try
            {
                var file = new SignedLicense("HardwareID", "SerialNumber", DateTime.Now, DateTime.Now + TimeSpan.FromDays(10), properties);
                Assert.Fail("FormatException expected.");
            }
            catch (FormatException) { }
        }
Exemplo n.º 5
0
        public void TestSerialization()
        {
            var license = new SignedLicense(HardwareIdentifier.NoHardwareIdentifier, "SerialNumber", DateTime.Now, DateTime.Now + TimeSpan.FromDays(10), CreateProperties());

            license.Sign(new LengthSigner());
            var licPlainText = license.SerializeAsPlainText();
            var licEncrypted = license.Serialize();

            var licensePlainText = SignedLicense.Deserialize(licPlainText);
            var licenseEncrypted = SignedLicense.Deserialize(licEncrypted);

            Assert.AreEqual(licensePlainText.SerializeAsPlainText(), licenseEncrypted.SerializeAsPlainText());
            Assert.AreEqual(licensePlainText.Serialize(), licenseEncrypted.Serialize());
        }
Exemplo n.º 6
0
        public void TestSigning_WithProperties_DifferentCultures()
        {
            var cultureDE = new CultureInfo("de");
            var cultureEN = new CultureInfo("en");


            Thread.CurrentThread.CurrentCulture = cultureDE;
            var file = new SignedLicense("HardwareID", "SerialNumber", DateTime.Now, DateTime.Now + TimeSpan.FromDays(10), CreateProperties());

            file.Sign(new HashCodeSigner());
            var content = file.Serialize();

            Thread.CurrentThread.CurrentCulture = cultureEN;
            var newFile = SignedLicense.Deserialize(content);

            newFile.Verify(new HashCodeSigner());
        }
Exemplo n.º 7
0
        public void TestSigning_WithProperties()
        {
            var file = new SignedLicense("HardwareID", "SerialNumber", DateTime.Now, DateTime.Now + TimeSpan.FromDays(10), CreateProperties());

            file.Sign(new LengthSigner());
            var content = file.Serialize();
            var newFile = SignedLicense.Deserialize(content);

            AssertDefaultPropertiesAreValid(newFile);
            AssertPropertiesAreValid(file);
            newFile.Verify(new LengthSigner());

            try
            {
                newFile.Verify(new DoubleLengthSigner());
                Assert.Fail("LicenseException expected");
            }
            catch (SignedLicenseException) { }
        }
Exemplo n.º 8
0
        SignedLicense IVerifier_VerifyLoad.LoadAndVerify(string licenseString)
        {
            var license = SignedLicense.Deserialize(licenseString);

            // verify signature
            license.Verify(mySigner);
            // verify application code
            if (!SerialNumber.IsApplicationCodeValid(license.SerialNumber, myApplicationCode))
            {
                throw new SignedLicenseException($"Application Code '{myApplicationCode}' is not valid for the license.");
            }
            // verify hardware identifier
            if (!HardwareIdentifier.IsValidForCurrentComputer(license.HardwareIdentifier))
            {
                throw new SignedLicenseException($"License has been activated for another computer.");
            }
            // verify expiration date
            if (license.ExpirationDate < DateTime.UtcNow)
            {
                throw new SignedLicenseException($"License has been expired since '{license.ExpirationDate}'.");
            }
            return(license);
        }
Exemplo n.º 9
0
 private static void AssertPropertiesAreValid(SignedLicense file)
 {
     Assert.AreEqual(2, file.Properties.Count);
     Assert.AreEqual("Val1", file.Properties["Prop1"]);
     Assert.AreEqual("Val2", file.Properties["Prop2"]);
 }
Exemplo n.º 10
0
 private static void AssertDefaultPropertiesAreValid(SignedLicense file)
 {
     Assert.AreEqual("HardwareID", file.HardwareIdentifier);
     Assert.AreEqual(DateTime.UtcNow.Date, file.IssueDate);
     Assert.AreEqual("SerialNumber", file.SerialNumber);
 }