From e6cfb6bd242fdc9a0a35122e849ed7811df0a5de Mon Sep 17 00:00:00 2001 From: Westin Musser <127992899+westin-m@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:39:31 -0700 Subject: [PATCH] add net8.0 target (#2108) add net8.0 target Put CustomKey and a custom converter for SecurityKey in TestUtils, transition aot test to net8.0 --- build/common.props | 7 +- build/commonTest.props | 9 +- build/dependencies.props | 12 +- build/targets.props | 2 +- build/targetsTest.props | 2 +- .../JsonWebTokenHandler.cs | 2 +- .../JwtTokenUtilities.cs | 2 +- ...crosoft.IdentityModel.JsonWebTokens.csproj | 2 +- ...ft.IdentityModel.KeyVaultExtensions.csproj | 4 +- .../IdentityModelTelemetryUtil.cs | 2 + ...tyModel.Protocols.SignedHttpRequest.csproj | 6 +- .../GlobalSuppressions.cs | 2 +- ...dentityModel.Protocols.WsFederation.csproj | 2 +- .../GlobalSuppressions.cs | 2 +- .../AsymmetricAdapter.cs | 8 +- .../AsymmetricSignatureProvider.cs | 2 +- .../CryptoProviderFactory.cs | 2 +- .../ECDsaAdapter.cs | 6 +- .../ECDsaSecurityKey.cs | 4 +- .../Encryption/EcdhKeyExchangeProvider.cs | 2 +- .../Exceptions/SecurityTokenException.cs | 8 +- .../SecurityTokenExpiredException.cs | 6 + .../SecurityTokenInvalidAlgorithmException.cs | 6 + .../SecurityTokenInvalidAudienceException.cs | 6 + .../SecurityTokenInvalidIssuerException.cs | 6 + .../SecurityTokenInvalidLifetimeException.cs | 3 + .../SecurityTokenInvalidTypeException.cs | 3 + .../SecurityTokenNotYetValidException.cs | 6 + .../SecurityTokenUnableToValidateException.cs | 3 + .../GlobalSuppressions.cs | 2 +- .../JsonWebKeyConverter.cs | 4 +- .../Microsoft.IdentityModel.Tokens.csproj | 8 +- .../RsaSecurityKey.cs | 2 +- .../SupportedAlgorithms.cs | 4 +- .../X509SecurityKey.cs | 4 +- .../opensource/json/JsonException.cs | 3 + .../opensource/json/Linq/JContainer.cs | 4 + .../GlobalSuppressions.cs | 2 +- .../JwtSecurityTokenHandler.cs | 2 +- .../CrossVersionTokenValidation.Tests.csproj | 2 +- ...ntityModel.AotCompatibility.TestApp.csproj | 2 +- ...dentityModel.AotCompatibility.Tests.csproj | 2 +- .../OpenIdConnectMessageTests.cs | 6 + .../CustomSecurityKey.cs | 34 ++++++ .../DerivedTypes.cs | 6 + .../KeyingMaterial.cs | 2 +- .../SecurityKeyCustomConverter.cs | 103 ++++++++++++++++++ .../AsymmetricAdapterTests.cs | 8 +- .../EcdhEsTests.cs | 2 +- .../JweUsingEchdTests.cs | 2 +- .../ReferenceTests.cs | 2 +- .../SecurityTokenExceptionTests.cs | 20 +++- 52 files changed, 291 insertions(+), 62 deletions(-) create mode 100644 test/Microsoft.IdentityModel.TestUtils/CustomSecurityKey.cs create mode 100644 test/Microsoft.IdentityModel.TestUtils/SecurityKeyCustomConverter.cs diff --git a/build/common.props b/build/common.props index 7db1892715..5ef7233ed1 100644 --- a/build/common.props +++ b/build/common.props @@ -37,7 +37,12 @@ true - + + + $(NoWarn);SYSLIB0050 + $(NoWarn);SYSLIB0051 + + diff --git a/build/commonTest.props b/build/commonTest.props index 9d82ef294a..82485826cd 100644 --- a/build/commonTest.props +++ b/build/commonTest.props @@ -18,11 +18,16 @@ $(DotNetCoreAppRuntimeVersion) - + $(DefineConstants);NET_CORE - + + $(NoWarn);SYSLIB0050 + $(NoWarn);SYSLIB0051 + + + diff --git a/build/dependencies.props b/build/dependencies.props index 9cfc6442d7..d6488e9acd 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -3,7 +3,6 @@ 2.1.1 3.0.5 1.0.3 - 4.5.0 1.0.0 2.0.3 4.3.0 @@ -15,10 +14,19 @@ 4.3.0 4.3.0 4.3.0 - 4.5.0 4.3.0 4.7.2 4.7.2 4.3.0 + + + 5.0.0 + 4.7.0 + + + + 4.5.0 + 4.5.0 + diff --git a/build/targets.props b/build/targets.props index 4e8f0384cf..eef092fc0b 100644 --- a/build/targets.props +++ b/build/targets.props @@ -1,6 +1,6 @@ - net461;net462;net472;netstandard2.0;net6.0 + net461;net462;net472;netstandard2.0;net6.0;net8.0 netstandard2.0 diff --git a/build/targetsTest.props b/build/targetsTest.props index 8b7d80d09a..4b5bb9a393 100644 --- a/build/targetsTest.props +++ b/build/targetsTest.props @@ -1,6 +1,6 @@ - net461;net462;net472;netcoreapp2.1;net6.0 + net461;net462;net472;netcoreapp2.1;net6.0;net8.0 netcoreapp2.1 diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs index 142a0f273b..d3ee761beb 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs @@ -1166,7 +1166,7 @@ internal IEnumerable GetContentEncryptionKeys(JsonWebToken jwtToken { try { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER 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 diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs index c4a0f834ca..c5988de095 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs +++ b/src/Microsoft.IdentityModel.JsonWebTokens/JwtTokenUtilities.cs @@ -318,7 +318,7 @@ internal static SecurityKey GetSecurityKey( securityKey = encryptingCredentials.Key; } -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER 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 diff --git a/src/Microsoft.IdentityModel.JsonWebTokens/Microsoft.IdentityModel.JsonWebTokens.csproj b/src/Microsoft.IdentityModel.JsonWebTokens/Microsoft.IdentityModel.JsonWebTokens.csproj index 1dbf9b2bb0..d502da5187 100644 --- a/src/Microsoft.IdentityModel.JsonWebTokens/Microsoft.IdentityModel.JsonWebTokens.csproj +++ b/src/Microsoft.IdentityModel.JsonWebTokens/Microsoft.IdentityModel.JsonWebTokens.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj b/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj index 918ccdec6b..bf69e0277a 100644 --- a/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj +++ b/src/Microsoft.IdentityModel.KeyVaultExtensions/Microsoft.IdentityModel.KeyVaultExtensions.csproj @@ -8,7 +8,7 @@ true latest Microsoft.IdentityModel.KeyVaultExtensions - netstandard2.0;net6.0 + netstandard2.0;net6.0;net8.0 .NET;Windows;Authentication;Identity;Azure;Key;Vault;Extensions @@ -30,4 +30,4 @@ - \ No newline at end of file + diff --git a/src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs b/src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs index 360f5e7294..487f4df120 100644 --- a/src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs +++ b/src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs @@ -39,6 +39,8 @@ public static class IdentityModelTelemetryUtil "ID_NETSTANDARD2_0"; #elif NET6_0 "ID_NET6_0"; +#elif NET8_0 + "ID_NET8_0"; #endif /// diff --git a/src/Microsoft.IdentityModel.Protocols.SignedHttpRequest/Microsoft.IdentityModel.Protocols.SignedHttpRequest.csproj b/src/Microsoft.IdentityModel.Protocols.SignedHttpRequest/Microsoft.IdentityModel.Protocols.SignedHttpRequest.csproj index 9408791c1f..8fe3e1d469 100644 --- a/src/Microsoft.IdentityModel.Protocols.SignedHttpRequest/Microsoft.IdentityModel.Protocols.SignedHttpRequest.csproj +++ b/src/Microsoft.IdentityModel.Protocols.SignedHttpRequest/Microsoft.IdentityModel.Protocols.SignedHttpRequest.csproj @@ -31,13 +31,13 @@ - + - + - + diff --git a/src/Microsoft.IdentityModel.Protocols.WsFederation/GlobalSuppressions.cs b/src/Microsoft.IdentityModel.Protocols.WsFederation/GlobalSuppressions.cs index 6a35dd1f18..a0561459c9 100644 --- a/src/Microsoft.IdentityModel.Protocols.WsFederation/GlobalSuppressions.cs +++ b/src/Microsoft.IdentityModel.Protocols.WsFederation/GlobalSuppressions.cs @@ -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_OR_GREATER [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 diff --git a/src/Microsoft.IdentityModel.Protocols.WsFederation/Microsoft.IdentityModel.Protocols.WsFederation.csproj b/src/Microsoft.IdentityModel.Protocols.WsFederation/Microsoft.IdentityModel.Protocols.WsFederation.csproj index 3f01ff1bb5..66f7e921ae 100644 --- a/src/Microsoft.IdentityModel.Protocols.WsFederation/Microsoft.IdentityModel.Protocols.WsFederation.csproj +++ b/src/Microsoft.IdentityModel.Protocols.WsFederation/Microsoft.IdentityModel.Protocols.WsFederation.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/Microsoft.IdentityModel.Protocols/GlobalSuppressions.cs b/src/Microsoft.IdentityModel.Protocols/GlobalSuppressions.cs index 7b5a935521..901dc16ac8 100644 --- a/src/Microsoft.IdentityModel.Protocols/GlobalSuppressions.cs +++ b/src/Microsoft.IdentityModel.Protocols/GlobalSuppressions.cs @@ -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_OR_GREATER [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 diff --git a/src/Microsoft.IdentityModel.Tokens/AsymmetricAdapter.cs b/src/Microsoft.IdentityModel.Tokens/AsymmetricAdapter.cs index 6b41df8d92..24090af332 100644 --- a/src/Microsoft.IdentityModel.Tokens/AsymmetricAdapter.cs +++ b/src/Microsoft.IdentityModel.Tokens/AsymmetricAdapter.cs @@ -9,7 +9,7 @@ using System.Reflection; #endif -#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 +#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER using System.Security.Cryptography.X509Certificates; #endif @@ -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_OR_GREATER if (algorithm.Equals(SecurityAlgorithms.RsaSsaPssSha256) || algorithm.Equals(SecurityAlgorithms.RsaSsaPssSha256Signature) || algorithm.Equals(SecurityAlgorithms.RsaSsaPssSha384) || @@ -251,7 +251,7 @@ private void InitializeUsingRsaSecurityKey(RsaSecurityKey rsaSecurityKey, string } else { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER var rsa = RSA.Create(rsaSecurityKey.Parameters); #else var rsa = RSA.Create(); @@ -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_OR_GREATER // HasAlgorithmName was introduced into Net46 internal AsymmetricAdapter(SecurityKey key, string algorithm, HashAlgorithm hashAlgorithm, HashAlgorithmName hashAlgorithmName, bool requirePrivateKey) diff --git a/src/Microsoft.IdentityModel.Tokens/AsymmetricSignatureProvider.cs b/src/Microsoft.IdentityModel.Tokens/AsymmetricSignatureProvider.cs index 6331dac42b..fe59937cab 100644 --- a/src/Microsoft.IdentityModel.Tokens/AsymmetricSignatureProvider.cs +++ b/src/Microsoft.IdentityModel.Tokens/AsymmetricSignatureProvider.cs @@ -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_OR_GREATER /// /// Creating a Signature requires the use of a . /// This method returns the diff --git a/src/Microsoft.IdentityModel.Tokens/CryptoProviderFactory.cs b/src/Microsoft.IdentityModel.Tokens/CryptoProviderFactory.cs index 0f07127178..9c603ecd79 100644 --- a/src/Microsoft.IdentityModel.Tokens/CryptoProviderFactory.cs +++ b/src/Microsoft.IdentityModel.Tokens/CryptoProviderFactory.cs @@ -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_OR_GREATER /// /// Creates a for a specific algorithm. /// diff --git a/src/Microsoft.IdentityModel.Tokens/ECDsaAdapter.cs b/src/Microsoft.IdentityModel.Tokens/ECDsaAdapter.cs index f3b91fca75..b42ab04307 100644 --- a/src/Microsoft.IdentityModel.Tokens/ECDsaAdapter.cs +++ b/src/Microsoft.IdentityModel.Tokens/ECDsaAdapter.cs @@ -28,7 +28,7 @@ internal class ECDsaAdapter /// internal ECDsaAdapter() { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER CreateECDsaFunction = CreateECDsaUsingECParams; #elif NETSTANDARD2_0 // Although NETSTANDARD2_0 specifies that ECParameters are supported, we still need to call SupportsECParameters() @@ -256,7 +256,7 @@ private static bool SupportsCNGKey() } } -#if NET472 || NETSTANDARD2_0 || NET6_0 +#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER /// /// Creates an ECDsa object using the and . /// 'ECParameters' structure is available in .NET Framework 4.7+, .NET Standard 1.6+, and .NET Core 1.0+. @@ -344,7 +344,7 @@ internal static string GetCrvParameterValue(ECCurve curve) /// True if structure is supported, false otherwise. internal static bool SupportsECParameters() { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER return true; #else try diff --git a/src/Microsoft.IdentityModel.Tokens/ECDsaSecurityKey.cs b/src/Microsoft.IdentityModel.Tokens/ECDsaSecurityKey.cs index e81c9e5ea3..61c2496d93 100644 --- a/src/Microsoft.IdentityModel.Tokens/ECDsaSecurityKey.cs +++ b/src/Microsoft.IdentityModel.Tokens/ECDsaSecurityKey.cs @@ -92,7 +92,7 @@ public override int KeySize /// https://datatracker.ietf.org/doc/html/rfc7638 public override bool CanComputeJwkThumbprint() { -#if NET472 || NETSTANDARD2_0 || NET6_0 +#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER if (ECDsaAdapter.SupportsECParameters()) return true; #endif @@ -106,7 +106,7 @@ public override bool CanComputeJwkThumbprint() /// https://datatracker.ietf.org/doc/html/rfc7638 public override byte[] ComputeJwkThumbprint() { -#if NET472 || NETSTANDARD2_0 || NET6_0 +#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER if (ECDsaAdapter.SupportsECParameters()) { ECParameters parameters = ECDsa.ExportParameters(false); diff --git a/src/Microsoft.IdentityModel.Tokens/Encryption/EcdhKeyExchangeProvider.cs b/src/Microsoft.IdentityModel.Tokens/Encryption/EcdhKeyExchangeProvider.cs index 5940994484..a1ccd090cf 100644 --- a/src/Microsoft.IdentityModel.Tokens/Encryption/EcdhKeyExchangeProvider.cs +++ b/src/Microsoft.IdentityModel.Tokens/Encryption/EcdhKeyExchangeProvider.cs @@ -8,7 +8,7 @@ namespace Microsoft.IdentityModel.Tokens { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER /// /// Provides a Security Key that can be used as Content Encryption Key (CEK) for use with a JWE /// diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs index 046ecba1ed..f544c99e93 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenException.cs @@ -47,12 +47,15 @@ public SecurityTokenException(string message, Exception innerException) /// /// the that holds the serialized object data. /// The contextual information about the source or destination. +#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_OR_GREATER /// /// When overridden in a derived class, sets the System.Runtime.Serialization.SerializationInfo /// with information about the exception. @@ -60,6 +63,9 @@ protected SecurityTokenException(SerializationInfo info, StreamingContext contex /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// thrown if is null. +#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) diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenExpiredException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenExpiredException.cs index 308b9756af..6fdd24e4d9 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenExpiredException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenExpiredException.cs @@ -52,6 +52,9 @@ public SecurityTokenExpiredException(string message, Exception inner) /// /// the that holds the serialized object data. /// The contextual information about the source or destination. +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif protected SecurityTokenExpiredException(SerializationInfo info, StreamingContext context) : base(info, context) { @@ -72,6 +75,9 @@ protected SecurityTokenExpiredException(SerializationInfo info, StreamingContext } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAlgorithmException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAlgorithmException.cs index 4dee4e87d5..0eb76c59c2 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAlgorithmException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAlgorithmException.cs @@ -55,6 +55,9 @@ public SecurityTokenInvalidAlgorithmException(string message, Exception innerExc /// /// the that holds the serialized object data. /// The contextual information about the source or destination. +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif protected SecurityTokenInvalidAlgorithmException(SerializationInfo info, StreamingContext context) : base(info, context) { @@ -75,6 +78,9 @@ protected SecurityTokenInvalidAlgorithmException(SerializationInfo info, Streami } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAudienceException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAudienceException.cs index c4c492aafd..25bf7c7abb 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAudienceException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidAudienceException.cs @@ -55,6 +55,9 @@ public SecurityTokenInvalidAudienceException(string message, Exception innerExce /// /// the that holds the serialized object data. /// The contextual information about the source or destination. +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif protected SecurityTokenInvalidAudienceException(SerializationInfo info, StreamingContext context) : base(info, context) { @@ -75,6 +78,9 @@ protected SecurityTokenInvalidAudienceException(SerializationInfo info, Streamin } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidIssuerException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidIssuerException.cs index 26173cfb9b..c1232df09b 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidIssuerException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidIssuerException.cs @@ -55,6 +55,9 @@ public SecurityTokenInvalidIssuerException(string message, Exception innerExcept /// /// the that holds the serialized object data. /// The contextual information about the source or destination. +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif protected SecurityTokenInvalidIssuerException(SerializationInfo info, StreamingContext context) : base(info, context) { @@ -75,6 +78,9 @@ protected SecurityTokenInvalidIssuerException(SerializationInfo info, StreamingC } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidLifetimeException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidLifetimeException.cs index cc3c3e8fb9..3868f3470e 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidLifetimeException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidLifetimeException.cs @@ -87,6 +87,9 @@ protected SecurityTokenInvalidLifetimeException(SerializationInfo info, Streamin } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidTypeException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidTypeException.cs index 07f43a3a41..6dccc65bd8 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidTypeException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidTypeException.cs @@ -75,6 +75,9 @@ protected SecurityTokenInvalidTypeException(SerializationInfo info, StreamingCon } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenNotYetValidException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenNotYetValidException.cs index 7c87f86481..e379e56265 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenNotYetValidException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenNotYetValidException.cs @@ -53,6 +53,9 @@ public SecurityTokenNotYetValidException(string message, Exception inner) /// /// the that holds the serialized object data. /// The contextual information about the source or destination. +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif protected SecurityTokenNotYetValidException(SerializationInfo info, StreamingContext context) : base(info, context) { @@ -73,6 +76,9 @@ protected SecurityTokenNotYetValidException(SerializationInfo info, StreamingCon } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenUnableToValidateException.cs b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenUnableToValidateException.cs index 6ee0c4d18f..285cf40a0b 100644 --- a/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenUnableToValidateException.cs +++ b/src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenUnableToValidateException.cs @@ -95,6 +95,9 @@ protected SecurityTokenUnableToValidateException(SerializationInfo info, Streami } /// +#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); diff --git a/src/Microsoft.IdentityModel.Tokens/GlobalSuppressions.cs b/src/Microsoft.IdentityModel.Tokens/GlobalSuppressions.cs index 86381917d7..adada5930c 100644 --- a/src/Microsoft.IdentityModel.Tokens/GlobalSuppressions.cs +++ b/src/Microsoft.IdentityModel.Tokens/GlobalSuppressions.cs @@ -55,7 +55,7 @@ [assembly: SuppressMessage("Design", "CA1001:Types That own disposable fields should be disposable", Justification = "Exceptions can occurr if disposed of", Scope = "type", Target = "~T:Microsoft.IdentityModel.Tokens.EventBasedLRUCache`2")] [assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Consistency", Scope = "member", Target = "~P:Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor.AdditionalInnerHeaderClaims")] [assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Used as validation", Scope = "member", Target = "~M:Microsoft.IdentityModel.Tokens.InternalValidators.ValidateLifetimeAndIssuerAfterSignatureNotValidatedJwt(Microsoft.IdentityModel.Tokens.SecurityToken,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.String,Microsoft.IdentityModel.Tokens.TokenValidationParameters,Microsoft.IdentityModel.Tokens.BaseConfiguration,System.Text.StringBuilder,System.Int32,System.Int32)")] -#if NET472 || NETSTANDARD2_0 || NET6_0 +#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER [assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Used to determine appropriate code path to take.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Tokens.JsonWebKeyConverter.ConvertFromECDsaSecurityKey(Microsoft.IdentityModel.Tokens.ECDsaSecurityKey)~Microsoft.IdentityModel.Tokens.JsonWebKey")] [assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Used to determine appropriate code path to take.", Scope = "member", Target = "~P:Microsoft.IdentityModel.Tokens.EcdhSecurityKey.PrivateKeyStatus")] [assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Adding StringComparison.Ordinal adds a performance penalty.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Tokens.EcdhKeyExchangeProvider.GenerateKdf(System.String,System.String)~Microsoft.IdentityModel.Tokens.SecurityKey")] diff --git a/src/Microsoft.IdentityModel.Tokens/JsonWebKeyConverter.cs b/src/Microsoft.IdentityModel.Tokens/JsonWebKeyConverter.cs index eda168f39c..f51bbbb63d 100644 --- a/src/Microsoft.IdentityModel.Tokens/JsonWebKeyConverter.cs +++ b/src/Microsoft.IdentityModel.Tokens/JsonWebKeyConverter.cs @@ -33,7 +33,7 @@ public static JsonWebKey ConvertFromSecurityKey(SecurityKey key) return ConvertFromSymmetricSecurityKey(symmetricKey); else if (key is X509SecurityKey x509Key) return ConvertFromX509SecurityKey(x509Key); -#if NET472 || NETSTANDARD2_0 || NET6_0 +#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER else if (key is ECDsaSecurityKey ecdsaSecurityKey) return ConvertFromECDsaSecurityKey(ecdsaSecurityKey); #endif @@ -157,7 +157,7 @@ public static JsonWebKey ConvertFromSymmetricSecurityKey(SymmetricSecurityKey ke }; } -#if NET472 || NETSTANDARD2_0 || NET6_0 +#if NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER /// /// Converts a into a /// diff --git a/src/Microsoft.IdentityModel.Tokens/Microsoft.IdentityModel.Tokens.csproj b/src/Microsoft.IdentityModel.Tokens/Microsoft.IdentityModel.Tokens.csproj index 25a9f84ab7..1010bd075d 100644 --- a/src/Microsoft.IdentityModel.Tokens/Microsoft.IdentityModel.Tokens.csproj +++ b/src/Microsoft.IdentityModel.Tokens/Microsoft.IdentityModel.Tokens.csproj @@ -20,8 +20,8 @@ $(DefineConstants);TRACE;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_REGEX_TIMEOUTS;$(AdditionalConstants) - - $(DefineConstants);HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_ASYNC_DISPOSABLE;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_EMIT;HAVE_REGEX_TIMEOUTS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_INDEXOF_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_GETHASHCODE_STRING_COMPARISON;HAVE_NULLABLE_ATTRIBUTES;HAVE_DYNAMIC_CODE_COMPILED;HAS_ARRAY_EMPTY;HAVE_DATE_ONLY;$(AdditionalConstants) + + $(DefineConstants);HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_ASYNC_DISPOSABLE;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_EMIT;HAVE_REGEX_TIMEOUTS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_INDEXOF_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_GETHASHCODE_STRING_COMPARISON;HAVE_NULLABLE_ATTRIBUTES;HAVE_DYNAMIC_CODE_COMPILED;HAS_ARRAY_EMPTY;HAVE_DATE_ONLY;$(AdditionalConstants) @@ -34,7 +34,7 @@ - + @@ -47,7 +47,7 @@ - + diff --git a/src/Microsoft.IdentityModel.Tokens/RsaSecurityKey.cs b/src/Microsoft.IdentityModel.Tokens/RsaSecurityKey.cs index 6a24e4c358..248f5cc947 100644 --- a/src/Microsoft.IdentityModel.Tokens/RsaSecurityKey.cs +++ b/src/Microsoft.IdentityModel.Tokens/RsaSecurityKey.cs @@ -76,7 +76,7 @@ public override bool HasPrivateKey { // imitate signing byte[] hash = new byte[20]; -#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 +#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER Rsa.SignData(hash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); #else if (Rsa is RSACryptoServiceProvider rsaCryptoServiceProvider) diff --git a/src/Microsoft.IdentityModel.Tokens/SupportedAlgorithms.cs b/src/Microsoft.IdentityModel.Tokens/SupportedAlgorithms.cs index b75be47896..c1abe440b1 100644 --- a/src/Microsoft.IdentityModel.Tokens/SupportedAlgorithms.cs +++ b/src/Microsoft.IdentityModel.Tokens/SupportedAlgorithms.cs @@ -104,7 +104,7 @@ internal static class SupportedAlgorithms SecurityAlgorithms.EcdhEsA256kw }; -#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 +#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER /// /// Creating a Signature requires the use of a . /// This method returns the @@ -339,7 +339,7 @@ private static bool IsSupportedRsaPss(SecurityKey key) // RSA-PSS is not available on .NET 4.5 LogHelper.LogInformation(LogMessages.IDX10692); return false; -#elif NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 +#elif NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER // RSACryptoServiceProvider doesn't support RSA-PSS if (key is RsaSecurityKey rsa && rsa.Rsa is RSACryptoServiceProvider) { diff --git a/src/Microsoft.IdentityModel.Tokens/X509SecurityKey.cs b/src/Microsoft.IdentityModel.Tokens/X509SecurityKey.cs index 5de03fb1d9..5b7687ec10 100644 --- a/src/Microsoft.IdentityModel.Tokens/X509SecurityKey.cs +++ b/src/Microsoft.IdentityModel.Tokens/X509SecurityKey.cs @@ -78,7 +78,7 @@ public AsymmetricAlgorithm PrivateKey { if (!_privateKeyAvailabilityDetermined) { -#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 +#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER _privateKey = RSACertificateExtensions.GetRSAPrivateKey(Certificate); #else _privateKey = Certificate.PrivateKey; @@ -105,7 +105,7 @@ public AsymmetricAlgorithm PublicKey { if (_publicKey == null) { -#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0 +#if NET461 || NET462 || NET472 || NETSTANDARD2_0 || NET6_0_OR_GREATER _publicKey = RSACertificateExtensions.GetRSAPublicKey(Certificate); #else _publicKey = Certificate.PublicKey.Key; diff --git a/src/Microsoft.IdentityModel.Tokens/opensource/json/JsonException.cs b/src/Microsoft.IdentityModel.Tokens/opensource/json/JsonException.cs index 20f23dc9e7..c1f65f0325 100644 --- a/src/Microsoft.IdentityModel.Tokens/opensource/json/JsonException.cs +++ b/src/Microsoft.IdentityModel.Tokens/opensource/json/JsonException.cs @@ -77,6 +77,9 @@ public JsonException(string message, Exception? innerException) /// The that contains contextual information about the source or destination. /// The parameter is null. /// The class name is null or is zero (0). +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif public JsonException(SerializationInfo info, StreamingContext context) : base(info, context) { diff --git a/src/Microsoft.IdentityModel.Tokens/opensource/json/Linq/JContainer.cs b/src/Microsoft.IdentityModel.Tokens/opensource/json/Linq/JContainer.cs index 4f64973c53..e92477bade 100644 --- a/src/Microsoft.IdentityModel.Tokens/opensource/json/Linq/JContainer.cs +++ b/src/Microsoft.IdentityModel.Tokens/opensource/json/Linq/JContainer.cs @@ -943,12 +943,16 @@ internal int ContentsHashCode() } #if HAVE_COMPONENT_MODEL +#pragma warning disable CS8769 // Nullability of reference types in type of parameter doesn't match implemented member (possibly because of nullability attributes). string ITypedList.GetListName(PropertyDescriptor[] listAccessors) +#pragma warning restore CS8769 // Nullability of reference types in type of parameter doesn't match implemented member (possibly because of nullability attributes). { return string.Empty; } +#pragma warning disable CS8769 // Nullability of reference types in type of parameter doesn't match implemented member (possibly because of nullability attributes). PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors) +#pragma warning restore CS8769 // Nullability of reference types in type of parameter doesn't match implemented member (possibly because of nullability attributes). { ICustomTypeDescriptor? d = First as ICustomTypeDescriptor; diff --git a/src/Microsoft.IdentityModel.Validators/GlobalSuppressions.cs b/src/Microsoft.IdentityModel.Validators/GlobalSuppressions.cs index 0ef7cebb58..5e664474b6 100644 --- a/src/Microsoft.IdentityModel.Validators/GlobalSuppressions.cs +++ b/src/Microsoft.IdentityModel.Validators/GlobalSuppressions.cs @@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Needs to be ignored", Scope = "member", Target = "~M:Microsoft.IdentityModel.Validators.AadIssuerValidator.IsValidIssuer(System.String,System.String,System.String)~System.Boolean")] -#if NET6_0 +#if NET6_0_OR_GREATER [assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Adding StringComparison.Ordinal adds a performance penalty.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Validators.AadIssuerValidator.CreateV1Authority(System.String)~System.String")] [assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Adding StringComparison.Ordinal adds a performance penalty.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Validators.AadIssuerValidator.IsValidIssuer(System.String,System.String,System.String)~System.Boolean")] [assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Adding StringComparison.Ordinal adds a performance penalty.", Scope = "member", Target = "~M:Microsoft.IdentityModel.Validators.AadIssuerValidator.#ctor(System.Net.Http.HttpClient,System.String)")] diff --git a/src/System.IdentityModel.Tokens.Jwt/JwtSecurityTokenHandler.cs b/src/System.IdentityModel.Tokens.Jwt/JwtSecurityTokenHandler.cs index 2edf2de22e..7b09d3e38b 100644 --- a/src/System.IdentityModel.Tokens.Jwt/JwtSecurityTokenHandler.cs +++ b/src/System.IdentityModel.Tokens.Jwt/JwtSecurityTokenHandler.cs @@ -1796,7 +1796,7 @@ internal IEnumerable GetContentEncryptionKeys(JwtSecurityToken jwtT { try { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER if (SupportedAlgorithms.EcdsaWrapAlgorithms.Contains(jwtToken.Header.Alg)) { //// on decryption we get the public key from the EPK value see: https://datatracker.ietf.org/doc/html/rfc7518#appendix-C diff --git a/test/CrossVersionTokenValidation.Tests/CrossVersionTokenValidation.Tests.csproj b/test/CrossVersionTokenValidation.Tests/CrossVersionTokenValidation.Tests.csproj index 86c2256d94..073d137a7a 100644 --- a/test/CrossVersionTokenValidation.Tests/CrossVersionTokenValidation.Tests.csproj +++ b/test/CrossVersionTokenValidation.Tests/CrossVersionTokenValidation.Tests.csproj @@ -43,4 +43,4 @@ - \ No newline at end of file + diff --git a/test/Microsoft.IdentityModel.AotCompatibility.TestApp/Microsoft.IdentityModel.AotCompatibility.TestApp.csproj b/test/Microsoft.IdentityModel.AotCompatibility.TestApp/Microsoft.IdentityModel.AotCompatibility.TestApp.csproj index a4a7f4211d..b8b047c289 100644 --- a/test/Microsoft.IdentityModel.AotCompatibility.TestApp/Microsoft.IdentityModel.AotCompatibility.TestApp.csproj +++ b/test/Microsoft.IdentityModel.AotCompatibility.TestApp/Microsoft.IdentityModel.AotCompatibility.TestApp.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Exe true full diff --git a/test/Microsoft.IdentityModel.AotCompatibility.Tests/Microsoft.IdentityModel.AotCompatibility.Tests.csproj b/test/Microsoft.IdentityModel.AotCompatibility.Tests/Microsoft.IdentityModel.AotCompatibility.Tests.csproj index 2d4cc1811b..f5cedafd52 100644 --- a/test/Microsoft.IdentityModel.AotCompatibility.Tests/Microsoft.IdentityModel.AotCompatibility.Tests.csproj +++ b/test/Microsoft.IdentityModel.AotCompatibility.Tests/Microsoft.IdentityModel.AotCompatibility.Tests.csproj @@ -4,7 +4,7 @@ - net6.0 + net6.0;net8.0 diff --git a/test/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/OpenIdConnectMessageTests.cs b/test/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/OpenIdConnectMessageTests.cs index f4e9423925..39a0d78433 100644 --- a/test/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/OpenIdConnectMessageTests.cs +++ b/test/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/OpenIdConnectMessageTests.cs @@ -233,6 +233,9 @@ public void OidcCreateAuthenticationRequestUrl(string testId, OpenIdConnectMessa #elif NET6_0 if (!message.SkuTelemetryValue.Equals("ID_NET6_0")) context.Diffs.Add($"{message.SkuTelemetryValue} != ID_NET6_0"); +#elif NET8_0 + if (!message.SkuTelemetryValue.Equals("ID_NET8_0")) + context.Diffs.Add($"{message.SkuTelemetryValue} != ID_NET8_0"); #elif NET_CORE if (!message.SkuTelemetryValue.Equals("ID_NETSTANDARD2_0")) context.Diffs.Add($"{message.SkuTelemetryValue} != ID_NETSTANDARD2_0"); @@ -506,6 +509,9 @@ public void OidcCreateLogoutRequestUrl(string testId, OpenIdConnectMessage messa #elif NET6_0 if (!message.SkuTelemetryValue.Equals("ID_NET6_0")) context.Diffs.Add($"{message.SkuTelemetryValue} != ID_NETCOREAPP3_1"); +#elif NET8_0 + if (!message.SkuTelemetryValue.Equals("ID_NET8_0")) + context.Diffs.Add($"{message.SkuTelemetryValue} != ID_NET8_0"); #elif NET_CORE if (!message.SkuTelemetryValue.Equals("ID_NETSTANDARD2_0")) context.Diffs.Add($"{message.SkuTelemetryValue} != ID_NETSTANDARD2_0"); diff --git a/test/Microsoft.IdentityModel.TestUtils/CustomSecurityKey.cs b/test/Microsoft.IdentityModel.TestUtils/CustomSecurityKey.cs new file mode 100644 index 0000000000..31b357b4ea --- /dev/null +++ b/test/Microsoft.IdentityModel.TestUtils/CustomSecurityKey.cs @@ -0,0 +1,34 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Microsoft.IdentityModel.Tokens; + +namespace Microsoft.IdentityModel.TestUtils +{ + public class CustomSecurityKey : SecurityKey + { + public override int KeySize => 1; + } +} diff --git a/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs b/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs index 745e449c36..f4580dba31 100644 --- a/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs +++ b/test/Microsoft.IdentityModel.TestUtils/DerivedTypes.cs @@ -226,11 +226,17 @@ public override int KeySize public override string KeyExchangeAlgorithm => throw new NotImplementedException(); +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif public override byte[] DecryptValue(byte[] rgb) { throw new NotImplementedException(); } +#if NET8_0_OR_GREATER + [Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] +#endif public override byte[] EncryptValue(byte[] rgb) { throw new NotImplementedException(); diff --git a/test/Microsoft.IdentityModel.TestUtils/KeyingMaterial.cs b/test/Microsoft.IdentityModel.TestUtils/KeyingMaterial.cs index ce44b35a13..1f2acdaf10 100644 --- a/test/Microsoft.IdentityModel.TestUtils/KeyingMaterial.cs +++ b/test/Microsoft.IdentityModel.TestUtils/KeyingMaterial.cs @@ -121,7 +121,7 @@ public static X509SecurityKey DefaultX509Key_2048_Public public static X509SecurityKey NotYetValidX509SecurityKey_Public = new X509SecurityKey(NotYetValidX509Cert_Public); public static SigningCredentials NotYetValidX509SigningCreds_Public = new SigningCredentials(NotYetValidX509SecurityKey_Public, SecurityAlgorithms.RsaSha256Signature); -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER //encoded strings for "AliceInformation", "BobInformation", "AliceNotMatchingInfo", and "BobNotMatchingInfo" public static string ApuExample1 = "QWxpY2VJbmZvcm1hdGlvbg"; public static string ApvExample1 = "Qm9iSW5mb3JtYXRpb24"; diff --git a/test/Microsoft.IdentityModel.TestUtils/SecurityKeyCustomConverter.cs b/test/Microsoft.IdentityModel.TestUtils/SecurityKeyCustomConverter.cs new file mode 100644 index 0000000000..044bbf5266 --- /dev/null +++ b/test/Microsoft.IdentityModel.TestUtils/SecurityKeyCustomConverter.cs @@ -0,0 +1,103 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +#if NET8_0_OR_GREATER +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.IdentityModel.Tokens; + +namespace Microsoft.IdentityModel.TestUtils +{ + /// + /// Custom Json converter for . + /// + public class SecurityKeyConverterWithTypeDiscriminator : JsonConverter + { + enum TypeDiscriminator + { + CustomKey = 1 + } + + /// + public override bool CanConvert(Type typeToConvert) => + typeof(SecurityKey).IsAssignableFrom(typeToConvert); + + /// + public override SecurityKey Read( + ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + Utf8JsonReader readerClone = reader; + + if (readerClone.TokenType != JsonTokenType.StartObject) + { + throw new JsonException(); + } + + readerClone.Read(); + if (readerClone.TokenType != JsonTokenType.PropertyName) + { + throw new JsonException(); + } + + var propertyName = readerClone.GetString(); + if (propertyName != "TypeDiscriminator") + { + throw new JsonException(); + } + + readerClone.Read(); + if (readerClone.TokenType != JsonTokenType.Number) + { + throw new JsonException(); + } + + TypeDiscriminator typeDiscriminator = (TypeDiscriminator)readerClone.GetInt32(); + SecurityKey securityKey = typeDiscriminator switch + { + TypeDiscriminator.CustomKey => JsonSerializer.Deserialize(ref reader)!, + _ => throw new JsonException() + }; + return securityKey; + } + + /// + public override void Write( + Utf8JsonWriter writer, SecurityKey securityKey, JsonSerializerOptions options) + { + writer.WriteStartObject(); + + if (securityKey is CustomSecurityKey customKey) + { + writer.WriteNumber("TypeDiscriminator", (int)TypeDiscriminator.CustomKey); + } + + writer.WriteNumber("KeySize", securityKey.KeySize); + + writer.WriteEndObject(); + } + } +} +#endif diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/AsymmetricAdapterTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/AsymmetricAdapterTests.cs index 9a180a3ce3..a0d2570872 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/AsymmetricAdapterTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/AsymmetricAdapterTests.cs @@ -24,7 +24,7 @@ public void AsymmetricAdapterUsageTests(AsymmetricAdapterTheoryData theoryData) try { -#if NET461 || NET462 || NET472 || NETCOREAPP2_1 || NET6_0 +#if NET461 || NET462 || NET472 || NETCOREAPP2_1 || NET6_0_OR_GREATER AsymmetricAdapter asymmetricdapter = new AsymmetricAdapter(theoryData.SecurityKey, theoryData.Algorithm, hashAlgorithm, SupportedAlgorithms.GetHashAlgorithmName(theoryData.Algorithm), true); #else AsymmetricAdapter asymmetricdapter = new AsymmetricAdapter(theoryData.SecurityKey, theoryData.Algorithm, hashAlgorithm, true); @@ -59,7 +59,7 @@ public static TheoryData AsymmetricAdapterUsageTest // RSA // RSACertificateExtensions.GetRSAPrivateKey - this results in - #if NET461 || NET462 || NET472 || NETCOREAPP2_1 || NET6_0 + #if NET461 || NET462 || NET472 || NETCOREAPP2_1 || NET6_0_OR_GREATER new AsymmetricAdapterTheoryData { Algorithm = SecurityAlgorithms.RsaSha256, @@ -79,7 +79,7 @@ public static TheoryData AsymmetricAdapterUsageTest }, // RSA.Create - #if NET472 || NETCOREAPP2_1 || NET6_0 + #if NET472 || NETCOREAPP2_1 || NET6_0_OR_GREATER new AsymmetricAdapterTheoryData { Algorithm = SecurityAlgorithms.RsaSha256, @@ -117,7 +117,7 @@ public static TheoryData AsymmetricAdapterUsageTest TestId = "KeyingMaterial_Ecdsa256Key" }, - #if NET472 || NETCOREAPP2_1 || NET6_0 + #if NET472 || NETCOREAPP2_1 || NET6_0_OR_GREATER new AsymmetricAdapterTheoryData { Algorithm = SecurityAlgorithms.EcdsaSha256, diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/EcdhEsTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/EcdhEsTests.cs index 02718119cf..8e520c92e0 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/EcdhEsTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/EcdhEsTests.cs @@ -8,7 +8,7 @@ using KEY = Microsoft.IdentityModel.TestUtils.KeyingMaterial; #pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER namespace Microsoft.IdentityModel.Tokens.Tests { public class EcdhEsTests diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/JweUsingEchdTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/JweUsingEchdTests.cs index 050a6764d1..2981a4ea55 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/JweUsingEchdTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/JweUsingEchdTests.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER using System; using System.Collections; diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/ReferenceTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/ReferenceTests.cs index 611d4a6352..e19c779a10 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/ReferenceTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/ReferenceTests.cs @@ -22,7 +22,7 @@ namespace Microsoft.IdentityModel.Tokens.Tests public class ReferenceTests { -#if NET472 || NET6_0 +#if NET472 || NET6_0_OR_GREATER [Fact] public void ECDH_ESReferenceTest() { diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/SecurityTokenExceptionTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/SecurityTokenExceptionTests.cs index 39e3302532..da9bddb840 100644 --- a/test/Microsoft.IdentityModel.Tokens.Tests/SecurityTokenExceptionTests.cs +++ b/test/Microsoft.IdentityModel.Tokens.Tests/SecurityTokenExceptionTests.cs @@ -5,7 +5,11 @@ using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; +#if NET8_0_OR_GREATER +using System.Text.Json; +#else using System.Runtime.Serialization.Formatters.Binary; +#endif using Microsoft.IdentityModel.TestUtils; using Xunit; @@ -27,6 +31,14 @@ public void SecurityTokenInvalidIssuerExceptionSerializesValues(SecurityTokenExc var memoryStream = new MemoryStream(); +#if NET8_0_OR_GREATER + var serializerOptions = new JsonSerializerOptions(); + serializerOptions.Converters.Add(new SecurityKeyConverterWithTypeDiscriminator()); + + JsonSerializer.Serialize(memoryStream, exception, theoryData.ExceptionType, serializerOptions); + memoryStream.Seek(0, SeekOrigin.Begin); + var serializedException = JsonSerializer.Deserialize(memoryStream, theoryData.ExceptionType, serializerOptions); +#else BinaryFormatter formatter = new BinaryFormatter(); #pragma warning disable SYSLIB0011 // Type or member is obsolete formatter.Serialize(memoryStream, exception); @@ -39,6 +51,7 @@ public void SecurityTokenInvalidIssuerExceptionSerializesValues(SecurityTokenExc var serializedException = formatter.Deserialize(memoryStream); #pragma warning restore SYSLIB0011 // Type or member is obsolete +#endif theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreEqual(exception, serializedException, context); @@ -221,12 +234,7 @@ public static TheoryData ExceptionTestData #pragma warning restore CS0618 // Type or member is obsolete }; } - } - - public class CustomSecurityKey : SecurityKey - { - public override int KeySize => 1; - } + } } public class SecurityTokenExceptionTheoryData : TheoryDataBase