Imported Upstream version 5.2.0.175

Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-06-07 13:16:24 +00:00
parent 4bdbaf4a88
commit 966bba02bb
8776 changed files with 346420 additions and 149650 deletions

View File

@@ -1,25 +1,50 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Xml.Tests", "tests\System.Security.Cryptography.Xml.Tests.csproj", "{3C32659A-6DB9-410A-8E24-BE91BFF4C024}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Xml.Tests", "tests\System.Security.Cryptography.Xml.Tests.csproj", "{4A85232C-E914-4E06-8542-26DAF4B22D60}"
ProjectSection(ProjectDependencies) = postProject
{E7F19085-6570-4811-8D3F-16B576049403} = {E7F19085-6570-4811-8D3F-16B576049403}
{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A} = {0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Xml", "src\System.Security.Cryptography.Xml.csproj", "{E7F19085-6570-4811-8D3F-16B576049403}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Xml", "src\System.Security.Cryptography.Xml.csproj", "{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}"
ProjectSection(ProjectDependencies) = postProject
{C7266957-DB20-4250-9C2E-E1FF83EDBD71} = {C7266957-DB20-4250-9C2E-E1FF83EDBD71}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Xml", "ref\System.Security.Cryptography.Xml.csproj", "{C7266957-DB20-4250-9C2E-E1FF83EDBD71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1A2F9F4A-A032-433E-B914-ADD5992BB178}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E893-4E87-987E-04EF0DCEAEFD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{2E666815-2EDB-464B-9DF6-380BF4789AD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C32659A-6DB9-410A-8E24-BE91BFF4C024}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C32659A-6DB9-410A-8E24-BE91BFF4C024}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7F19085-6570-4811-8D3F-16B576049403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7F19085-6570-4811-8D3F-16B576049403}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A85232C-E914-4E06-8542-26DAF4B22D60}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{4A85232C-E914-4E06-8542-26DAF4B22D60}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{4A85232C-E914-4E06-8542-26DAF4B22D60}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{4A85232C-E914-4E06-8542-26DAF4B22D60}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{C7266957-DB20-4250-9C2E-E1FF83EDBD71}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{C7266957-DB20-4250-9C2E-E1FF83EDBD71}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{C7266957-DB20-4250-9C2E-E1FF83EDBD71}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{C7266957-DB20-4250-9C2E-E1FF83EDBD71}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4A85232C-E914-4E06-8542-26DAF4B22D60} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
{C7266957-DB20-4250-9C2E-E1FF83EDBD71} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
EndGlobalSection
EndGlobal

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<!-- Disabling the builds for Xml until we get it up and running. This excludes it from being built by build.cmd
<Project Include="System.Security.Cryptography.Xml.pkgproj"/>
-->
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -2,10 +2,10 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Security.Cryptography.Xml.builds">
<ProjectReference Include="..\ref\System.Security.Cryptography.Xml.csproj">
<SupportedFramework>net462;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Security.Cryptography.Xml.builds" />
<ProjectReference Include="..\src\System.Security.Cryptography.Xml.csproj" />
</ItemGroup>
<ItemGroup>
<InboxOnTargetFramework Include="MonoAndroid10" />

View File

@@ -2,7 +2,8 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard;
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>
</Project>

View File

