You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -0,0 +1,38 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25123.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.ProtectedData", "src\System.Security.Cryptography.ProtectedData.csproj", "{FB39F994-1504-4B96-9588-E0385D3B73F1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.ProtectedData.Tests", "tests\System.Security.Cryptography.ProtectedData.Tests.csproj", "{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
net46_Debug|Any CPU = net46_Debug|Any CPU
|
||||
net46_Release|Any CPU = net46_Release|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.net46_Debug|Any CPU.ActiveCfg = net46_Debug|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.net46_Debug|Any CPU.Build.0 = net46_Debug|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.net46_Release|Any CPU.ActiveCfg = net46_Release|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.net46_Release|Any CPU.Build.0 = net46_Release|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
|
||||
{FB39F994-1504-4B96-9588-E0385D3B73F1}.Release|Any CPU.Build.0 = Windows_Release|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.net46_Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.net46_Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.net46_Release|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.net46_Release|Any CPU.Build.0 = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.Release|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}.Release|Any CPU.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
7
external/corefx/src/System.Security.Cryptography.ProtectedData/dir.props
vendored
Normal file
7
external/corefx/src/System.Security.Cryptography.ProtectedData/dir.props
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.0.2.0</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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>
|
||||
<Project Include="System.Security.Cryptography.ProtectedData.pkgproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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>
|
||||
<ProjectReference Include="..\ref\System.Security.Cryptography.ProtectedData.csproj">
|
||||
<SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\src\System.Security.Cryptography.ProtectedData.builds" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InboxOnTargetFramework Include="MonoAndroid10" />
|
||||
<InboxOnTargetFramework Include="MonoTouch10" />
|
||||
<InboxOnTargetFramework Include="xamarinios10" />
|
||||
<InboxOnTargetFramework Include="xamarinmac20" />
|
||||
<InboxOnTargetFramework Include="xamarintvos10" />
|
||||
<InboxOnTargetFramework Include="xamarinwatchos10" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
8
external/corefx/src/System.Security.Cryptography.ProtectedData/ref/Configurations.props
vendored
Normal file
8
external/corefx/src/System.Security.Cryptography.ProtectedData/ref/Configurations.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
public enum DataProtectionScope
|
||||
{
|
||||
CurrentUser = 0,
|
||||
LocalMachine = 1,
|
||||
}
|
||||
public static partial class ProtectedData
|
||||
{
|
||||
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, System.Security.Cryptography.DataProtectionScope scope) { throw null; }
|
||||
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, System.Security.Cryptography.DataProtectionScope scope) { throw null; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?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" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System.Security.Cryptography.ProtectedData.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
12
external/corefx/src/System.Security.Cryptography.ProtectedData/src/Configurations.props
vendored
Normal file
12
external/corefx/src/System.Security.Cryptography.ProtectedData/src/Configurations.props
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
net46-Windows_NT;
|
||||
netstandard1.3-Windows_NT;
|
||||
netstandard1.3-Unix;
|
||||
netstandard-Windows_NT;
|
||||
netstandard-Unix;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
123
external/corefx/src/System.Security.Cryptography.ProtectedData/src/Resources/Strings.resx
vendored
Normal file
123
external/corefx/src/System.Security.Cryptography.ProtectedData/src/Resources/Strings.resx
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
<?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">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Cryptography_DpApi_ProfileMayNotBeLoaded" xml:space="preserve">
|
||||
<value>The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<OSGroup Condition="'$(OSGroup)' == ''">Windows_NT</OSGroup>
|
||||
</PropertyGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{FB39F994-1504-4B96-9588-E0385D3B73F1}</ProjectGuid>
|
||||
<AssemblyName>System.Security.Cryptography.ProtectedData</AssemblyName>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'net46'">true</IsPartialFacadeAssembly>
|
||||
<ResourcesSourceOutputDirectory Condition="'$(TargetGroup)' == 'net46'">None</ResourcesSourceOutputDirectory>
|
||||
<GeneratePlatformNotSupportedAssembly Condition="'$(TargetsUnix)' == 'true'">true</GeneratePlatformNotSupportedAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net46-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net46-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Unix-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Unix-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Unix-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Unix-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Windows_NT-Release|AnyCPU'" />
|
||||
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' AND '$(GeneratePlatformNotSupportedAssembly)' != 'true'">
|
||||
<Compile Include="System\Security\Cryptography\DataProtectionScope.cs" />
|
||||
<Compile Include="System\Security\Cryptography\ProtectedData.cs" />
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.CryptProtectData.cs">
|
||||
<Link>Interop\Windows\Crypt32\Interop.CryptProtectData.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.CryptUnprotectData.cs">
|
||||
<Link>Interop\Windows\Crypt32\Interop.CryptUnprotectData.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.CryptProtectDataFlags.cs">
|
||||
<Link>Interop\Windows\Crypt32\Interop.CryptProtectDataFlags.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\Crypt32\Interop.DATA_BLOB.cs">
|
||||
<Link>Interop\Windows\Crypt32\Interop.DATA_BLOB.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Errors.cs">
|
||||
<Link>Interop\Windows\Interop.Errors.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Internal\Cryptography\Windows\CryptoThrowHelper.cs">
|
||||
<Link>Internal\Cryptography\Windows\CryptoThrowHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.FormatMessage.cs">
|
||||
<Link>Internal\Windows\kernel32\Interop.FormatMessage.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\Interop.Libraries.cs">
|
||||
<Link>Common\Interop\Windows\Interop.Libraries.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'net46'">
|
||||
<TargetingPackReference Include="mscorlib" />
|
||||
<TargetingPackReference Include="System.Security" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Diagnostics.Tools" />
|
||||
<Reference Include="System.Resources.ResourceManager" />
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.InteropServices" />
|
||||
<Reference Include="System.Security.Cryptography.Primitives" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
public enum DataProtectionScope
|
||||
{
|
||||
CurrentUser = 0,
|
||||
LocalMachine = 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// 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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Internal.Cryptography;
|
||||
|
||||
using DATA_BLOB = Interop.Crypt32.DATA_BLOB;
|
||||
using CryptProtectDataFlags = Interop.Crypt32.CryptProtectDataFlags;
|
||||
|
||||
namespace System.Security.Cryptography
|
||||
{
|
||||
public static partial class ProtectedData
|
||||
{
|
||||
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
if (userData == null)
|
||||
throw new ArgumentNullException(nameof(userData));
|
||||
|
||||
return ProtectOrUnprotect(userData, optionalEntropy, scope, protect: true);
|
||||
}
|
||||
|
||||
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)
|
||||
{
|
||||
if (encryptedData == null)
|
||||
throw new ArgumentNullException(nameof(encryptedData));
|
||||
|
||||
return ProtectOrUnprotect(encryptedData, optionalEntropy, scope, protect: false);
|
||||
}
|
||||
|
||||
private static byte[] ProtectOrUnprotect(byte[] inputData, byte[] optionalEntropy, DataProtectionScope scope, bool protect)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* pInputData = inputData, pOptionalEntropy = optionalEntropy)
|
||||
{
|
||||
DATA_BLOB userDataBlob = new DATA_BLOB((IntPtr)pInputData, (uint)(inputData.Length));
|
||||
DATA_BLOB optionalEntropyBlob = default(DATA_BLOB);
|
||||
if (optionalEntropy != null)
|
||||
{
|
||||
optionalEntropyBlob = new DATA_BLOB((IntPtr)pOptionalEntropy, (uint)(optionalEntropy.Length));
|
||||
}
|
||||
|
||||
// For desktop compat, we ignore unknown bits in the "scope" value rather than throwing.
|
||||
CryptProtectDataFlags flags = CryptProtectDataFlags.CRYPTPROTECT_UI_FORBIDDEN;
|
||||
if (scope == DataProtectionScope.LocalMachine)
|
||||
{
|
||||
flags |= CryptProtectDataFlags.CRYPTPROTECT_LOCAL_MACHINE;
|
||||
}
|
||||
|
||||
DATA_BLOB outputBlob = default(DATA_BLOB);
|
||||
try
|
||||
{
|
||||
bool success = protect ?
|
||||
Interop.Crypt32.CryptProtectData(ref userDataBlob, null, ref optionalEntropyBlob, IntPtr.Zero, IntPtr.Zero, flags, out outputBlob) :
|
||||
Interop.Crypt32.CryptUnprotectData(ref userDataBlob, IntPtr.Zero, ref optionalEntropyBlob, IntPtr.Zero, IntPtr.Zero, flags, out outputBlob);
|
||||
if (!success)
|
||||
{
|
||||
int lastWin32Error = Marshal.GetLastWin32Error();
|
||||
if (protect && ErrorMayBeCausedByUnloadedProfile(lastWin32Error))
|
||||
throw new CryptographicException(SR.Cryptography_DpApi_ProfileMayNotBeLoaded);
|
||||
else
|
||||
throw lastWin32Error.ToCryptographicException();
|
||||
}
|
||||
|
||||
// In some cases, the API would fail due to OOM but simply return a null pointer.
|
||||
if (outputBlob.pbData == IntPtr.Zero)
|
||||
throw new OutOfMemoryException();
|
||||
|
||||
int length = (int)(outputBlob.cbData);
|
||||
byte[] outputBytes = new byte[length];
|
||||
Marshal.Copy(outputBlob.pbData, outputBytes, 0, length);
|
||||
return outputBytes;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (outputBlob.pbData != IntPtr.Zero)
|
||||
{
|
||||
int length = (int)(outputBlob.cbData);
|
||||
byte* pOutputData = (byte*)(outputBlob.pbData);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
pOutputData[i] = 0;
|
||||
}
|
||||
Marshal.FreeHGlobal(outputBlob.pbData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if an error code may have been caused by trying to do a crypto operation while the
|
||||
// current user's profile is not yet loaded.
|
||||
private static bool ErrorMayBeCausedByUnloadedProfile(int errorCode)
|
||||
{
|
||||
// CAPI returns a file not found error if the user profile is not yet loaded
|
||||
return errorCode == Interop.Errors.E_FILENOTFOUND ||
|
||||
errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
external/corefx/src/System.Security.Cryptography.ProtectedData/tests/Configurations.props
vendored
Normal file
8
external/corefx/src/System.Security.Cryptography.ProtectedData/tests/Configurations.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard1.3-Windows_NT;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
79
external/corefx/src/System.Security.Cryptography.ProtectedData/tests/ProtectedDataTests.cs
vendored
Normal file
79
external/corefx/src/System.Security.Cryptography.ProtectedData/tests/ProtectedDataTests.cs
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
// 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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using Test.Cryptography;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Security.Cryptography.ProtectedDataTests
|
||||
{
|
||||
public static class ProtectedDataTests
|
||||
{
|
||||
[Fact]
|
||||
public static void RoundTrip()
|
||||
{
|
||||
RoundTrip(null);
|
||||
RoundTrip(new byte[] { 4, 5, 6 });
|
||||
}
|
||||
|
||||
private static void RoundTrip(byte[] entropy)
|
||||
{
|
||||
foreach (DataProtectionScope scope in new DataProtectionScope[] { DataProtectionScope.CurrentUser, DataProtectionScope.LocalMachine })
|
||||
{
|
||||
byte[] plain = { 1, 2, 3 };
|
||||
byte[] encrypted = ProtectedData.Protect(plain, entropy, scope);
|
||||
Assert.NotEqual<byte>(plain, encrypted);
|
||||
byte[] recovered = ProtectedData.Unprotect(encrypted, entropy, scope);
|
||||
Assert.Equal<byte>(plain, recovered);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void NullEntropyEquivalence()
|
||||
{
|
||||
// Passing a zero-length array as entropy is equivalent to passing null as entropy.
|
||||
byte[] plain = { 1, 2, 3 };
|
||||
byte[] nullEntropy = { };
|
||||
byte[] encrypted = ProtectedData.Protect(plain, null, DataProtectionScope.CurrentUser);
|
||||
byte[] recovered = ProtectedData.Unprotect(encrypted, nullEntropy, DataProtectionScope.CurrentUser);
|
||||
Assert.Equal<byte>(plain, recovered);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void NullEntropyEquivalence2()
|
||||
{
|
||||
// Passing a zero-length array as entropy is equivalent to passing null as entropy.
|
||||
byte[] plain = { 1, 2, 3 };
|
||||
byte[] nullEntropy = { };
|
||||
byte[] encrypted = ProtectedData.Protect(plain, nullEntropy, DataProtectionScope.CurrentUser);
|
||||
byte[] recovered = ProtectedData.Unprotect(encrypted, null, DataProtectionScope.CurrentUser);
|
||||
Assert.Equal<byte>(plain, recovered);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void WrongEntropy()
|
||||
{
|
||||
// Passing a zero-length array as entropy is equivalent to passing null as entropy.
|
||||
byte[] entropy1 = { 4, 5, 6 };
|
||||
byte[] entropy2 = { 4, 5, 7 };
|
||||
WrongEntropy(null, entropy1);
|
||||
WrongEntropy(entropy1, null);
|
||||
WrongEntropy(entropy1, entropy2);
|
||||
}
|
||||
|
||||
private static void WrongEntropy(byte[] entropy1, byte[] entropy2)
|
||||
{
|
||||
foreach (DataProtectionScope scope in new DataProtectionScope[] { DataProtectionScope.CurrentUser, DataProtectionScope.LocalMachine })
|
||||
{
|
||||
byte[] plain = { 1, 2, 3 };
|
||||
byte[] encrypted = ProtectedData.Protect(plain, entropy1, scope);
|
||||
Assert.ThrowsAny<CryptographicException>(() => ProtectedData.Unprotect(encrypted, entropy2, scope));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?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>
|
||||
<Project Include="System.Security.Cryptography.ProtectedData.Tests.csproj">
|
||||
<OSGroup>Windows_NT</OSGroup>
|
||||
<TestTFMs>netcoreapp;netcore50;netcoreapp1.0;net46</TestTFMs>
|
||||
</Project>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{749ED7AD-E3C1-4611-99BD-C5D4B3934B3A}</ProjectGuid>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.3-Windows_NT-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="ProtectedDataTests.cs" />
|
||||
<Compile Include="$(CommonTestPath)\System\Security\Cryptography\ByteUtils.cs">
|
||||
<Link>CommonTest\System\Security\Cryptography\ByteUtils.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user