Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -75,10 +75,8 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[Ignore ("2.0 throws a NullReferenceException - reported as FDBK25892")]
// http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=02dd9730-d1ad-4170-8c82-36858c55fbe2
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_XmlDocument_Null ()
{
@ -100,9 +98,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void Constructor_XmlElement_WithoutLoadXml ()
{
XmlDocument doc = new XmlDocument ();
@ -213,6 +208,87 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.IsTrue (vrfy.CheckSignature (), "RSA-Compute/Verify");
}
// The same as MSDNSample(), but adding a few attributes
public SignedXml MSDNSampleMixedCaseAttributes ()
{
// Create example data to sign.
XmlDocument document = new XmlDocument ();
XmlNode node = document.CreateNode (XmlNodeType.Element, "", "MyElement", "samples");
node.InnerText = "This is some text";
XmlAttribute a1 = document.CreateAttribute ("Aa");
XmlAttribute a2 = document.CreateAttribute ("Bb");
XmlAttribute a3 = document.CreateAttribute ("aa");
XmlAttribute a4 = document.CreateAttribute ("bb");
a1.Value = "one";
a2.Value = "two";
a3.Value = "three";
a4.Value = "four";
node.Attributes.Append (a1);
node.Attributes.Append (a2);
node.Attributes.Append (a3);
node.Attributes.Append (a4);
document.AppendChild (node);
// Create the SignedXml message.
SignedXml signedXml = new SignedXml ();
// Create a data object to hold the data to sign.
DataObject dataObject = new DataObject ();
dataObject.Data = document.ChildNodes;
dataObject.Id = "MyObjectId";
// Add the data object to the signature.
signedXml.AddObject (dataObject);
// Create a reference to be able to package everything into the
// message.
Reference reference = new Reference ();
reference.Uri = "#MyObjectId";
// Add it to the message.
signedXml.AddReference (reference);
return signedXml;
}
public string AsymmetricRSAMixedCaseAttributes ()
{
SignedXml signedXml = MSDNSampleMixedCaseAttributes ();
RSA key = RSA.Create ();
signedXml.SigningKey = key;
// Add a KeyInfo.
KeyInfo keyInfo = new KeyInfo ();
keyInfo.AddClause (new RSAKeyValue (key));
signedXml.KeyInfo = keyInfo;
// Compute the signature.
signedXml.ComputeSignature ();
// Get the XML representation of the signature.
XmlElement xmlSignature = signedXml.GetXml ();
StringWriter sw = new StringWriter ();
XmlWriter w = new XmlTextWriter (sw);
xmlSignature.WriteTo (w);
return sw.ToString ();
}
// Example output from Windows for AsymmetricRSAMixedCaseAttributes()
private const string AsymmetricRSAMixedCaseAttributesResult = "<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>0j1xLsePFtuRHfXEnVdTSLWtAm4=</DigestValue></Reference></SignedInfo><SignatureValue>hmrEBgns5Xx14aDhzqOyIh0qLNMUldtW8+fNPcvtD/2KtEhNZQGctnhs90CRa1NZ08TqzW2pUaEwmqvMAtF4v8KtWzC/zTuc1jH6nxQvQSQo0ABhuXdu7/hknZkXJ4yKBbdgbKjAsKfULwbWrP/PacLPoYfCO+wXSrt+wLMTTWU=</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>4h/rHDr54r6SZWk2IPCeHX7N+wR1za0VBLshuS6tq3RSWap4PY2BM8VdbKH2T9RzyZoiHufjng+1seUx430iMsXisOLUkPP+yGtMQOSZ3CQHAa+IYA+fplXipixI0rV1J1wJNXQm3HxXQqKWpIv5fkwBtj8o2k6CWMgPNgFCnxc=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement Aa=\"one\" Bb=\"two\" aa=\"three\" bb=\"four\" xmlns=\"samples\">This is some text</MyElement></Object></Signature>";
[Test]
public void AsymmetricRSAMixedCaseAttributesVerifyWindows ()
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml (AsymmetricRSAMixedCaseAttributesResult);
SignedXml v1 = new SignedXml ();
v1.LoadXml (doc.DocumentElement);
Assert.IsTrue (v1.CheckSignature ());
}
[Test]
public void AsymmetricDSASignature ()
{
@ -260,11 +336,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
// Compute the signature.
byte[] secretkey = Encoding.Default.GetBytes ("password");
HMACSHA1 hmac = new HMACSHA1 (secretkey);
#if NET_2_0
Assert.AreEqual (0, signedXml.KeyInfo.Count, "KeyInfo");
#else
Assert.IsNull (signedXml.KeyInfo, "KeyInfo");
#endif
Assert.IsNull (signedXml.SignatureLength, "SignatureLength");
Assert.IsNull (signedXml.SignatureMethod, "SignatureMethod");
Assert.IsNull (signedXml.SignatureValue, "SignatureValue");
@ -272,11 +344,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
signedXml.ComputeSignature (hmac);
#if NET_2_0
Assert.AreEqual (0, signedXml.KeyInfo.Count, "KeyInfo");
#else
Assert.IsNull (signedXml.KeyInfo, "KeyInfo");
#endif
Assert.IsNull (signedXml.SignatureLength, "SignatureLength");
Assert.AreEqual (SignedXml.XmlDsigHMACSHA1Url, signedXml.SignatureMethod, "SignatureMethod");
Assert.AreEqual (20, signedXml.SignatureValue.Length, "SignatureValue");
@ -399,7 +467,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
AsymmetricAlgorithm aa2 = sxe.PublicGetPublicKey ();
Assert.IsNull (aa2, "Second Public Key is null");
}
#if NET_2_0
[Test]
// [ExpectedException (typeof (ArgumentNullException))]
public void AddObject_Null ()
@ -416,16 +483,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
SignedXml sx = new SignedXml ();
sx.AddReference (null);
}
#else
[Test]
public void Add_Null ()
{
SignedXml sx = new SignedXml ();
// no ArgumentNull exceptions for those
sx.AddObject (null);
sx.AddReference (null);
}
#endif
[Test]
[ExpectedException (typeof (CryptographicException))]
public void GetXml_WithoutInfo ()
@ -472,9 +529,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CheckSignatureEmpty ()
{
SignedXml sx = new SignedXml ();
@ -600,7 +654,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.IsNull (sign.GetIdElement (new XmlDocument (), null));
}
#if NET_2_0
[Test]
[Category ("NotWorking")] // bug #79483
public void DigestValue_CRLF ()
@ -1293,7 +1346,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
// verify MS-generated signature
Assert.IsTrue (sign.CheckSignature (new HMACRIPEMD160 (hmackey)));
}
#endif
// CVE-2009-0217
// * a 0-length signature is the worse case - it accepts anything
// * between 1-7 bits length are considered invalid (not a multiple of 8)
@ -1421,7 +1473,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
SignedXml sign = GetSignedXml (xml);
Assert.IsTrue (sign.CheckSignature (new HMACSHA1 (Encoding.ASCII.GetBytes ("secret"))));
}
#if NET_2_0
[Test]
[Category ("NotDotNet")] // will fail until a fix is available
public void VerifyHMAC_SmallerHalfLength ()
@ -1440,7 +1491,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
SignedXml sign = GetSignedXml (xml);
Assert.IsTrue (sign.CheckSignature (new HMACSHA256 (Encoding.ASCII.GetBytes ("secret"))));
}
#endif
[Test]
public void VerifyHMAC_FullLength ()
{