Skip to content

Commit bcf7319

Browse files
MackinnonBuckSteveSandersonMSTratcherTanayParikhJamesNK
authored
Update SDK to 7.0.100-rc.2.22419.24 (#43028)
- {lots of different SDK versions tried} - Validate DataProtection custom algorithm has a constructor - Additional fixes - Suppress IL2121 - Fix NoWarn overrides - Update LinkabilityChecker.csproj - Update WasmLinkerTest.csproj - Bump SDK version yet again - Hack to stop using `msbuild` server - please open an issue to keep trying to remove this - Disable msbuild server for source-build job Co-authored-by: Steve Sanderson <[email protected]> Co-authored-by: Chris Ross <[email protected]> Co-authored-by: Tanay Parikh <[email protected]> Co-authored-by: James Newton-King <[email protected]> Co-authored-by: Sébastien Ros <[email protected]> Co-authored-by: Doug Bunting <[email protected]> Co-authored-by: Safia Abdalla <[email protected]>
1 parent 5659774 commit bcf7319

File tree

18 files changed

+167
-76
lines changed

18 files changed

+167
-76
lines changed

.azure/pipelines/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,13 @@ stages:
733733
container: 'mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7-20210714125435-9b5bbc2'
734734
buildScript: './eng/build.sh $(_PublishArgs) --no-build-repo-tasks'
735735
skipPublishValidation: true
736-
timeoutInMinutes: 120
736+
jobProperties:
737+
timeoutInMinutes: 120
738+
variables:
739+
# !temporary! Remove as soon as .NET SDK includes a new-enough `msbuild` to make this hack unnecessary
740+
DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER: true
741+
# Log environment variables in binary logs to ease debugging
742+
MSBUILDLOGALLENVIRONMENTVARIABLES: true
737743

738744
# Publish to the BAR and perform source indexing. Wait until everything else is done.
739745
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:

.azure/pipelines/jobs/default-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ jobs:
220220
# Include the variables we always want.
221221
COMPlus_DbgEnableMiniDump: 1
222222
COMPlus_DbgMiniDumpName: "$(System.DefaultWorkingDirectory)/dotnet-%d.%t.core"
223+
# !temporary! Remove as soon as .NET SDK includes a new-enough `msbuild` to make this hack unnecessary
224+
DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER: true
223225
# Expand provided `env:` properties, if any.
224226
${{ if step.env }}:
225227
${{ step.env }}
@@ -231,12 +233,16 @@ jobs:
231233
env:
232234
COMPlus_DbgEnableMiniDump: 1
233235
COMPlus_DbgMiniDumpName: "$(System.DefaultWorkingDirectory)/dotnet-%d.%t.core"
236+
# !temporary! Remove as soon as .NET SDK includes a new-enough `msbuild` to make this hack unnecessary
237+
DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER: true
234238
- ${{ if ne(parameters.agentOs, 'Windows') }}:
235239
- script: $(BuildDirectory)/build.sh --ci --nobl --configuration $(BuildConfiguration) $(BuildScriptArgs)
236240
displayName: Run build.sh
237241
env:
238242
COMPlus_DbgEnableMiniDump: 1
239243
COMPlus_DbgMiniDumpName: "$(System.DefaultWorkingDirectory)/dotnet-%d.%t.core"
244+
# !temporary! Remove as soon as .NET SDK includes a new-enough `msbuild` to make this hack unnecessary
245+
DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER: true
240246

241247
- ${{ parameters.afterBuild }}
242248

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119

120120
<!-- xUnit1004 = warns about skipped tests. Make this a non-fatal build warning. -->
121121
<WarningsNotAsErrors>$(WarningsNotAsErrors);xUnit1004</WarningsNotAsErrors>
122+
123+
<!-- don't warn about unnecessary trim warning suppressions. can be removed with preview 6. -->
124+
<NoWarn>$(NoWarn);IL2121</NoWarn>
122125
</PropertyGroup>
123126

124127
<!-- Source code settings -->

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"sdk": {
3-
"version": "7.0.100-rc.1.22375.2"
3+
"version": "7.0.100-rc.2.22426.5"
44
},
55
"tools": {
6-
"dotnet": "7.0.100-rc.1.22375.2",
6+
"dotnet": "7.0.100-rc.2.22426.5",
77
"runtimes": {
88
"dotnet/x86": [
99
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"

src/Components/WebAssembly/testassets/Wasm.Authentication.Server/Wasm.Authentication.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
55

66
<!-- IdentityServer packages are not strong named. -->
7-
<NoWarn>CS8002</NoWarn>
7+
<NoWarn>$(NoWarn);CS8002</NoWarn>
88
<!-- This project references the shared framework transitively. Prevent restore errors by setting this flag. -->
99
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
1010
<IdentityDefaultUIFramework>Bootstrap5</IdentityDefaultUIFramework>

src/Components/WebAssembly/testassets/WasmLinkerTest/WasmLinkerTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
OutputDirectory="$(LibrariesTrimmedArtifactsPath)"
5353
ReferenceAssemblyPaths="@(RuntimePackAsset);@(ReferencePath->WithMetadataValue('ExternallyResolved', 'true'))"
5454
ExtraArgs="$(ILLinkArgs)"
55+
NoWarn="$(NoWarn)"
5556
TrimMode="link"
5657
ToolExe="$(_DotNetHostFileName)"
5758
ToolPath="$(_DotNetHostDirectory)" />

src/DataProtection/DataProtection/src/AuthenticatedEncryption/AuthenticatedEncryptorFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ private static string GetBCryptAlgorithmNameFromValidationAlgorithm(ValidationAl
163163
}
164164
}
165165

166+
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
166167
private static Type GetManagedTypeFromEncryptionAlgorithm(EncryptionAlgorithm algorithm)
167168
{
168169
switch (algorithm)
@@ -180,6 +181,7 @@ private static Type GetManagedTypeFromEncryptionAlgorithm(EncryptionAlgorithm al
180181
}
181182
}
182183

184+
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
183185
private static Type GetManagedTypeFromValidationAlgorithm(ValidationAlgorithm algorithm)
184186
{
185187
switch (algorithm)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
7+
using System.Security.Cryptography;
8+
using System.Xml.Linq;
9+
10+
namespace Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
11+
12+
internal static class ManagedAlgorithmHelpers
13+
{
14+
private static readonly List<Type> KnownAlgorithmTypes = new List<Type>
15+
{
16+
typeof(Aes),
17+
typeof(HMACSHA1),
18+
typeof(HMACSHA256),
19+
typeof(HMACSHA384),
20+
typeof(HMACSHA512)
21+
};
22+
23+
// Any changes to this method should also be be reflected in FriendlyNameToType.
24+
public static string TypeToFriendlyName(Type type)
25+
{
26+
if (KnownAlgorithmTypes.Contains(type))
27+
{
28+
return type.Name;
29+
}
30+
else
31+
{
32+
return type.AssemblyQualifiedName!;
33+
}
34+
}
35+
36+
// Any changes to this method should also be be reflected in TypeToFriendlyName.
37+
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
38+
[UnconditionalSuppressMessage("Trimmer", "IL2075", Justification = "Unknown type is checked for whether it has a public parameterless constructor. Handle trimmed types by providing a useful error message.")]
39+
[UnconditionalSuppressMessage("Trimmer", "IL2073", Justification = "Unknown type is checked for whether it has a public parameterless constructor. Handle trimmed types by providing a useful error message.")]
40+
public static Type FriendlyNameToType(string typeName)
41+
{
42+
foreach (var knownType in KnownAlgorithmTypes)
43+
{
44+
if (knownType.Name == typeName)
45+
{
46+
return knownType;
47+
}
48+
}
49+
50+
var type = TypeExtensions.GetTypeWithTrimFriendlyErrorMessage(typeName);
51+
52+
// Type name could be full or assembly qualified name of known type.
53+
if (KnownAlgorithmTypes.Contains(type))
54+
{
55+
return type;
56+
}
57+
58+
// All other types are created using Activator.CreateInstance. Validate it has a valid constructor.
59+
if (type.GetConstructor(Type.EmptyTypes) == null)
60+
{
61+
throw new InvalidOperationException($"Algorithm type {type} doesn't have a public parameterless constructor. If the app is published with trimming then the constructor may have been trimmed. Ensure the type's assembly is excluded from trimming.");
62+
}
63+
64+
return type;
65+
}
66+
}

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/ManagedAuthenticatedEncryptorConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Security.Cryptography;
67
using Microsoft.Extensions.Logging.Abstractions;
78

@@ -24,6 +25,7 @@ public sealed class ManagedAuthenticatedEncryptorConfiguration : AlgorithmConfig
2425
/// The default algorithm is AES.
2526
/// </remarks>
2627
[ApplyPolicy]
28+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
2729
public Type EncryptionAlgorithmType { get; set; } = typeof(Aes);
2830

2931
/// <summary>
@@ -47,6 +49,7 @@ public sealed class ManagedAuthenticatedEncryptorConfiguration : AlgorithmConfig
4749
/// The default algorithm is HMACSHA256.
4850
/// </remarks>
4951
[ApplyPolicy]
52+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
5053
public Type ValidationAlgorithmType { get; set; } = typeof(HMACSHA256);
5154

5255
/// <inheritdoc />

src/DataProtection/DataProtection/src/AuthenticatedEncryption/ConfigurationModel/ManagedAuthenticatedEncryptorDescriptor.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public XmlSerializedDescriptorInfo ExportToXml()
4949
// </descriptor>
5050

5151
var encryptionElement = new XElement("encryption",
52-
new XAttribute("algorithm", TypeToFriendlyName(Configuration.EncryptionAlgorithmType)),
52+
new XAttribute("algorithm", ManagedAlgorithmHelpers.TypeToFriendlyName(Configuration.EncryptionAlgorithmType)),
5353
new XAttribute("keyLength", Configuration.EncryptionAlgorithmKeySize));
5454

5555
var validationElement = new XElement("validation",
56-
new XAttribute("algorithm", TypeToFriendlyName(Configuration.ValidationAlgorithmType)));
56+
new XAttribute("algorithm", ManagedAlgorithmHelpers.TypeToFriendlyName(Configuration.ValidationAlgorithmType)));
5757

5858
var rootElement = new XElement("descriptor",
5959
new XComment(" Algorithms provided by specified SymmetricAlgorithm and KeyedHashAlgorithm "),
@@ -63,34 +63,4 @@ public XmlSerializedDescriptorInfo ExportToXml()
6363

6464
return new XmlSerializedDescriptorInfo(rootElement, typeof(ManagedAuthenticatedEncryptorDescriptorDeserializer));
6565
}
66-
67-
// Any changes to this method should also be be reflected
68-
// in ManagedAuthenticatedEncryptorDescriptorDeserializer.FriendlyNameToType.
69-
private static string TypeToFriendlyName(Type type)
70-
{
71-
if (type == typeof(Aes))
72-
{
73-
return nameof(Aes);
74-
}
75-
else if (type == typeof(HMACSHA1))
76-
{
77-
return nameof(HMACSHA1);
78-
}
79-
else if (type == typeof(HMACSHA256))
80-
{
81-
return nameof(HMACSHA256);
82-
}
83-
else if (type == typeof(HMACSHA384))
84-
{
85-
return nameof(HMACSHA384);
86-
}
87-
else if (type == typeof(HMACSHA512))
88-
{
89-
return nameof(HMACSHA512);
90-
}
91-
else
92-
{
93-
return type.AssemblyQualifiedName!;
94-
}
95-
}
9666
}

0 commit comments

Comments
 (0)