**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Test / Microsoft.Web.Services.Security / AuthenticationKeyTest.cs
blob0d2fdbecff4a25eba7257df100320f87fcdb20f3
1 //
2 // AuthenticationKeyTest.cs
3 // - NUnit Test Cases for AuthenticationKey
4 //
5 // Author:
6 // Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 //
11 using NUnit.Framework;
12 using Microsoft.Web.Services.Security;
13 using System;
14 using System.Security.Cryptography;
15 using System.Xml;
17 namespace MonoTests.MS.Web.Services.Security {
19 [TestFixture]
20 public class AuthenticationKeyTest : Assertion {
22 [Test]
23 [ExpectedException (typeof (ArgumentNullException))]
24 public void ConstructorAsymmetricNull ()
26 // we do not want to confuse the compiler about null ;-)
27 AsymmetricAlgorithm aa = null;
28 AuthenticationKey ak = new AuthenticationKey (aa);
31 [Test]
32 [ExpectedException (typeof (ArgumentNullException))]
33 public void ConstructorSymmetricNull ()
35 // we do not want to confuse the compiler about null ;-)
36 SymmetricAlgorithm sa = null;
37 AuthenticationKey ak = new AuthenticationKey (sa);
40 [Test]
41 // LAMESPEC: undocumented exception
42 [ExpectedException (typeof (ArgumentNullException))]
43 public void CheckSignatureNull ()
45 DSA dsa = DSA.Create ();
46 dsa.ImportParameters (AllTests.GetDSAKey (false));
47 AuthenticationKey ak = new AuthenticationKey (dsa);
48 ak.CheckSignature (null);
51 [Test]
52 public void CheckSignatureDSA ()
54 DSA dsa = DSA.Create ();
55 dsa.ImportParameters (AllTests.GetDSAKey (false));
56 AuthenticationKey ak = new AuthenticationKey (dsa);
57 AssertNotNull ("AuthenticationKey(DSA)", ak);
59 XmlDocument doc = new XmlDocument ();
60 doc.LoadXml ("<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#dsa-sha1\" /><Reference URI=\"http://www.go-mono.com/\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>JjDjPDymSPahf7zC6CCqaTz39uQ=</DigestValue></Reference></SignedInfo><SignatureValue>j2Rl0vEKoKbRfOTtEZvYoNSdiJdkCfN+FfuMntTqVMmYFFtl/nWExg==</SignatureValue></Signature>");
61 SignedXml signedXml = new SignedXml ();
62 signedXml.LoadXml (doc.DocumentElement);
63 Assert ("CheckSignature(DSA)", ak.CheckSignature (signedXml));
66 [Test]
67 public void CheckSignatureRSA ()
69 RSA rsa = RSA.Create ();
70 rsa.ImportParameters (AllTests.GetRSAKey (false));
71 AuthenticationKey ak = new AuthenticationKey (rsa);
72 AssertNotNull ("AuthenticationKey(RSA)", ak);
74 XmlDocument doc = new XmlDocument ();
75 doc.LoadXml ("<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"http://www.go-mono.com/\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>JjDjPDymSPahf7zC6CCqaTz39uQ=</DigestValue></Reference></SignedInfo><SignatureValue>l/Anzks1CncmNQsDb2ZgSYEcXcX7sS0jql5fmQcEVAkRDhxwV2Lb+6Z2yPO5F+QZ+54m8w/QJdbQJduyOF0w1blkWd1Iz5ubOt79Cg1f0zO8SYwB1X6j0SzXXB5tTm1hYjKzX/iAqgUJF1o8bscu74A8xCwQio2ay7TWoTEl/Ss=</SignatureValue></Signature>");
76 SignedXml signedXml = new SignedXml ();
77 signedXml.LoadXml (doc.DocumentElement);
78 Assert ("CheckSignature(RSA)", ak.CheckSignature (signedXml));
81 [Test]
82 public void CheckSignatureSymmetricAlgo ()
84 // default (should be Rjindael)
85 SymmetricAlgorithm sa = SymmetricAlgorithm.Create ();
86 sa.Key = new byte [16]; // 128 bits (all zeros)
87 AuthenticationKey ak = new AuthenticationKey (sa);
88 AssertNotNull ("AuthenticationKey(SymmetricAlgorithm)", ak);
90 XmlDocument doc = new XmlDocument ();
91 doc.LoadXml ("<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#hmac-sha1\" /><Reference URI=\"http://www.go-mono.com/\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>JjDjPDymSPahf7zC6CCqaTz39uQ=</DigestValue></Reference></SignedInfo><SignatureValue>y5NfXaoCALrMxBsn/wGKNJUNJ7Y=</SignatureValue></Signature>");
92 SignedXml signedXml = new SignedXml ();
93 signedXml.LoadXml (doc.DocumentElement);
94 Assert ("CheckSignature(HMAC)", ak.CheckSignature (signedXml));