@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<PropertyGroup>
<ProjectGuid>{C7266957-DB20-4250-9C2E-E1FF83EDBD71}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.Security.Cryptography.Xml.cs" />
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj" />
<ProjectReference Include="..\..\System.Security.Cryptography.Algorithms\ref\System.Security.Cryptography.Algorithms.csproj" />
<ProjectReference Include="..\..\System.Security.Cryptography.Primitives\ref\System.Security.Cryptography.Primitives.csproj" />
<ProjectReference Include="..\..\System.Security.Cryptography.X509Certificates\ref\System.Security.Cryptography.X509Certificates.csproj" />
<ProjectReference Include="..\..\System.Xml.ReaderWriter\ref\System.Xml.ReaderWriter.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@@ -1,64 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@@ -4,6 +4,7 @@
<PropertyGroup>
<AssemblyName>System.Security.Cryptography.Xml</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProjectGuid>{0544EAE3-0CF2-4EA6-93BE-A9FF8B52724A}</ProjectGuid>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
@@ -33,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" />
@@ -80,6 +82,8 @@
<Compile Include="System\Security\Cryptography\Xml\XmlDsigXPathTransform.cs" />
<Compile Include="System\Security\Cryptography\Xml\XmlDsigXsltTransform.cs" />
<Compile Include="System\Security\Cryptography\Xml\XmlLicenseTransform.cs" />
<Compile Include="System\Security\Cryptography\Xml\CryptoHelpers.cs" />
<Compile Include="System\Security\Cryptography\Xml\RSAPKCS1SHA1SignatureDescription.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Collections" />

View File

@@ -19,7 +19,7 @@ namespace System.Security.Cryptography.Xml
{
XmlNode nodeA = a as XmlNode;
XmlNode nodeB = b as XmlNode;
if ((a == null) || (b == null))
if ((nodeA == null) || (nodeB == null))
throw new ArgumentException();
int namespaceCompare = string.CompareOrdinal(nodeA.NamespaceURI, nodeB.NamespaceURI);
if (namespaceCompare != 0) return namespaceCompare;

View File

@@ -0,0 +1,84 @@
// 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 static class CryptoHelpers
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 needed for compat.")]
public static object CreateFromName(string name)
{
switch (name)
{
case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315":
return new XmlDsigC14NTransform();
case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments":
return new XmlDsigC14NWithCommentsTransform();
case "http://www.w3.org/2001/10/xml-exc-c14n#":
return new XmlDsigExcC14NTransform();
case "http://www.w3.org/2001/10/xml-exc-c14n#WithComments":
return new XmlDsigExcC14NWithCommentsTransform();
case "http://www.w3.org/2000/09/xmldsig#base64":
return new XmlDsigBase64Transform();
case "http://www.w3.org/TR/1999/REC-xpath-19991116":
return new XmlDsigXPathTransform();
case "http://www.w3.org/TR/1999/REC-xslt-19991116":
return new XmlDsigXsltTransform();
case "http://www.w3.org/2000/09/xmldsig#enveloped-signature":
return new XmlDsigEnvelopedSignatureTransform();
case "http://www.w3.org/2002/07/decrypt#XML":
return new XmlDecryptionTransform();
case "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform":
return new XmlLicenseTransform();
case "http://www.w3.org/2000/09/xmldsig# X509Data":
return new KeyInfoX509Data();
case "http://www.w3.org/2000/09/xmldsig# KeyName":
return new KeyInfoName();
case "http://www.w3.org/2000/09/xmldsig# KeyValue/DSAKeyValue":
return new DSAKeyValue();
case "http://www.w3.org/2000/09/xmldsig# KeyValue/RSAKeyValue":
return new RSAKeyValue();
case "http://www.w3.org/2000/09/xmldsig# RetrievalMethod":
return new KeyInfoRetrievalMethod();
case "http://www.w3.org/2001/04/xmlenc# EncryptedKey":
return new KeyInfoEncryptedKey();
case "http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160":
throw new NotImplementedException(name);
//return new System.Security.Cryptography.HMACRIPEMD160();
case "http://www.w3.org/2000/09/xmldsig#dsa-sha1":
return new DSASignatureDescription();
case "System.Security.Cryptography.DSASignatureDescription":
throw new NotImplementedException(name);
//return new DSASignatureDescription();
case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
return new RSAPKCS1SHA1SignatureDescription();
case "System.Security.Cryptography.RSASignatureDescription":
throw new NotImplementedException(name);
//return new RSAPKCS1SHA1SignatureDescription();
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256":
throw new NotImplementedException(name);
//return new RSAPKCS1SHA256SignatureDescription();
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384":
throw new NotImplementedException(name);
//return new RSAPKCS1SHA384SignatureDescription();
case "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512":
throw new NotImplementedException(name);
//return new RSAPKCS1SHA512SignatureDescription();
// workarounds for issue https://github.com/dotnet/corefx/issues/16563
// remove attribute from this method when removing them
case "http://www.w3.org/2000/09/xmldsig#sha1":
return SHA1.Create();
}
return CryptoConfig.CreateFromName(name);
}
}
}

