forked from dotnet/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure DataProtection can be used in trimmed apps. (dotnet#48082)
* Add a DynamicDependency to ensure Aes decryption works in EncryptedXmlDecryptor * Suppress the warnings from EncryptedXml * Add trimming tests to ensure these scenarios work correctly. * Remove the RequiresUnreferencedCode attribute on AddAuthentication, since this is the only thing in that method that has warnings. Fix dotnet#47695 * Fix parallel build to not copy files to the same destination
- Loading branch information
Showing
71 changed files
with
373 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
...Protection/DataProtection/src/Microsoft.AspNetCore.DataProtection.WarningSuppressions.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
94 changes: 94 additions & 0 deletions
94
...ection/DataProtection/test/Microsoft.AspNetCore.DataProtection.TrimmingTests/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
internal static class Constants | ||
{ | ||
public const string Password = "password"; | ||
|
||
public const string Key = | ||
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Suppression approved. Dummy certificate for testing.")] | ||
@"MIIKPgIBAzCCCfoGCSqGSIb3DQEHAaCCCesEggnnMIIJ4zCCBgwGCSqGSIb3DQEHAaCCBf0EggX5 | ||
MIIF9TCCBfEGCyqGSIb3DQEMCgECoIIE/jCCBPowHAYKKoZIhvcNAQwBAzAOBAijQh1kbOZOYQIC | ||
B9AEggTY+wDp3V31Lh7f8YrsqEsyGZ+GlYvFhLWvDASjisYJi5NlQ0ONbf0KO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SmZboU | ||
35iV7s5brC67ChbRIJk2cq/odioWyxVoKjAIZmH+e08QYc6mZRRgce6VVbk8R9Lh9/wkd2u9IIbd | ||
NP5hynCdo85eTjJ4RaF8LGJwK45Jkw3jIghcKePkLzQIN03OGKm2+YjQV18M3UtlB7cti4JwZJCL | ||
MDswHzAHBgUrDgMCGgQUvUM7Kw/8NN+1PlObSrj4zZwINasEFNL9LO5HLwrmwm/xDlNMw1KASQOL | ||
AgIH0A=="; | ||
|
||
public const string KeyRingXmlFileName = "key-9c15d488-4417-49ab-ae39-ed2f36a9ebe3.xml"; | ||
public const string KeyRingXmlContents = """ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<key id="9c15d488-4417-49ab-ae39-ed2f36a9ebe3" version="1"> | ||
<creationDate>2023-05-04T19:16:30.3590154Z</creationDate> | ||
<activationDate>2023-05-04T19:16:30.3487875Z</activationDate> | ||
<expirationDate>2115-08-02T19:16:30.3487875Z</expirationDate> | ||
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection"> | ||
<descriptor> | ||
<encryption algorithm="AES_256_CBC" /> | ||
<validation algorithm="HMACSHA256" /> | ||
<encryptedSecret decryptorType="Microsoft.AspNetCore.DataProtection.XmlEncryption.EncryptedXmlDecryptor, Microsoft.AspNetCore.DataProtection" xmlns="http://schemas.asp.net/2015/03/dataProtection"> | ||
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> | ||
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" /> | ||
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> | ||
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"> | ||
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> | ||
<KeyInfo xmlns="http://www.w3.org/2000/09/xmld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Data> | ||
</KeyInfo> | ||
<CipherData> | ||
<CipherValue>ahdd65gng0TzxZ/6Nw1zLvqFi3lsvz4tvAF4pBz7BZCqTHbTzaRnK5rMWSP9wEk8fa0LN9CGw7y1QxKfuPneTooYogDPGdVc6T8IbmASGfQI1SZZy7yOkF4IcTz9txJ4wbcjf4hUXPvYeBb0l1QlvKLh0BpXquhZqeM8Gat4IXz1iQbTCB31regpmeDSGJz6ok1ZFhjn0v4K5YvXucofxTmh+0aONveMWyadp56dP4KJVM5x4z6UddiFdVlk4euuSX6qbVHI7eA4UGSdnu8lsbBa5aiypS0kRO8NGyab+nSY907hn8E7mUCc9MjyS/QwFSZyT3y88q0pb1bK8zL8tA==</CipherValue> | ||
</CipherData> | ||
</EncryptedKey> | ||
</KeyInfo> | ||
<CipherData> | ||
<CipherValue>YTcCujeLvS47fgVUWLUC9FaZJDp+MSMtuxAkUWfAh5xnbKI8i0dFulIftz+lykfx+/1dMmQ/GsFSbbqhjCG6GDUKz5/eBXEg/It9Vagu9y0UTlrfj0dLaSG7jaw+wNY9DXTsvRtIHkEI0XQHWr0HqkJYVDfiA4yRZu2Sfue9nSmIZFMhCZOP286hJ0JFsqX1+phX3sR6JX31mGKopltlAsIGgL8MRTXWp5tZxuk9W+sgoWfJziDYmrPP2P6eMn7AdX4T+TDbuAY7MtaExL8Itv8WeKN34lxXocT7hRIjHaZMfiqocDX6YcIjnYhgeKQ1XlFo4j4fZ/p4PwxMmXdhrr/yAhzPhhOt6kqncsNnfVWbPS6+dh+3XE6/K0Oa2B5avbYKOv21KU69mSaXc4EsPA==</CipherValue> | ||
</CipherData> | ||
</EncryptedData> | ||
</encryptedSecret> | ||
</descriptor> | ||
</descriptor> | ||
</key> | ||
"""; | ||
} |
12 changes: 12 additions & 0 deletions
12
...tCore.DataProtection.TrimmingTests/Microsoft.AspNetCore.DataProtection.TrimmingTests.proj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Include="TestCertificateXmlEncryptor.cs" | ||
AdditionalSourceFiles="Constants.cs" /> | ||
<TestConsoleAppSourceFiles Include="TestEncryptedXmlDecryptor.cs" | ||
AdditionalSourceFiles="Constants.cs" /> | ||
<TestConsoleAppSourceFiles Include="TestUnprotectWorksWithX509Certificate.cs" | ||
AdditionalSourceFiles="Constants.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
31 changes: 31 additions & 0 deletions
31
...ion/test/Microsoft.AspNetCore.DataProtection.TrimmingTests/TestCertificateXmlEncryptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.DataProtection.XmlEncryption; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using System; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Xml.Linq; | ||
|
||
var cert = new X509Certificate2(Convert.FromBase64String(Constants.Key), Constants.Password); | ||
|
||
var encryptor = new CertificateXmlEncryptor(cert, NullLoggerFactory.Instance); | ||
|
||
var e = XElement.Parse(""" | ||
<root> | ||
<child Value="hi" /> | ||
</root> | ||
"""); | ||
|
||
var result = encryptor.Encrypt(e); | ||
|
||
if (result.DecryptorType.Name != "EncryptedXmlDecryptor") | ||
{ | ||
return -1; | ||
} | ||
if (result.EncryptedElement.Name.LocalName != "EncryptedData") | ||
{ | ||
return -2; | ||
} | ||
|
||
return 100; |
Oops, something went wrong.