SignedXmlTest.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. //
  2. // SignedXmlTest.cs - NUnit Test Cases for SignedXml
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. // (C) 2004 Novell (http://www.novell.com)
  9. //
  10. using System;
  11. using System.Security.Cryptography;
  12. using System.Security.Cryptography.Xml;
  13. using System.Text;
  14. using System.Xml;
  15. using NUnit.Framework;
  16. namespace MonoTests.System.Security.Cryptography.Xml {
  17. public class SignedXmlEx : SignedXml {
  18. // required to test protected GetPublicKey in SignedXml
  19. public AsymmetricAlgorithm PublicGetPublicKey ()
  20. {
  21. return base.GetPublicKey ();
  22. }
  23. }
  24. [TestFixture]
  25. public class SignedXmlTest : Assertion {
  26. private const string signature = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>CTnnhjxUQHJmD+t1MjVXrOW+MCA=</DigestValue></Reference></SignedInfo><SignatureValue>dbFt6Zw3vR+Xh7LbM/vuifyFA7gPh/NlDM2Glz/SJBsveISieuTBpZlk/zavAeuXR/Nu0Ztt4OP4tCOg09a2RNlrTP0dhkeEfL1jTzpnVaLHuQbCiwOWCgbRif7Xt7N12FuiHYb3BltP/YyXS4E12NxlGlqnDiFA1v/mkK5+C1o=</SignatureValue><KeyInfo><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>hEfTJNa2idz2u+fSYDDG4Lx/xuk4aBbvOPVNqgc1l9Y8t7Pt+ZyF+kkF3uUl8Y0700BFGAsprnhwrWENK+PGdtvM5796ZKxCCa0ooKkofiT4355HqK26hpV8dvj38vq/rkJe1jHZgkTKa+c/0vjcYZOI/RT/IZv9JfXxVWLuLxk=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><ObjectListTag xmlns=\"\" /></Object></Signature>";
  27. [Test]
  28. public void StaticValues ()
  29. {
  30. AssertEquals ("XmlDsigCanonicalizationUrl", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", SignedXml.XmlDsigCanonicalizationUrl);
  31. AssertEquals ("XmlDsigCanonicalizationWithCommentsUrl", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", SignedXml.XmlDsigCanonicalizationWithCommentsUrl);
  32. AssertEquals ("XmlDsigDSAUrl", "http://www.w3.org/2000/09/xmldsig#dsa-sha1", SignedXml.XmlDsigDSAUrl);
  33. AssertEquals ("XmlDsigHMACSHA1Url", "http://www.w3.org/2000/09/xmldsig#hmac-sha1", SignedXml.XmlDsigHMACSHA1Url);
  34. AssertEquals ("XmlDsigMinimalCanonicalizationUrl", "http://www.w3.org/2000/09/xmldsig#minimal", SignedXml.XmlDsigMinimalCanonicalizationUrl);
  35. AssertEquals ("XmlDsigNamespaceUrl", "http://www.w3.org/2000/09/xmldsig#", SignedXml.XmlDsigNamespaceUrl);
  36. AssertEquals ("XmlDsigRSASHA1Url", "http://www.w3.org/2000/09/xmldsig#rsa-sha1", SignedXml.XmlDsigRSASHA1Url);
  37. AssertEquals ("XmlDsigSHA1Url", "http://www.w3.org/2000/09/xmldsig#sha1", SignedXml.XmlDsigSHA1Url);
  38. }
  39. [Test]
  40. public void Constructor_Empty ()
  41. {
  42. XmlDocument doc = new XmlDocument ();
  43. doc.LoadXml (signature);
  44. XmlNodeList xnl = doc.GetElementsByTagName ("Signature", SignedXml.XmlDsigNamespaceUrl);
  45. XmlElement xel = (XmlElement) xnl [0];
  46. SignedXml sx = new SignedXml (doc);
  47. sx.LoadXml (xel);
  48. Assert ("CheckSignature", sx.CheckSignature ());
  49. }
  50. [Test]
  51. public void Constructor_XmlDocument ()
  52. {
  53. XmlDocument doc = new XmlDocument ();
  54. doc.LoadXml (signature);
  55. XmlNodeList xnl = doc.GetElementsByTagName ("Signature", SignedXml.XmlDsigNamespaceUrl);
  56. XmlElement xel = (XmlElement) xnl [0];
  57. SignedXml sx = new SignedXml (doc);
  58. sx.LoadXml (doc.DocumentElement);
  59. Assert ("CheckSignature", sx.CheckSignature ());
  60. }
  61. [Test]
  62. [ExpectedException (typeof (ArgumentNullException))]
  63. public void Constructor_XmlDocument_Null ()
  64. {
  65. XmlDocument doc = null;
  66. SignedXml sx = new SignedXml (doc);
  67. }
  68. [Test]
  69. public void Constructor_XmlElement ()
  70. {
  71. XmlDocument doc = new XmlDocument ();
  72. doc.LoadXml (signature);
  73. XmlNodeList xnl = doc.GetElementsByTagName ("Signature", SignedXml.XmlDsigNamespaceUrl);
  74. XmlElement xel = (XmlElement) xnl [0];
  75. SignedXml sx = new SignedXml (doc.DocumentElement);
  76. sx.LoadXml (xel);
  77. Assert ("CheckSignature", sx.CheckSignature ());
  78. }
  79. [Test]
  80. [ExpectedException (typeof (CryptographicException))]
  81. public void Constructor_XmlElement_WithoutLoadXml ()
  82. {
  83. XmlDocument doc = new XmlDocument ();
  84. doc.LoadXml (signature);
  85. XmlNodeList xnl = doc.GetElementsByTagName ("Signature", SignedXml.XmlDsigNamespaceUrl);
  86. XmlElement xel = (XmlElement) xnl [0];
  87. SignedXml sx = new SignedXml (doc.DocumentElement);
  88. Assert ("!CheckSignature", sx.CheckSignature ());
  89. // SignedXml (XmlElement) != SignedXml () + LoadXml (XmlElement)
  90. }
  91. [Test]
  92. [ExpectedException (typeof (ArgumentNullException))]
  93. public void Constructor_XmlElement_Null ()
  94. {
  95. XmlElement xel = null;
  96. SignedXml sx = new SignedXml (xel);
  97. }
  98. // sample from MSDN (url)
  99. public SignedXml MSDNSample ()
  100. {
  101. // Create example data to sign.
  102. XmlDocument document = new XmlDocument ();
  103. XmlNode node = document.CreateNode (XmlNodeType.Element, "", "MyElement", "samples");
  104. node.InnerText = "This is some text";
  105. document.AppendChild (node);
  106. // Create the SignedXml message.
  107. SignedXml signedXml = new SignedXml ();
  108. // Create a data object to hold the data to sign.
  109. DataObject dataObject = new DataObject ();
  110. dataObject.Data = document.ChildNodes;
  111. dataObject.Id = "MyObjectId";
  112. // Add the data object to the signature.
  113. signedXml.AddObject (dataObject);
  114. // Create a reference to be able to package everything into the
  115. // message.
  116. Reference reference = new Reference ();
  117. reference.Uri = "#MyObjectId";
  118. // Add it to the message.
  119. signedXml.AddReference (reference);
  120. return signedXml;
  121. }
  122. [Test]
  123. public void AsymmetricRSASignature ()
  124. {
  125. SignedXml signedXml = MSDNSample ();
  126. RSA key = RSA.Create ();
  127. signedXml.SigningKey = key;
  128. // Add a KeyInfo.
  129. KeyInfo keyInfo = new KeyInfo ();
  130. keyInfo.AddClause (new RSAKeyValue (key));
  131. signedXml.KeyInfo = keyInfo;
  132. AssertEquals ("KeyInfo", 1, signedXml.KeyInfo.Count);
  133. AssertNull ("SignatureLength", signedXml.SignatureLength);
  134. AssertNull ("SignatureMethod", signedXml.SignatureMethod);
  135. AssertNull ("SignatureValue", signedXml.SignatureValue);
  136. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  137. // Compute the signature.
  138. signedXml.ComputeSignature ();
  139. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  140. AssertEquals ("SignatureMethod", SignedXml.XmlDsigRSASHA1Url, signedXml.SignatureMethod);
  141. AssertEquals ("SignatureValue", 128, signedXml.SignatureValue.Length);
  142. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  143. // Get the XML representation of the signature.
  144. XmlElement xmlSignature = signedXml.GetXml ();
  145. // LAMESPEC: we must reload the signature or it won't work
  146. // MS framework throw a "malformed element"
  147. SignedXml vrfy = new SignedXml ();
  148. vrfy.LoadXml (xmlSignature);
  149. // assert that we can verify our own signature
  150. Assert ("RSA-Compute/Verify", vrfy.CheckSignature ());
  151. }
  152. [Test]
  153. public void AsymmetricDSASignature ()
  154. {
  155. SignedXml signedXml = MSDNSample ();
  156. DSA key = DSA.Create ();
  157. signedXml.SigningKey = key;
  158. // Add a KeyInfo.
  159. KeyInfo keyInfo = new KeyInfo ();
  160. keyInfo.AddClause (new DSAKeyValue (key));
  161. signedXml.KeyInfo = keyInfo;
  162. AssertEquals ("KeyInfo", 1, signedXml.KeyInfo.Count);
  163. AssertNull ("SignatureLength", signedXml.SignatureLength);
  164. AssertNull ("SignatureMethod", signedXml.SignatureMethod);
  165. AssertNull ("SignatureValue", signedXml.SignatureValue);
  166. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  167. // Compute the signature.
  168. signedXml.ComputeSignature ();
  169. AssertNull ("SignatureLength", signedXml.SignatureLength);
  170. AssertEquals ("SignatureMethod", SignedXml.XmlDsigDSAUrl, signedXml.SignatureMethod);
  171. AssertEquals ("SignatureValue", 40, signedXml.SignatureValue.Length);
  172. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  173. // Get the XML representation of the signature.
  174. XmlElement xmlSignature = signedXml.GetXml ();
  175. // LAMESPEC: we must reload the signature or it won't work
  176. // MS framework throw a "malformed element"
  177. SignedXml vrfy = new SignedXml ();
  178. vrfy.LoadXml (xmlSignature);
  179. // assert that we can verify our own signature
  180. Assert ("DSA-Compute/Verify", vrfy.CheckSignature ());
  181. }
  182. [Test]
  183. public void SymmetricHMACSHA1Signature ()
  184. {
  185. SignedXml signedXml = MSDNSample ();
  186. // Compute the signature.
  187. byte[] secretkey = Encoding.Default.GetBytes ("password");
  188. HMACSHA1 hmac = new HMACSHA1 (secretkey);
  189. AssertNull ("KeyInfo", signedXml.KeyInfo);
  190. AssertNull ("SignatureLength", signedXml.SignatureLength);
  191. AssertNull ("SignatureMethod", signedXml.SignatureMethod);
  192. AssertNull ("SignatureValue", signedXml.SignatureValue);
  193. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  194. signedXml.ComputeSignature (hmac);
  195. AssertNull ("KeyInfo", signedXml.KeyInfo);
  196. AssertNull ("SignatureLength", signedXml.SignatureLength);
  197. AssertEquals ("SignatureMethod", SignedXml.XmlDsigHMACSHA1Url, signedXml.SignatureMethod);
  198. AssertEquals ("SignatureValue", 20, signedXml.SignatureValue.Length);
  199. AssertNull ("SigningKeyName", signedXml.SigningKeyName);
  200. // Get the XML representation of the signature.
  201. XmlElement xmlSignature = signedXml.GetXml ();
  202. // LAMESPEC: we must reload the signature or it won't work
  203. // MS framework throw a "malformed element"
  204. SignedXml vrfy = new SignedXml ();
  205. vrfy.LoadXml (xmlSignature);
  206. // assert that we can verify our own signature
  207. Assert ("HMACSHA1-Compute/Verify", vrfy.CheckSignature (hmac));
  208. }
  209. [Test]
  210. [ExpectedException (typeof (CryptographicException))]
  211. public void SymmetricMACTripleDESSignature ()
  212. {
  213. SignedXml signedXml = MSDNSample ();
  214. // Compute the signature.
  215. byte[] secretkey = Encoding.Default.GetBytes ("password");
  216. MACTripleDES hmac = new MACTripleDES (secretkey);
  217. signedXml.ComputeSignature (hmac);
  218. }
  219. // Using empty constructor
  220. // LAMESPEC: The two other constructors don't seems to apply in verifying signatures
  221. [Test]
  222. public void AsymmetricRSAVerify ()
  223. {
  224. string value = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo><SignatureValue>A6XuE8Cy9iOffRXaW9b0+dUcMUJQnlmwLsiqtQnADbCtZXnXAaeJ6nGnQ4Mm0IGi0AJc7/2CoJReXl7iW4hltmFguG1e3nl0VxCyCTHKGOCo1u8R3K+B1rTaenFbSxs42EM7/D9KETsPlzfYfis36yM3PqatiCUOsoMsAiMGzlc=</SignatureValue><KeyInfo><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><RSAKeyValue><Modulus>tI8QYIpbG/m6JLyvP+S3X8mzcaAIayxomyTimSh9UCpEucRnGvLw0P73uStNpiF7wltTZA1HEsv+Ha39dY/0j/Wiy3RAodGDRNuKQao1wu34aNybZ673brbsbHFUfw/o7nlKD2xO84fbajBZmKtBBDy63NHt+QL+grSrREPfCTM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement xmlns=\"samples\">This is some text</MyElement></Object></Signature>";
  225. XmlDocument doc = new XmlDocument ();
  226. doc.LoadXml (value);
  227. SignedXml v1 = new SignedXml ();
  228. v1.LoadXml (doc.DocumentElement);
  229. Assert ("RSA-CheckSignature()", v1.CheckSignature ());
  230. SignedXml v2 = new SignedXml ();
  231. v2.LoadXml (doc.DocumentElement);
  232. AsymmetricAlgorithm key = null;
  233. bool vrfy = v2.CheckSignatureReturningKey (out key);
  234. Assert ("RSA-CheckSignatureReturningKey()", vrfy);
  235. SignedXml v3 = new SignedXml ();
  236. v3.LoadXml (doc.DocumentElement);
  237. Assert ("RSA-CheckSignature(key)", v3.CheckSignature (key));
  238. }
  239. // Using empty constructor
  240. // LAMESPEC: The two other constructors don't seems to apply in verifying signatures
  241. [Test]
  242. public void AsymmetricDSAVerify ()
  243. {
  244. string value = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#dsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo><SignatureValue>BYz/qRGjGsN1yMFPxWa3awUZm1y4I/IxOQroMxkOteRGgk1HIwhRYw==</SignatureValue><KeyInfo><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>iglVaZ+LsSL8Y0aDXmFMBwva3xHqIypr3l/LtqBH9ziV2Sh1M4JVasAiKqytWIWt/s/Uk8Ckf2tO2Ww1vsNi1NL+Kg9T7FE52sn380/rF0miwGkZeidzm74OWhykb3J+wCTXaIwOzAWI1yN7FoeoN7wzF12jjlSXAXeqPMlViqk=</P><Q>u4sowiJMHilNRojtdmIuQY2YnB8=</Q><G>SdnN7d+wn1n+HH4Hr8MIryIRYgcXdbZ5TH7jAnuWc1koqRc1AZfcYAZ6RDf+orx6Lzn055FTFiN+1NHQfGUtXJCWW0zz0FVV1NJux7WRj8vGTldjJ5ef0oCenkpwDjcIxWsZgVobve4GPoyN1sAc1scnkJB59oupibklmF4y72A=</G><Y>XejzS8Z51yfl0zbYnxSYYbHqreSLjNCoGPB/KjM1TOyV5sMjz0StKtGrFWryTWc7EgvFY7kUth4e04VKf9HbK8z/FifHTXj8+Tszbjzw8GfInnBwLN+vJgbpnjtypmiI5Bm2nLiRbfkdAHP+OrKtr/EauM9GQfYuaxm3/Vj8B84=</Y><J>vGwGg9wqwwWP9xsoPoXu6kHArJtadiNKe9azBiUx5Ob883gd5wlKfEcGuKkBmBySGbgwxyOsIBovd9Kk48hF01ymfQzAAuHR0EdJECSsTsTTKVTLQNBU32O+PRbLYpv4E8kt6rNL83JLJCBY</J><Seed>sqzn8J6fd2gtEyq6YOqiUSHgPE8=</Seed><PgenCounter>sQ==</PgenCounter></DSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement xmlns=\"samples\">This is some text</MyElement></Object></Signature>";
  245. XmlDocument doc = new XmlDocument ();
  246. doc.LoadXml (value);
  247. SignedXml v1 = new SignedXml ();
  248. v1.LoadXml (doc.DocumentElement);
  249. Assert ("DSA-CheckSignature()", v1.CheckSignature ());
  250. SignedXml v2 = new SignedXml ();
  251. v2.LoadXml (doc.DocumentElement);
  252. AsymmetricAlgorithm key = null;
  253. bool vrfy = v2.CheckSignatureReturningKey (out key);
  254. Assert ("DSA-CheckSignatureReturningKey()", vrfy);
  255. SignedXml v3 = new SignedXml ();
  256. v3.LoadXml (doc.DocumentElement);
  257. Assert ("DSA-CheckSignature(key)", v3.CheckSignature (key));
  258. }
  259. [Test]
  260. public void SymmetricHMACSHA1Verify ()
  261. {
  262. string value = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#hmac-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo><SignatureValue>e2RxYr5yGbvTqZLCFcgA2RAC0yE=</SignatureValue><Object Id=\"MyObjectId\"><MyElement xmlns=\"samples\">This is some text</MyElement></Object></Signature>";
  263. XmlDocument doc = new XmlDocument ();
  264. doc.LoadXml (value);
  265. SignedXml v1 = new SignedXml ();
  266. v1.LoadXml (doc.DocumentElement);
  267. byte[] secretkey = Encoding.Default.GetBytes ("password");
  268. HMACSHA1 hmac = new HMACSHA1 (secretkey);
  269. Assert ("HMACSHA1-CheckSignature(key)", v1.CheckSignature (hmac));
  270. }
  271. [Test]
  272. // adapted from http://bugzilla.ximian.com/show_bug.cgi?id=52084
  273. public void GetIdElement ()
  274. {
  275. XmlDocument doc = new XmlDocument ();
  276. doc.LoadXml (signature);
  277. SignedXml v1 = new SignedXml ();
  278. v1.LoadXml (doc.DocumentElement);
  279. Assert ("CheckSignature", v1.CheckSignature ());
  280. XmlElement xel = v1.GetIdElement (doc, "MyObjectId");
  281. Assert ("GetIdElement", xel.InnerXml.StartsWith ("<ObjectListTag"));
  282. }
  283. [Test]
  284. public void GetPublicKey ()
  285. {
  286. XmlDocument doc = new XmlDocument ();
  287. doc.LoadXml (signature);
  288. SignedXmlEx sxe = new SignedXmlEx ();
  289. sxe.LoadXml (doc.DocumentElement);
  290. AsymmetricAlgorithm aa1 = sxe.PublicGetPublicKey ();
  291. Assert ("First Public Key is RSA", (aa1 is RSA));
  292. AsymmetricAlgorithm aa2 = sxe.PublicGetPublicKey ();
  293. AssertNull ("Second Public Key is null", aa2);
  294. }
  295. [Test]
  296. public void Add_Null ()
  297. {
  298. SignedXml sx = new SignedXml ();
  299. // no ArgumentNull exceptions for those
  300. sx.AddObject (null);
  301. sx.AddReference (null);
  302. }
  303. [Test]
  304. [ExpectedException (typeof (CryptographicException))]
  305. public void GetXml_WithoutInfo ()
  306. {
  307. SignedXml sx = new SignedXml ();
  308. XmlElement xel = sx.GetXml ();
  309. }
  310. [Test]
  311. [ExpectedException (typeof (ArgumentNullException))]
  312. public void LoadXml_Null ()
  313. {
  314. SignedXml sx = new SignedXml ();
  315. sx.LoadXml (null);
  316. }
  317. [Test]
  318. public void SigningKeyName ()
  319. {
  320. SignedXmlEx sxe = new SignedXmlEx ();
  321. AssertNull ("SigningKeyName", sxe.SigningKeyName);
  322. sxe.SigningKeyName = "mono";
  323. AssertEquals ("SigningKeyName", "mono", sxe.SigningKeyName);
  324. }
  325. [Test]
  326. public void CheckSignatureEmptySafe ()
  327. {
  328. SignedXml sx;
  329. KeyInfoClause kic;
  330. KeyInfo ki;
  331. // empty keyinfo passes...
  332. sx = new SignedXml ();
  333. sx.KeyInfo = new KeyInfo ();
  334. Assert (!sx.CheckSignature ());
  335. // with empty KeyInfoName
  336. kic = new KeyInfoName ();
  337. ki = new KeyInfo ();
  338. ki.AddClause (kic);
  339. sx.KeyInfo = ki;
  340. Assert (!sx.CheckSignature ());
  341. }
  342. [Test]
  343. [ExpectedException (typeof (CryptographicException))]
  344. public void CheckSignatureEmpty ()
  345. {
  346. SignedXml sx = new SignedXml ();
  347. sx.CheckSignature ();
  348. }
  349. }
  350. }