View File

@@ -44,6 +44,15 @@ namespace System.Security.Cryptography.Xml
// public methods
//
/// <summary>
/// Create an XML representation.
/// </summary>
/// <remarks>
/// Based upon https://www.w3.org/TR/xmldsig-core/#sec-DSAKeyValue.
/// </remarks>
/// <returns>
/// An <see cref="XmlElement"/> containing the XML representation.
/// </returns>
public override XmlElement GetXml()
{
XmlDocument xmlDocument = new XmlDocument();
@@ -51,44 +60,62 @@ namespace System.Security.Cryptography.Xml
return GetXml(xmlDocument);
}
private const string KeyValueElementName = "KeyValue";
private const string DSAKeyValueElementName = "DSAKeyValue";
//Optional {P,Q}-Sequence
private const string PElementName = "P";
private const string QElementName = "Q";
//Optional Members
private const string GElementName = "G";
private const string JElementName = "J";
//Mandatory Members
private const string YElementName = "Y";
//Optional {Seed,PgenCounter}-Sequence
private const string SeedElementName = "Seed";
private const string PgenCounterElementName = "PgenCounter";
internal override XmlElement GetXml(XmlDocument xmlDocument)
{
DSAParameters dsaParams = _key.ExportParameters(false);
XmlElement keyValueElement = xmlDocument.CreateElement("KeyValue", SignedXml.XmlDsigNamespaceUrl);
XmlElement dsaKeyValueElement = xmlDocument.CreateElement("DSAKeyValue", SignedXml.XmlDsigNamespaceUrl);
XmlElement keyValueElement = xmlDocument.CreateElement(KeyValueElementName, SignedXml.XmlDsigNamespaceUrl);
XmlElement dsaKeyValueElement = xmlDocument.CreateElement(DSAKeyValueElementName, SignedXml.XmlDsigNamespaceUrl);
XmlElement pElement = xmlDocument.CreateElement("P", SignedXml.XmlDsigNamespaceUrl);
XmlElement pElement = xmlDocument.CreateElement(PElementName, SignedXml.XmlDsigNamespaceUrl);
pElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(dsaParams.P)));
dsaKeyValueElement.AppendChild(pElement);
XmlElement qElement = xmlDocument.CreateElement("Q", SignedXml.XmlDsigNamespaceUrl);
XmlElement qElement = xmlDocument.CreateElement(QElementName, SignedXml.XmlDsigNamespaceUrl);
qElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(dsaParams.Q)));
dsaKeyValueElement.AppendChild(qElement);
XmlElement gElement = xmlDocument.CreateElement("G", SignedXml.XmlDsigNamespaceUrl);
XmlElement gElement = xmlDocument.CreateElement(GElementName, SignedXml.XmlDsigNamespaceUrl);
gElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(dsaParams.G)));
dsaKeyValueElement.AppendChild(gElement);
XmlElement yElement = xmlDocument.CreateElement("Y", SignedXml.XmlDsigNamespaceUrl);
XmlElement yElement = xmlDocument.CreateElement(YElementName, SignedXml.XmlDsigNamespaceUrl);
yElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(dsaParams.Y)));
dsaKeyValueElement.AppendChild(yElement);
// Add optional components if present
if (dsaParams.J != null)
{
XmlElement jElement = xmlDocument.CreateElement("J", SignedXml.XmlDsigNamespaceUrl);
XmlElement jElement = xmlDocument.CreateElement(JElementName, SignedXml.XmlDsigNamespaceUrl);
jElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(dsaParams.J)));
dsaKeyValueElement.AppendChild(jElement);
}
if (dsaParams.Seed != null)
{ // note we assume counter is correct if Seed is present
XmlElement seedElement = xmlDocument.CreateElement("Seed", SignedXml.XmlDsigNamespaceUrl);
XmlElement seedElement = xmlDocument.CreateElement(SeedElementName, SignedXml.XmlDsigNamespaceUrl);
seedElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(dsaParams.Seed)));
dsaKeyValueElement.AppendChild(seedElement);
XmlElement counterElement = xmlDocument.CreateElement("PgenCounter", SignedXml.XmlDsigNamespaceUrl);
XmlElement counterElement = xmlDocument.CreateElement(PgenCounterElementName, SignedXml.XmlDsigNamespaceUrl);
counterElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(Utils.ConvertIntToByteArray(dsaParams.Counter))));
dsaKeyValueElement.AppendChild(counterElement);
}
@@ -98,10 +125,79 @@ namespace System.Security.Cryptography.Xml
return keyValueElement;
}
/// <summary>
/// Deserialize from the XML representation.
/// </summary>
/// <remarks>
/// Based upon https://www.w3.org/TR/xmldsig-core/#sec-DSAKeyValue.
/// </remarks>
/// <param name="value">
/// An <see cref="XmlElement"/> containing the XML representation. This cannot be null.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="value"/> cannot be null.
/// </exception>
/// <exception cref="CryptographicException">
/// The XML has the incorrect schema or the DSA parameters are invalid.
/// </exception>
public override void LoadXml(XmlElement value)
{
// Until DSA implements FromXmlString, throw here
throw new PlatformNotSupportedException();
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if (value.Name != KeyValueElementName
|| value.NamespaceURI != SignedXml.XmlDsigNamespaceUrl)
{
throw new CryptographicException($"Root element must be {KeyValueElementName} element in namepsace {SignedXml.XmlDsigNamespaceUrl}");
}
const string xmlDsigNamespacePrefix = "dsig";
XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(value.OwnerDocument.NameTable);
xmlNamespaceManager.AddNamespace(xmlDsigNamespacePrefix, SignedXml.XmlDsigNamespaceUrl);
XmlNode dsaKeyValueElement = value.SelectSingleNode($"{xmlDsigNamespacePrefix}:{DSAKeyValueElementName}", xmlNamespaceManager);
if (dsaKeyValueElement == null)
{
throw new CryptographicException($"{KeyValueElementName} must contain child element {DSAKeyValueElementName}");
}
XmlNode yNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{YElementName}", xmlNamespaceManager);
if (yNode == null)
throw new CryptographicException($"{YElementName} is missing");
XmlNode pNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{PElementName}", xmlNamespaceManager);
XmlNode qNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{QElementName}", xmlNamespaceManager);
if ((pNode == null && qNode != null) || (pNode != null && qNode == null))
throw new CryptographicException($"{PElementName} and {QElementName} can only occour in combination");
XmlNode gNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{GElementName}", xmlNamespaceManager);
XmlNode jNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{JElementName}", xmlNamespaceManager);
XmlNode seedNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{SeedElementName}", xmlNamespaceManager);
XmlNode pgenCounterNode = dsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{PgenCounterElementName}", xmlNamespaceManager);
if ((seedNode == null && pgenCounterNode != null) || (seedNode != null && pgenCounterNode == null))
throw new CryptographicException($"{SeedElementName} and {PgenCounterElementName} can only occur in combination");
try
{
Key.ImportParameters(new DSAParameters
{
P = (pNode != null) ? Convert.FromBase64String(pNode.InnerText) : null,
Q = (qNode != null) ? Convert.FromBase64String(qNode.InnerText) : null,
G = (gNode != null) ? Convert.FromBase64String(gNode.InnerText) : null,
Y = Convert.FromBase64String(yNode.InnerText),
J = (jNode != null) ? Convert.FromBase64String(jNode.InnerText) : null,
Seed = (seedNode != null) ? Convert.FromBase64String(seedNode.InnerText) : null,
Counter = (pgenCounterNode != null) ? Utils.ConvertByteArrayToInt(Convert.FromBase64String(pgenCounterNode.InnerText)) : 0
});
}
catch (Exception ex)
{
throw new CryptographicException($"An error occurred parsing the key components", ex);
}
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -352,7 +352,7 @@ namespace System.Security.Cryptography.Xml
if (key == null)
throw new CryptographicException(SR.Cryptography_Xml_MissingDecryptionKey);
SymmetricAlgorithm symAlg = (SymmetricAlgorithm)CryptoConfig.CreateFromName(symmetricAlgorithmUri);
SymmetricAlgorithm symAlg = (SymmetricAlgorithm)CryptoHelpers.CreateFromName(symmetricAlgorithmUri);
symAlg.Key = key;
return symAlg;
}
@@ -447,7 +447,7 @@ namespace System.Security.Cryptography.Xml
if (encryptionKey != null)
{
// this is a symmetric algorithm for sure
SymmetricAlgorithm symAlg = (SymmetricAlgorithm)CryptoConfig.CreateFromName(encryptedKey.EncryptionMethod.KeyAlgorithm);
SymmetricAlgorithm symAlg = (SymmetricAlgorithm)CryptoHelpers.CreateFromName(encryptedKey.EncryptionMethod.KeyAlgorithm);
symAlg.Key = encryptionKey;
return EncryptedXml.DecryptKey(encryptedKey.CipherData.CipherValue, symAlg);
}

