public void TestVerifySignatureFailure2() { //First sign sm = new SignatureManager(); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); XmlNamespaceManager nsMgr = new XmlNamespaceManager(signed.OwnerDocument.NameTable); nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); //get the Digest value XmlNode digValueNode = signed.SelectSingleNode("ds:SignedInfo/ds:Reference/ds:DigestValue", nsMgr); string digest = digValueNode.InnerXml; //Tamper it. digest = digest.ToUpper(); signed.SelectSingleNode("ds:SignedInfo/ds:Reference/ds:DigestValue", nsMgr).InnerXml = digest; //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TestVerifySignatureFailure1() { //First sign sm = new SignatureManager(); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //get the SignatureValue XmlNode sigValueNode = signed.SelectSingleNode("SignatureValue"); string signature = sigValueNode.InnerXml; //Tamper it. signature = signature.ToUpper(); signed.SelectSingleNode("SignatureValue").InnerXml = signature; //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TestConstructor2() { ProcessRegistry pr = new ProcessRegistry(SHA256Namespace); sm = new SignatureManager(pr); Assert.IsNotNull(sm, "SignatureManager instance is null"); Assert.IsTrue(sm is SignatureManager, "SignatureManager instance has wrong type"); }
public void TestSign() { sm = new SignatureManager(); XmlNode res = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Verify if the Signature node is well formed Assert.AreEqual(res.Name, "Signature", "Root Node is malformed"); Assert.AreEqual(res.NamespaceURI, "http://www.w3.org/2000/09/xmldsig#", "Root attribute collection has no default namespace"); Assert.AreEqual(res.Attributes.GetNamedItem("Id").Value, "myFirstSign", "Id attribute is incorrect"); //Other checks for well formed output are done by VerifySignature method }
public void TestSign() { sm = new SignatureManager(); XmlNode res = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Verify if the Signature node is well formed Assert.AreEqual(res.Name, "Signature", "Root Node is malformed"); Assert.AreEqual(res.Attributes.Count, 2, "Root attribute collection has incorrect count"); Assert.AreEqual(res.Attributes[0].Name, "xmlns", "Root attribute collection has no xmlns attribute"); Assert.AreEqual(res.Attributes.GetNamedItem("Id").Value, "myFirstSign", "Id attribute is incorrect"); //Other checks for well formed output are done by VerifySignature method }
public void TearDown() { sm = null; transformersList1 = null; digester1 = null; reference1 = null; references = null; c14nParams = null; c14nIVO = null; dsa = null; signerParams = null; signerIVO = null; digesterMain = null; }
public void TheDemo() { //Setup References IList <InstantiationVO> transformersList1 = new List <InstantiationVO>(); InstantiationVO digester1 = new InstantiationVO("http://www.w3.org/2000/09/xmldsig#sha1", new Dictionary <string, object>()); IReference reference1 = new Reference("http://www.google.com", transformersList1, digester1, "http"); IList <IReference> references = new List <IReference>(); references.Add(reference1); //Setup Canonicalizer IDictionary <string, object> c14nParams = new Dictionary <string, object>(); InstantiationVO c14nIVO = new InstantiationVO("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", c14nParams); //Setup Signers DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); DSAParameters dsaParams = dsa.ExportParameters(true); IDictionary <string, object> signerParams = new Dictionary <string, object>(); signerParams.Add("DSAKeyInfo", dsaParams); InstantiationVO signerIVO = new InstantiationVO("xml:dig:signer:rsa-dsa", signerParams); //Setup main digester InstantiationVO digesterMain = new InstantiationVO("http://www.w3.org/2000/09/xmldsig#sha1", new Dictionary <string, object>()); SignatureManager sm = new SignatureManager(); //Sign the references XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TestVerifySignature() { //First sign sm = new SignatureManager(SHA256Namespace); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters DSAParameters verificationDSAParams = dsa.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify. Note that if no exception is thrown here then verification was successful. //No assert would be required. sm.VerifySignature(signed, keyInfoProvider); }
public void TestVerifySignatureFailure3() { //First sign sm = new SignatureManager(); XmlNode signed = sm.Sign(references, c14nIVO, signerIVO, "myFirstSign"); //Now verify the XmlSignature using the VerifySignature method exposed by the SignatureManager class IDictionary <string, object> keyInfoProviderParams = new Dictionary <string, object>(); //Note here the use of false only exports the public key to the DSA parameters //Note that new instance of DSACryptoServiceProvider creates a different public key than //the one that was used for signing DSACryptoServiceProvider dsa1 = new DSACryptoServiceProvider(); DSAParameters verificationDSAParams = dsa1.ExportParameters(false); //Set the Public Key of the KeyInfoProvider class keyInfoProviderParams.Add("PublicKey", verificationDSAParams); //Create Instantiation VO for KeyInfoProvider InstantiationVO keyInfoProvider = new InstantiationVO("testKeyInfoProvider", keyInfoProviderParams); //Verify sm.VerifySignature(signed, keyInfoProvider); }
public void TestSignFail1() { sm = new SignatureManager(); sm.Sign(references, c14nIVO, null, "myFirstSign"); }
public void TestConstructor2() { sm = new SignatureManager("MyNamespace"); }
public void TestConstructor1() { sm = new SignatureManager(SHA256Namespace); Assert.IsNotNull(sm, "SignatureManager instance is null"); Assert.IsTrue(sm is SignatureManager, "SignatureManager instance has wrong type"); }
public void TestConstructor3() { string s = null; sm = new SignatureManager(s); }
public void TestConstructor4() { string s = String.Empty; sm = new SignatureManager(s); }
public void TestSignFail3() { sm = new SignatureManager(); signerIVO = new InstantiationVO("nonExistantSignerKey", signerParams); sm.Sign(references, c14nIVO, signerIVO, "myId"); }
public void TestSignFail2() { sm = new SignatureManager(); sm.Sign(references, c14nIVO, signerIVO, null); }
public void TestConstructor6() { ProcessRegistry pr = null; sm = new SignatureManager(pr); }
public void TestConstructor8() { ProcessRegistry pr = new ProcessRegistry(); sm = new SignatureManager("aNonExistantNamespace"); }