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"); }
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); }
public void GeneratedXmlCanBeValidated() { // Setup var license = CreateLicenseDetail(); var key = new RSACryptoServiceProvider(1024); var xml = new LicenseGenerator(key).GenerateSignedXml(license); // Test var validator = new LicenseValidator(key); var validatedLicense = validator.ValidateLicenseXml(xml); // Verify Assert.IsNotNull(validatedLicense, "Validated license was null"); Assert.IsTrue(license.Equals(validatedLicense), "Validated license did not match original license"); }
public void GeneratedXmlIsCorrectlySigned() { var key = new RSACryptoServiceProvider(); var generator = new LicenseGenerator(key); var rawXml = generator.GenerateSignedXml(new LicenseDetails()); var doc = new XmlDocument(); TextReader reader = new StringReader(rawXml); doc.Load(reader); var signedXml = new SignedXml(doc); var nodeList = doc.GetElementsByTagName("Signature"); signedXml.LoadXml((XmlElement)nodeList[0]); var result = signedXml.CheckSignature(key); Assert.IsTrue(result, "Verification of xml signature failed"); }
public void ExceptionThrownWhenNullLicenseDetailsPassedIn() { var key = new RSACryptoServiceProvider(); var generator = new LicenseGenerator(key); generator.GenerateSignedXml(null); }