Skip to content

Commit

Permalink
Update DerivedTypes.cs
Browse files Browse the repository at this point in the history
add net8.0 target

Put CustomKey and a custom converter for SecurityKey in TestUtils,
transition aot test to net8.0
  • Loading branch information
westin-m committed Jun 9, 2023
1 parent a5b252a commit 059b573
Show file tree
Hide file tree
Showing 52 changed files with 291 additions and 62 deletions.
7 changes: 6 additions & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>


<PropertyGroup>
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
<NoWarn>$(NoWarn);SYSLIB0051</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="$(MicrosoftSourceLinkGitHubVersion)" PrivateAssets="All"/>
</ItemGroup>
Expand Down
9 changes: 7 additions & 2 deletions build/commonTest.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.1'">$(DotNetCoreAppRuntimeVersion)</RuntimeFrameworkVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net8.0'">
<DefineConstants>$(DefineConstants);NET_CORE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'net6.0'">
<PropertyGroup>
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
<NoWarn>$(NoWarn);SYSLIB0051</NoWarn>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
</ItemGroup>

Expand Down
12 changes: 10 additions & 2 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<AspNetCoreMinSupportedVersion>2.1.1</AspNetCoreMinSupportedVersion>
<MicrosoftAzureKeyVaultVersion>3.0.5</MicrosoftAzureKeyVaultVersion>
<MicrosoftAzureServicesAppAuthenticationVersion>1.0.3</MicrosoftAzureServicesAppAuthenticationVersion>
<MicrosoftCSharpVersion>4.5.0</MicrosoftCSharpVersion>
<MicrosoftSourceLinkGitHubVersion>1.0.0</MicrosoftSourceLinkGitHubVersion>
<NetStandardVersion>2.0.3</NetStandardVersion>
<SystemCollectionsSpecializedVersion>4.3.0</SystemCollectionsSpecializedVersion>
Expand All @@ -15,10 +14,19 @@
<SystemRuntimeSerializationPrimitivesVersion>4.3.0</SystemRuntimeSerializationPrimitivesVersion>
<SystemRuntimeSerializationXmlVersion>4.3.0</SystemRuntimeSerializationXmlVersion>
<SystemSecurityClaimsVersion>4.3.0</SystemSecurityClaimsVersion>
<SystemSecurityCryptographyCngVersion>4.5.0</SystemSecurityCryptographyCngVersion>
<SystemTextEncoding>4.3.0</SystemTextEncoding>
<SystemTextJson>4.7.2</SystemTextJson>
<SystemTextEncodingsWeb>4.7.2</SystemTextEncodingsWeb>
<SystemXmlXmlDocumentVersion>4.3.0</SystemXmlXmlDocumentVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<SystemSecurityCryptographyCngVersion>5.0.0</SystemSecurityCryptographyCngVersion>
<MicrosoftCSharpVersion>4.7.0</MicrosoftCSharpVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'net8.0'">
<SystemSecurityCryptographyCngVersion>4.5.0</SystemSecurityCryptographyCngVersion>
<MicrosoftCSharpVersion>4.5.0</MicrosoftCSharpVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion build/targets.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<SrcTargets>net461;net462;net472;netstandard2.0;net6.0</SrcTargets>
<SrcTargets>net461;net462;net472;netstandard2.0;net6.0;net8.0</SrcTargets>
<SrcStandardTargets>netstandard2.0</SrcStandardTargets>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion build/targetsTest.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TestTargets>net461;net462;net472;netcoreapp2.1;net6.0</TestTargets>
<TestTargets>net461;net462;net472;netcoreapp2.1;net6.0;net8.0</TestTargets>
<TestOnlyCoreTargets>netcoreapp2.1</TestOnlyCoreTargets>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ internal IEnumerable<SecurityKey> GetContentEncryptionKeys(JsonWebToken jwtToken
{
try
{
#if NET472 || NET6_0
#if NET472 || NET6_0 || NET8_0
if (SupportedAlgorithms.EcdsaWrapAlgorithms.Contains(jwtToken.Alg))
{
// on decryption we get the public key from the EPK value see: https://datatracker.ietf.org/doc/html/rfc7518#appendix-C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ internal static SecurityKey GetSecurityKey(

securityKey = encryptingCredentials.Key;
}
#if NET472 || NET6_0
#if NET472 || NET6_0 || NET8_0
else if (SupportedAlgorithms.EcdsaWrapAlgorithms.Contains(encryptingCredentials.Alg))
{
// on decryption we get the public key from the EPK value see: https://datatracker.ietf.org/doc/html/rfc7518#appendix-C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<ProjectReference Include="..\Microsoft.IdentityModel.Tokens\Microsoft.IdentityModel.Tokens.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'net6.0'">
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Text.Encoding" Version="$(SystemTextEncoding)" />
<PackageReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWeb)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJson)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
<PackageId>Microsoft.IdentityModel.KeyVaultExtensions</PackageId>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<PackageTags>.NET;Windows;Authentication;Identity;Azure;Key;Vault;Extensions</PackageTags>
</PropertyGroup>

Expand All @@ -30,4 +30,4 @@
<ProjectReference Include="..\Microsoft.IdentityModel.Tokens\Microsoft.IdentityModel.Tokens.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static class IdentityModelTelemetryUtil
"ID_NETSTANDARD2_0";
#elif NET6_0
"ID_NET6_0";
#elif NET8_0
"ID_NET8_0";
#endif

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net6.0'">
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472' Or '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Text.Encoding" Version="$(SystemTextEncoding)" />
<PackageReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWeb)" />
<PackageReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWeb)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJson)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net6.0'">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Net.Http" Version="$(SystemNetHttpVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Doesn't own object", Scope = "member", Target = "~M:Microsoft.IdentityModel.Protocols.WsFederation.WsFederationMetadataSerializer.ReadEntityDescriptor(System.Xml.XmlReader)~Microsoft.IdentityModel.Protocols.WsFederation.WsFederationConfiguration")]

