Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c435f41
fix tests trying to create SHA1CryptoServiceProvider
krwq Mar 3, 2017
32ab581
disable MAC3DES test, add DSASignatureDescription
krwq Mar 3, 2017
fd114f9
fix or better reason for test failure
krwq Mar 3, 2017
ff68844
disable AsymmetricDSASignature test with different reason
krwq Mar 3, 2017
8de1a2a
fix improperly wrapped Assert.Throws (verified with Mono)
krwq Mar 3, 2017
41864db
fix reverse condition
krwq Mar 3, 2017
d5f7335
disable few more tests with better issue
krwq Mar 4, 2017
efb7150
expect exception on unsupported output
krwq Mar 4, 2017
5b4dddf
fix few more tests
krwq Mar 4, 2017
4ed2428
attempt to fix escaping issue
krwq Mar 4, 2017
a556ced
fix replacement char
krwq Mar 4, 2017
bde5d64
Use XmlPreloadedResolver to remove file dependencies
anthonylangsworth Mar 4, 2017
c742452
Move String2Stream and ExecuteTransform into TestHelpers
anthonylangsworth Mar 4, 2017
8f8cb74
Consolidate and fix up tests
anthonylangsworth Mar 4, 2017
088b6d5
Use TestHelpers version of ExecuteTransform
anthonylangsworth Mar 4, 2017
9c2e262
Correct file:// reference to ensure examples are verbatim
anthonylangsworth Mar 4, 2017
c66b24f
Remove final TestHelpers.Create* reference
anthonylangsworth Mar 4, 2017
710775a
Remove TestHelpers.Create*
anthonylangsworth Mar 4, 2017
55f4b87
Fix Transform.PropagatedNamespace and test
anthonylangsworth Mar 4, 2017
e5b43ed
Merge pull request #1 from anthonylangsworth/signed-xml-fixing-tests-1
krwq Mar 4, 2017
258206f
Fix PropagatedNamespaces and test
anthonylangsworth Mar 5, 2017
42612de
[Fact()] to [Fact]
anthonylangsworth Mar 5, 2017
2740de0
Merge pull request #2 from anthonylangsworth/PropagatedNamespace
krwq Mar 6, 2017
95cb211
Merge branch 'signed-xml-fixing-tests-1' of github.com:krwq/corefx in…
anthonylangsworth Mar 6, 2017
fe36785
Fix slash error in Un*x
anthonylangsworth Mar 6, 2017
34aff2c
Merge pull request #3 from anthonylangsworth/slashfix
krwq Mar 6, 2017
b079fd0
assign more concrete issues to disabled tests
krwq Mar 6, 2017
2a5a8eb
disable test failing on linux
krwq Mar 6, 2017
caf7de2
apply review feedback
krwq Mar 6, 2017
4b01e4b
revert product fix and disable test
krwq Mar 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Compile Include="System\Security\Cryptography\Xml\DataReference.cs" />
<Compile Include="System\Security\Cryptography\Xml\DocPosition.cs" />
<Compile Include="System\Security\Cryptography\Xml\DSAKeyValue.cs" />
<Compile Include="System\Security\Cryptography\Xml\DSASignatureDescription.cs" />
<Compile Include="System\Security\Cryptography\Xml\EncryptedData.cs" />
<Compile Include="System\Security\Cryptography\Xml\EncryptedKey.cs" />
<Compile Include="System\Security\Cryptography\Xml\EncryptedReference.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public static object CreateFromName(string name)
throw new NotImplementedException(name);
//return new System.Security.Cryptography.HMACRIPEMD160();
case "http://www.w3.org/2000/09/xmldsig#dsa-sha1":
throw new NotImplementedException(name);
//return new DSASignatureDescription();
return new DSASignatureDescription();
case "System.Security.Cryptography.DSASignatureDescription":
throw new NotImplementedException(name);
//return new DSASignatureDescription();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System.Security.Cryptography.Xml
{
internal class DSASignatureDescription : SignatureDescription
{
const string HashAlgorithm = "SHA1";

public DSASignatureDescription()
{
KeyAlgorithm = typeof(System.Security.Cryptography.DSA).AssemblyQualifiedName;
FormatterAlgorithm = typeof(System.Security.Cryptography.DSASignatureFormatter).AssemblyQualifiedName;
DeformatterAlgorithm = typeof(System.Security.Cryptography.DSASignatureDeformatter).AssemblyQualifiedName;
DigestAlgorithm = "SHA1";
}

public sealed override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
{
var item = (AsymmetricSignatureDeformatter)CryptoHelpers.CreateFromName(DeformatterAlgorithm);
item.SetKey(key);
item.SetHashAlgorithm(HashAlgorithm);
return item;
}

public sealed override AsymmetricSignatureFormatter CreateFormatter(AsymmetricAlgorithm key)
{
var item = (AsymmetricSignatureFormatter)CryptoHelpers.CreateFromName(FormatterAlgorithm);
item.SetKey(key);
item.SetHashAlgorithm(HashAlgorithm);
return item;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 needed for compat.")]
public sealed override HashAlgorithm CreateDigest()
{
return SHA1.Create();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void GetXml_SameDsa()
}
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16779")]
public void LoadXml()
{
const string pValue = "oDZlcdJA1Kf6UeNEIZqm4KDqA6zpX7CmEtAGWi9pgnBhWOUDVEfhswfsvTLR5BCbKfE6KoHvt5Hh8D1RcAko//iZkLZ+gds9y/5Oxape8tu3TUi1BnNPWu8ieXjMtdnpyudKFsCymssJked1rBeRePG23HTVwOV1DpopjRkjBEU=";
Expand All @@ -110,6 +110,7 @@ public void LoadXml()
Assert.Equal(Convert.ToBase64String(parameters.Q), qValue);
Assert.Equal(Convert.ToBase64String(parameters.G), gValue);
Assert.Equal(Convert.ToBase64String(parameters.Y), yValue);
Assert.NotNull(parameters.Seed);
Assert.Equal(Convert.ToBase64String(parameters.Seed), seedValue);
Assert.Equal(BitConverter.GetBytes(parameters.Counter)[0], Convert.FromBase64String(pgenCounterValue)[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Sample2()
}
}

[Fact(Skip = "TODO: fix me")]
[Fact]
public void Sample3()
{
AssertDecryption1("System.Security.Cryptography.Xml.Tests.EncryptedXmlSample3.xml");
Expand Down Expand Up @@ -224,7 +224,7 @@ public void GetDecryptionIV_EncryptedDataNull()
Assert.Throws<ArgumentNullException>(() => ex.GetDecryptionIV(null, EncryptedXml.XmlEncAES128Url));
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void GetDecryptionIV_StringNull()
{
// Added EncryptionMethod and CipherData to avoid a CryptographicException
Expand Down
2 changes: 1 addition & 1 deletion src/System.Security.Cryptography.Xml/tests/KeyInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void Complex()
}
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16779")]
public void ImportKeyNode()
{
string value = "<KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyName>Mono::</KeyName><KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue><P>rjxsMU368YOCTQejWkiuO9e/vUVwkLtq1jKiU3TtJ53hBJqjFRuTa228vZe+BH2su9RPn/vYFWfQDv6zgBYe3eNdu4Afw+Ny0FatX6dl3E77Ra6Tsd3MmLXBiGSQ1mMNd5G2XQGpbt9zsGlUaexXekeMLxIufgfZLwYp67M+2WM=</P><Q>tf0K9rMyvUrU4cIkwbCrDRhQAJk=</Q><G>S8Z+1pGCed00w6DtVcqZLKjfqlCJ7JsugEFIgSy/Vxtu9YGCMclV4ijGEbPo/jU8YOSMuD7E9M7UaopMRcmKQjoKZzoJjkgVFP48Ohxl1f08lERnButsxanx3+OstFwUGQ8XNaGg3KrIoZt1FUnfxN3RHHTvVhjzNSHxMGULGaU=</G><Y>LnrxxRGLYeV2XLtK3SYz8RQHlHFZYrtznDZyMotuRfO5uC5YODhSFyLXvb1qB3WeGtF4h3Eo4KzHgMgfN2ZMlffxFRhJgTtH3ctbL8lfQoDkjeiPPnYGhspdJxr0tyZmiy0gkjJG3vwHYrLnvZWx9Wm/unqiOlGBPNuxJ+hOeP8=</Y><J>9RhE5TycDtdEIXxS3HfxFyXYgpy81zY5lVjwD6E9JP37MWEi80BlX6ab1YPm6xYSEoqReMPP9RgGiW6DuACpgI7+8vgCr4i/7VhzModJAA56PwvTu6UMt9xxKU/fT672v8ucREkMWoc7lEey</J><Seed>HxW3N4RHWVgqDQKuGg7iJTUTiCs=</Seed><PgenCounter>Asw=</PgenCounter></DSAKeyValue></KeyValue>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void AddSubjectKeyId_String_Null()
Assert.Throws< NullReferenceException>(() => data1.AddSubjectKeyId((string)null));
}

[Fact(Skip = "TODO: fix me")]
[Fact]
public void AddSubjectKeyId_String_BadHexData()
{
KeyInfoX509Data data = new KeyInfoX509Data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void GetXmlWithoutSetProperty()
Assert.Equal(result, el.OuterXml);
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void GetXmlWithSetProperty()
{
XmlDocument doc = new XmlDocument();
Expand Down
61 changes: 28 additions & 33 deletions src/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void SignatureMethodMismatch()
Assert.Throws<CryptographicException>(() => signedXml.ComputeSignature());
}

[Fact(Skip = "TODO: fix me")]
[Fact]
public void AsymmetricRSASignature()
{
SignedXml signedXml = MSDNSample();
Expand All @@ -188,7 +188,7 @@ public void AsymmetricRSASignature()

Assert.Null(signedXml.SigningKeyName);
Assert.Equal(SignedXml.XmlDsigRSASHA1Url, signedXml.SignatureMethod);
Assert.Equal(128, signedXml.SignatureValue.Length);
Assert.Equal(key.KeySize / 8, signedXml.SignatureValue.Length);
Assert.Null(signedXml.SigningKeyName);

// Get the XML representation of the signature.
Expand Down Expand Up @@ -284,7 +284,7 @@ public void AsymmetricRSAMixedCaseAttributesVerifyWindows()
Assert.True(v1.CheckSignature());
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16691")]
public void AsymmetricDSASignature()
{
SignedXml signedXml = MSDNSample();
Expand Down Expand Up @@ -357,19 +357,6 @@ public void SymmetricHMACSHA1Signature()
Assert.True(vrfy.CheckSignature(hmac), "HMACSHA1-Compute/Verify");
}

[Fact(Skip = "TODO: fix me")]
public void SymmetricMACTripleDESSignature()
{
SignedXml signedXml = MSDNSample();
// Compute the signature.
byte[] secretkey = Encoding.Default.GetBytes("password");
using (HMAC hmac = HMACSHA256.Create())
{
hmac.Key = secretkey;
Assert.Throws<CryptographicException>(() => signedXml.ComputeSignature(hmac));
}
}

// Using empty constructor
// LAMESPEC: The two other constructors don't seems to apply in verifying signatures
[Fact]
Expand All @@ -396,7 +383,7 @@ public void AsymmetricRSAVerify()

// Using empty constructor
// LAMESPEC: The two other constructors don't seems to apply in verifying signatures
[Fact(Skip = "TODO: fix me")]
[Fact]
public void AsymmetricDSAVerify()
{
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>";
Expand Down Expand Up @@ -565,7 +552,7 @@ public void ComputeSignatureMissingReferencedObject()
Assert.Throws<CryptographicException>(() => signedXml.ComputeSignature());
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void DataReferenceToNonDataObject()
{
XmlDocument doc = new XmlDocument();
Expand Down Expand Up @@ -638,15 +625,15 @@ string SignWithHMACSHA1(string input, byte[] key, Transform transform)
return sw.ToString();
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void GetIdElement_Null()
{
SignedXml sign = new SignedXml();
Assert.Null(sign.GetIdElement(null, "value"));
Assert.Null(sign.GetIdElement(new XmlDocument(), null));
}

[Fact(Skip = "TODO: fix me")]
[Fact]
public void DigestValue_CRLF()
{
XmlDocument doc = CreateSomeXml("\r\n");
Expand All @@ -658,8 +645,12 @@ public void DigestValue_CRLF()

s.Position = 0;

HashAlgorithm hash = HashAlgorithm.Create("System.Security.Cryptography.SHA1CryptoServiceProvider");
byte[] digest = hash.ComputeHash(s);
byte[] digest;
using (HashAlgorithm hash = SHA1.Create())
{
digest = hash.ComputeHash(s);
}

Assert.Equal("IKbfdK2/DMfXyezCf5QggVCXfk8=", Convert.ToBase64String(digest));

X509Certificate2 cert = new X509Certificate2(_pkcs12, "mono");
Expand Down Expand Up @@ -699,7 +690,7 @@ public void DigestValue_CRLF()
+ "</SignedInfo>", signedXml.SignedInfo.GetXml().OuterXml);
}

[Fact(Skip = "TODO: fix me")]
[Fact]
public void DigestValue_LF()
{
XmlDocument doc = CreateSomeXml("\n");
Expand All @@ -711,8 +702,12 @@ public void DigestValue_LF()

s.Position = 0;

HashAlgorithm hash = HashAlgorithm.Create("System.Security.Cryptography.SHA1CryptoServiceProvider");
byte[] digest = hash.ComputeHash(s);
byte[] digest;
using (HashAlgorithm hash = SHA1.Create())
{
digest = hash.ComputeHash(s);
}

Assert.Equal("e3dsi1xK8FAx1vsug7J203JbEAU=", Convert.ToBase64String(digest));

X509Certificate2 cert = new X509Certificate2(_pkcs12, "mono");
Expand Down Expand Up @@ -1360,7 +1355,7 @@ private void HmacMustBeMultipleOfEightBits(int bits)
sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("secret")));
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void HmacMustBeMultipleOfEightBits()
{
for (int i = 1; i < 160; i++)
Expand All @@ -1373,7 +1368,7 @@ public void HmacMustBeMultipleOfEightBits()
}
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_ZeroLength()
{
string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
Expand Down Expand Up @@ -1401,7 +1396,7 @@ public void VerifyHMAC_ZeroLength()
CheckErratum(sign, new HMACSHA1(Encoding.ASCII.GetBytes("secret")), "4");
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_SmallerThanMinimumLength()
{
// 72 is a multiple of 8 but smaller than the minimum of 80 bits
Expand All @@ -1410,7 +1405,7 @@ public void VerifyHMAC_SmallerThanMinimumLength()
CheckErratum(sign, new HMACSHA1(Encoding.ASCII.GetBytes("secret")), "72");
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_MinimumLength()
{
// 80 bits is the minimum (and the half-size of HMACSHA1)
Expand All @@ -1419,7 +1414,7 @@ public void VerifyHMAC_MinimumLength()
Assert.True(sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("secret"))));
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_SmallerHalfLength()
{
// 80bits is smaller than the half-size of HMACSHA256
Expand All @@ -1428,7 +1423,7 @@ public void VerifyHMAC_SmallerHalfLength()
CheckErratum(sign, new HMACSHA256(Encoding.ASCII.GetBytes("secret")), "80");
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_HalfLength()
{
// 128 is the half-size of HMACSHA256
Expand All @@ -1445,7 +1440,7 @@ public void VerifyHMAC_FullLength()
Assert.True(sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("secret"))));
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_HMACOutputLength_Signature_Mismatch()
{
string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
Expand All @@ -1469,7 +1464,7 @@ public void VerifyHMAC_HMACOutputLength_Signature_Mismatch()
Assert.Throws<CryptographicException>(() => sign.CheckSignature(new HMACSHA1(Encoding.ASCII.GetBytes("no clue"))));
}

[Fact(Skip = "TODO: fix me")]
[Fact(Skip = "https://github.com/dotnet/corefx/issues/16685")]
public void VerifyHMAC_HMACOutputLength_Invalid()
{
string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
<Compile Include="XmlDsigXsltTransformTest.cs" />
<Compile Include="XmlLicenseTransformTest.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Common\tests\System\IO\TempFile.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="EncryptedXmlSample3.xml" />
<EmbeddedResource Include="EncryptedXmlSample2.xml" />
Expand All @@ -57,4 +54,4 @@
<Compile Include="Samples\Samples.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>
Loading