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()); }
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()); }
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) { } }
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); }