[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Breaking change", Scope = "member", Target = "~P:Microsoft.IdentityModel.Protocols.WsFederation.SecurityTokenServiceTypeRoleDescriptor.KeyInfos")]
#if NET6_0
#if NET6_0 || NET8_0
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Adding StringComparison.Ordinal adds a performance penalty.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Protocols.WsFederation.QueryHelper.ParseNullableQuery(System.String)~System.Collections.Generic.IDictionary{System.String,System.Collections.Generic.IList{System.String}}")]
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ProjectReference Include="..\Microsoft.IdentityModel.Xml\Microsoft.IdentityModel.Xml.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net6.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Xml.XmlDocument" Version="$(SystemXmlXmlDocumentVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
[assembly: SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Previously released as returning an array", Scope = "member", Target = "~P:Microsoft.IdentityModel.Protocols.HttpRequestData.Body")]
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Previously released read/write", Scope = "member", Target = "~P:Microsoft.IdentityModel.Protocols.HttpRequestData.Headers")]
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Previously released read/write", Scope = "member", Target = "~P:Microsoft.IdentityModel.Protocols.HttpRequestData.PropertyBag")]
#if NET6_0
#if NET6_0 || NET8_0
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Adding StringComparison.Ordinal adds a performance penalty.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Protocols.AuthenticationProtocolMessage.BuildRedirectUrl~System.String")]
#endif
8 changes: 4 additions & 4 deletions src/Microsoft.IdentityModel.Tokens/AsymmetricAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection;
#endif

#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0
#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
using System.Security.Cryptography.X509Certificates;
#endif

Expand Down Expand Up @@ -215,7 +215,7 @@ private void InitializeUsingRsa(RSA rsa, string algorithm)
}
#endif

#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0
#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
if (algorithm.Equals(SecurityAlgorithms.RsaSsaPssSha256) ||
algorithm.Equals(SecurityAlgorithms.RsaSsaPssSha256Signature) ||
algorithm.Equals(SecurityAlgorithms.RsaSsaPssSha384) ||
Expand Down Expand Up @@ -251,7 +251,7 @@ private void InitializeUsingRsaSecurityKey(RsaSecurityKey rsaSecurityKey, string
}
else
{
#if NET472 || NET6_0
#if NET472 || NET6_0 || NET8_0
var rsa = RSA.Create(rsaSecurityKey.Parameters);
#else
var rsa = RSA.Create();
Expand Down Expand Up @@ -321,7 +321,7 @@ private bool VerifyWithECDsaWithLength(byte[] bytes, int start, int length, byte
}

#region NET61+ related code
#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0
#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0

// HasAlgorithmName was introduced into Net46
internal AsymmetricAdapter(SecurityKey key, string algorithm, HashAlgorithm hashAlgorithm, HashAlgorithmName hashAlgorithmName, bool requirePrivateKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private static PrivateKeyStatus FoundPrivateKey(SecurityKey key)
return PrivateKeyStatus.Unknown;
}

#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0
#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
/// <summary>
/// Creating a Signature requires the use of a <see cref="HashAlgorithm"/>.
/// This method returns the <see cref="HashAlgorithmName"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public virtual SignatureProvider CreateForVerifying(SecurityKey key, string algo
return CreateSignatureProvider(key, algorithm, false, cacheProvider);
}

#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0
#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
/// <summary>
/// Creates a <see cref="HashAlgorithm"/> for a specific algorithm.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.IdentityModel.Tokens/ECDsaAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class ECDsaAdapter
/// </exception>
internal ECDsaAdapter()
{
#if NET472 || NET6_0
#if NET472 || NET6_0 || NET8_0
CreateECDsaFunction = CreateECDsaUsingECParams;
#elif NETSTANDARD2_0
// Although NETSTANDARD2_0 specifies that ECParameters are supported, we still need to call SupportsECParameters()
Expand Down Expand Up @@ -256,7 +256,7 @@ private static bool SupportsCNGKey()
}
}

#if NET472 || NETSTANDARD2_0 || NET6_0
#if NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
/// <summary>
/// Creates an ECDsa object using the <paramref name="jsonWebKey"/> and <paramref name="usePrivateKey"/>.
/// 'ECParameters' structure is available in .NET Framework 4.7+, .NET Standard 1.6+, and .NET Core 1.0+.
Expand Down Expand Up @@ -344,7 +344,7 @@ internal static string GetCrvParameterValue(ECCurve curve)
/// <returns>True if <see cref="ECParameters"/> structure is supported, false otherwise.</returns>
internal static bool SupportsECParameters()
{
#if NET472 || NET6_0
#if NET472 || NET6_0 || NET8_0
return true;
#else
try
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.IdentityModel.Tokens/ECDsaSecurityKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override int KeySize
/// <remarks>https://datatracker.ietf.org/doc/html/rfc7638</remarks>
public override bool CanComputeJwkThumbprint()
{
#if NET472 || NETSTANDARD2_0 || NET6_0
#if NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
if (ECDsaAdapter.SupportsECParameters())
return true;
#endif
Expand All @@ -106,7 +106,7 @@ public override bool CanComputeJwkThumbprint()
/// <remarks>https://datatracker.ietf.org/doc/html/rfc7638</remarks>
public override byte[] ComputeJwkThumbprint()
{
#if NET472 || NETSTANDARD2_0 || NET6_0
#if NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
if (ECDsaAdapter.SupportsECParameters())
{
ECParameters parameters = ECDsa.ExportParameters(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.IdentityModel.Tokens
{
#if NET472 || NET6_0
#if NET472 || NET6_0 || NET8_0
/// <summary>
/// Provides a Security Key that can be used as Content Encryption Key (CEK) for use with a JWE
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,25 @@ public SecurityTokenException(string message, Exception innerException)
/// </summary>
/// <param name="info">the <see cref="SerializationInfo"/> that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
protected SecurityTokenException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

#if NET472 || NETSTANDARD2_0 || NET6_0
#if NET472 || NETSTANDARD2_0 || NET6_0 || NET8_0
/// <summary>
/// When overridden in a derived class, sets the System.Runtime.Serialization.SerializationInfo
/// with information about the exception.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">thrown if <paramref name="info"/> is null.</exception>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public SecurityTokenExpiredException(string message, Exception inner)
/// </summary>
/// <param name="info">the <see cref="SerializationInfo"/> that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
protected SecurityTokenExpiredException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand All @@ -72,6 +75,9 @@ protected SecurityTokenExpiredException(SerializationInfo info, StreamingContext
}

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public SecurityTokenInvalidAlgorithmException(string message, Exception innerExc
/// </summary>
/// <param name="info">the <see cref="SerializationInfo"/> that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
protected SecurityTokenInvalidAlgorithmException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand All @@ -75,6 +78,9 @@ protected SecurityTokenInvalidAlgorithmException(SerializationInfo info, Streami
}

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public SecurityTokenInvalidAudienceException(string message, Exception innerExce
/// </summary>
/// <param name="info">the <see cref="SerializationInfo"/> that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
protected SecurityTokenInvalidAudienceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand All @@ -75,6 +78,9 @@ protected SecurityTokenInvalidAudienceException(SerializationInfo info, Streamin
}

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
Expand Down
Loading

0 comments on commit 059b573

Please sign in to comment.