View File

@@ -94,7 +94,7 @@ namespace System.Security.Cryptography.Xml
}
}
}
KeyInfoClause keyInfoClause = (KeyInfoClause)CryptoConfig.CreateFromName(kicString);
KeyInfoClause keyInfoClause = (KeyInfoClause)CryptoHelpers.CreateFromName(kicString);
// if we don't know what kind of KeyInfoClause we're looking at, use a generic KeyInfoNode:
if (keyInfoClause == null)
keyInfoClause = new KeyInfoNode();

View File

@@ -18,7 +18,7 @@ namespace System.Security.Cryptography.Xml
{
XmlNode nodeA = a as XmlNode;
XmlNode nodeB = b as XmlNode;
if ((a == null) || (b == null))
if ((nodeA == null) || (nodeB == null))
throw new ArgumentException();
bool nodeAdefault = Utils.IsDefaultNamespaceNode(nodeA);
bool nodeBdefault = Utils.IsDefaultNamespaceNode(nodeB);

View File

@@ -44,6 +44,15 @@ namespace System.Security.Cryptography.Xml
// public methods
//
/// <summary>
/// Create an XML representation.
/// </summary>
/// <remarks>
/// Based upon https://www.w3.org/TR/xmldsig-core/#sec-RSAKeyValue.
/// </remarks>
/// <returns>
/// An <see cref="XmlElement"/> containing the XML representation.
/// </returns>
public override XmlElement GetXml()
{
XmlDocument xmlDocument = new XmlDocument();
@@ -51,18 +60,23 @@ namespace System.Security.Cryptography.Xml
return GetXml(xmlDocument);
}
private const string KeyValueElementName = "KeyValue";
private const string RSAKeyValueElementName = "RSAKeyValue";
private const string ModulusElementName = "Modulus";
private const string ExponentElementName = "Exponent";
internal override XmlElement GetXml(XmlDocument xmlDocument)
{
RSAParameters rsaParams = _key.ExportParameters(false);
XmlElement keyValueElement = xmlDocument.CreateElement("KeyValue", SignedXml.XmlDsigNamespaceUrl);
XmlElement rsaKeyValueElement = xmlDocument.CreateElement("RSAKeyValue", SignedXml.XmlDsigNamespaceUrl);
XmlElement keyValueElement = xmlDocument.CreateElement(KeyValueElementName, SignedXml.XmlDsigNamespaceUrl);
XmlElement rsaKeyValueElement = xmlDocument.CreateElement(RSAKeyValueElementName, SignedXml.XmlDsigNamespaceUrl);
XmlElement modulusElement = xmlDocument.CreateElement("Modulus", SignedXml.XmlDsigNamespaceUrl);
XmlElement modulusElement = xmlDocument.CreateElement(ModulusElementName, SignedXml.XmlDsigNamespaceUrl);
modulusElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(rsaParams.Modulus)));
rsaKeyValueElement.AppendChild(modulusElement);
XmlElement exponentElement = xmlDocument.CreateElement("Exponent", SignedXml.XmlDsigNamespaceUrl);
XmlElement exponentElement = xmlDocument.CreateElement(ExponentElementName, SignedXml.XmlDsigNamespaceUrl);
exponentElement.AppendChild(xmlDocument.CreateTextNode(Convert.ToBase64String(rsaParams.Exponent)));
rsaKeyValueElement.AppendChild(exponentElement);
@@ -71,10 +85,55 @@ namespace System.Security.Cryptography.Xml
return keyValueElement;
}
/// <summary>
/// Deserialize from the XML representation.
/// </summary>
/// <remarks>
/// Based upon https://www.w3.org/TR/xmldsig-core/#sec-RSAKeyValue.
/// </remarks>
/// <param name="value">
/// An <see cref="XmlElement"/> containing the XML representation. This cannot be null.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="value"/> cannot be null.
/// </exception>
/// <exception cref="CryptographicException">
/// The XML has the incorrect schema or the RSA parameters are invalid.
/// </exception>
public override void LoadXml(XmlElement value)
{
// Until RSA implements FromXmlString, throw here
throw new PlatformNotSupportedException();
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if (value.Name != KeyValueElementName
|| value.NamespaceURI != SignedXml.XmlDsigNamespaceUrl)
{
throw new CryptographicException($"Root element must be {KeyValueElementName} element in namepsace {SignedXml.XmlDsigNamespaceUrl}");
}
const string xmlDsigNamespacePrefix = "dsig";
XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(value.OwnerDocument.NameTable);
xmlNamespaceManager.AddNamespace(xmlDsigNamespacePrefix, SignedXml.XmlDsigNamespaceUrl);
XmlNode rsaKeyValueElement = value.SelectSingleNode($"{xmlDsigNamespacePrefix}:{RSAKeyValueElementName}", xmlNamespaceManager);
if (rsaKeyValueElement == null)
{
throw new CryptographicException($"{KeyValueElementName} must contain child element {RSAKeyValueElementName}");
}
try
{
Key.ImportParameters(new RSAParameters
{
Modulus = Convert.FromBase64String(rsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{ModulusElementName}", xmlNamespaceManager).InnerText),
Exponent = Convert.FromBase64String(rsaKeyValueElement.SelectSingleNode($"{xmlDsigNamespacePrefix}:{ExponentElementName}", xmlNamespaceManager).InnerText)
});
}
catch (Exception ex)
{
throw new CryptographicException($"An error occurred parsing the {ModulusElementName} and {ExponentElementName} elements", ex);
}
}
}
}

View File

@@ -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 RSAPKCS1SHA1SignatureDescription : SignatureDescription
{
const string HashAlgorithm = "SHA1";
public RSAPKCS1SHA1SignatureDescription()
{
KeyAlgorithm = typeof(System.Security.Cryptography.RSA).AssemblyQualifiedName;
FormatterAlgorithm = typeof(System.Security.Cryptography.RSAPKCS1SignatureFormatter).AssemblyQualifiedName;
DeformatterAlgorithm = typeof(System.Security.Cryptography.RSAPKCS1SignatureDeformatter).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();
}
}
}

View File

@@ -233,7 +233,7 @@ namespace System.Security.Cryptography.Xml
{
XmlElement transformElement = transformNode as XmlElement;
string algorithm = Utils.GetAttribute(transformElement, "Algorithm", SignedXml.XmlDsigNamespaceUrl);
Transform transform = CryptoConfig.CreateFromName(algorithm) as Transform;
Transform transform = CryptoHelpers.CreateFromName(algorithm) as Transform;
if (transform == null)
throw new CryptographicException(SR.Cryptography_Xml_UnknownTransform);
AddTransform(transform);
@@ -302,7 +302,7 @@ namespace System.Security.Cryptography.Xml
{
// refList is a list of elements that might be targets of references
// Now's the time to create our hashing algorithm
_hashAlgorithm = CryptoConfig.CreateFromName(_digestMethod) as HashAlgorithm;
_hashAlgorithm = CryptoHelpers.CreateFromName(_digestMethod) as HashAlgorithm;
if (_hashAlgorithm == null)
throw new CryptographicException(SR.Cryptography_Xml_CreateHashAlgorithmFailed);

View File

@@ -98,7 +98,7 @@ namespace System.Security.Cryptography.Xml
{
if (_canonicalizationMethodTransform == null)
{
_canonicalizationMethodTransform = CryptoConfig.CreateFromName(CanonicalizationMethod) as Transform;
_canonicalizationMethodTransform = CryptoHelpers.CreateFromName(CanonicalizationMethod) as Transform;
if (_canonicalizationMethodTransform == null)
throw new CryptographicException(string.Format(CultureInfo.CurrentCulture, SR.Cryptography_Xml_CreateTransformFailed, CanonicalizationMethod));
_canonicalizationMethodTransform.SignedXml = SignedXml;

View File

@@ -410,7 +410,7 @@ namespace System.Security.Cryptography.Xml
}
// See if there is a signature description class defined in the Config file
SignatureDescription signatureDescription = CryptoConfig.CreateFromName(SignedInfo.SignatureMethod) as SignatureDescription;
SignatureDescription signatureDescription = CryptoHelpers.CreateFromName(SignedInfo.SignatureMethod) as SignatureDescription;
if (signatureDescription == null)
throw new CryptographicException(SR.Cryptography_Xml_SignatureDescriptionNotCreated);
HashAlgorithm hashAlg = signatureDescription.CreateDigest();
@@ -653,7 +653,7 @@ namespace System.Security.Cryptography.Xml
}
// See if we're signed witn an HMAC algorithm
HMAC hmac = CryptoConfig.CreateFromName(SignatureMethod) as HMAC;
HMAC hmac = CryptoHelpers.CreateFromName(SignatureMethod) as HMAC;
if (hmac == null)
{
// We aren't signed with an HMAC algorithm, so we cannot have a truncated HMAC
@@ -1016,7 +1016,7 @@ namespace System.Security.Cryptography.Xml
SignedXmlDebugLog.LogBeginCheckSignedInfo(this, m_signature.SignedInfo);
SignatureDescription signatureDescription = CryptoConfig.CreateFromName(SignatureMethod) as SignatureDescription;
SignatureDescription signatureDescription = CryptoHelpers.CreateFromName(SignatureMethod) as SignatureDescription;
if (signatureDescription == null)
throw new CryptographicException(SR.Cryptography_Xml_SignatureDescriptionNotCreated);

View File

@@ -705,7 +705,7 @@ namespace System.Security.Cryptography.Xml
reference.Id,
reference.Type,
reference.DigestMethod,
CryptoConfig.CreateFromName(reference.DigestMethod).GetType().Name);
CryptoHelpers.CreateFromName(reference.DigestMethod).GetType().Name);
WriteLine(signedXml,
TraceEventType.Verbose,
@@ -835,7 +835,7 @@ namespace System.Security.Cryptography.Xml
SR.Log_ReferenceHash,
GetObjectId(reference),
reference.DigestMethod,
CryptoConfig.CreateFromName(reference.DigestMethod).GetType().Name,
CryptoHelpers.CreateFromName(reference.DigestMethod).GetType().Name,
FormatBytes(actualHash),
FormatBytes(expectedHash));
@@ -1047,7 +1047,7 @@ namespace System.Security.Cryptography.Xml
SR.Log_SignedXmlRecursionLimit,
GetObjectId(reference),
reference.DigestMethod,
CryptoConfig.CreateFromName(reference.DigestMethod).GetType().Name);
CryptoHelpers.CreateFromName(reference.DigestMethod).GetType().Name);
WriteLine(signedXml,
TraceEventType.Information,

Some files were not shown because too many files have changed in this diff Show More