Skip to content

Commit

Permalink
Remove net45 (#4451)
Browse files Browse the repository at this point in the history
* Remove net45

* more stuff

* fix
  • Loading branch information
bgavrilMS committed Dec 11, 2023
1 parent f4de22e commit 22a4beb
Show file tree
Hide file tree
Showing 59 changed files with 69 additions and 1,990 deletions.
5 changes: 1 addition & 4 deletions build/platform_and_feature_flags.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
<PropertyGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) Or '$(TargetFramework)' == '$(TargetFrameworkNet6Android)'">
<DefineConstants>$(DefineConstants);ANDROID;SUPPORTS_BROKER;IS_XAMARIN_OR_UWP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == '$(TargetFrameworkNetDesktop45)' Or '$(TargetFramework)' == '$(TargetFrameworkNetDesktop462)' ">
<DefineConstants>$(DefineConstants);DESKTOP;SUPPORTS_CONFIDENTIAL_CLIENT;SUPPORTS_CUSTOM_CACHE;SUPPORTS_WIN32;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == '$(TargetFrameworkNetDesktop462)'">
<DefineConstants>$(DefineConstants);SUPPORTS_BROKER</DefineConstants>
<DefineConstants>$(DefineConstants)DESKTOP;SUPPORTS_BROKER;SUPPORTS_CONFIDENTIAL_CLIENT;SUPPORTS_CUSTOM_CACHE;SUPPORTS_WIN32</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == '$(TargetFrameworkIos)' Or '$(TargetFramework)' == '$(TargetFrameworkNet6Ios)' Or '$(TargetFramework)' == '$(TargetFrameworkNet6Mac)'">
<DefineConstants>$(DefineConstants);iOS;SUPPORTS_BROKER;IS_XAMARIN_OR_UWP</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ public PublicClientApplicationBuilder WithBroker(bool enableBroker = true)
{
#pragma warning disable CS0162 // Unreachable code detected

#if NET45
throw new PlatformNotSupportedException(
"The Windows broker is not available on .NET Framework 4.5, use at least .NET Framework 4.6.2");
#endif

#if NET462
if (Config.BrokerCreatorFunc == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ namespace Microsoft.Identity.Client.AuthScheme.PoP
internal class InMemoryCryptoProvider : IPoPCryptoProvider
{
internal /* internal for test only */ const int RsaKeySize = 2048;

#if NET45
private RSACryptoServiceProvider _signingKey;
#else
private RSA _signingKey;
#endif


public InMemoryCryptoProvider()
{
Expand All @@ -32,20 +28,16 @@ public InMemoryCryptoProvider()

private void InitializeSigningKey()
{
#if NET45
_signingKey = new RSACryptoServiceProvider(RsaKeySize);
#else
_signingKey = RSA.Create();
_signingKey.KeySize = RsaKeySize;
#endif
RSAParameters publicKeyInfo = _signingKey.ExportParameters(false);

CannonicalPublicKeyJwk = ComputeCanonicalJwk(publicKeyInfo);
}

public byte[] Sign(byte[] payload)
{
return Sign(_signingKey, payload);
return _signingKey.SignData(payload, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}

/// <summary>
Expand All @@ -56,14 +48,5 @@ private static string ComputeCanonicalJwk(RSAParameters rsaPublicKey)
{
return $@"{{""{JsonWebKeyParameterNames.E}"":""{Base64UrlHelpers.Encode(rsaPublicKey.Exponent)}"",""{JsonWebKeyParameterNames.Kty}"":""{JsonWebAlgorithmsKeyTypes.RSA}"",""{JsonWebKeyParameterNames.N}"":""{Base64UrlHelpers.Encode(rsaPublicKey.Modulus)}""}}";
}

public static byte[] Sign(RSA RsaKey, byte[] payload)
{
#if NET45
return ((RSACryptoServiceProvider)RsaKey).SignData(payload, CryptoConfig.MapNameToOID("SHA256"));
#else
return RsaKey.SignData(payload, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CertificateAndClaimsClientCredential(X509Certificate2 certificate, IDicti
oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientAssertionType, OAuth2AssertionType.JwtBearer);
oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientAssertion, assertion);

return TaskUtil.CompletedTask;
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SecretStringClientCredential(string secret)
public Task AddConfidentialClientParametersAsync(OAuth2Client oAuth2Client, ILoggerAdapter logger, ICryptographyManager cryptographyManager, string clientId, string tokenEndpoint, bool sendX5C, CancellationToken cancellationToken)
{
oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientSecret, Secret);
return TaskUtil.CompletedTask;
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Task AddConfidentialClientParametersAsync(OAuth2Client oAuth2Client, ILog
{
oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientAssertionType, OAuth2AssertionType.JwtBearer);
oAuth2Client.AddBodyParameter(OAuth2Parameter.ClientAssertion, _signedAssertion);
return TaskUtil.CompletedTask;
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFrameworkNetDesktop462>net462</TargetFrameworkNetDesktop462>
<TargetFrameworkNetStandard>netstandard2.0</TargetFrameworkNetStandard>
<TargetFrameworkNet6>net6.0</TargetFrameworkNet6>
<TargetFrameworkNet6Win>net6.0-windows</TargetFrameworkNet6Win>
<TargetFrameworkNet6Win>net6.0-windows</TargetFrameworkNet6Win>
<TargetFrameworkUap>uap10.0.17763</TargetFrameworkUap>
<Configurations>Debug;Release;Debug + MobileApps</Configurations>
</PropertyGroup>

<!-- Mobile and legacy targets - comment these out or set env variable INCLUDE_MOBILE_AND_LEGACY_TFM to speedup the build -->
<PropertyGroup Condition="'$(INCLUDE_MOBILE_AND_LEGACY_TFM)' != ''">
<TargetFrameworkNetDesktop45>net45</TargetFrameworkNetDesktop45>
<TargetFrameworkIos>Xamarin.iOS10</TargetFrameworkIos>
<TargetFrameworkAndroid9>MonoAndroid9.0</TargetFrameworkAndroid9>
<TargetFrameworkAndroid10>MonoAndroid10.0</TargetFrameworkAndroid10>
Expand All @@ -29,7 +29,7 @@

<!-- Package that includes all the TFMs https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/3863 -->
<PropertyGroup Condition="'$(NET_ONLY_INTERNAL_PACKAGE)' == ''">
<TargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(TargetFrameworkNetDesktop45);$(TargetFrameworkNetDesktop462);$(TargetFrameworkNetStandard);$(TargetFrameworkUap);$(TargetFrameworkIos);$(TargetFrameworkAndroid9);$(TargetFrameworkAndroid10);$(TargetFrameworkNet6Ios);$(TargetFrameworkNet6Android);$(TargetFrameworkNet6Mac);$(TargetFrameworkNet6);$(TargetFrameworkNet6Win);</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(TargetFrameworkNetDesktop462);$(TargetFrameworkNetStandard);$(TargetFrameworkUap);$(TargetFrameworkIos);$(TargetFrameworkAndroid9);$(TargetFrameworkAndroid10);$(TargetFrameworkNet6Ios);$(TargetFrameworkNet6Android);$(TargetFrameworkNet6Mac);$(TargetFrameworkNet6);$(TargetFrameworkNet6Win);</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(TargetFrameworkNetStandard);$(TargetFrameworkIos);$(TargetFrameworkAndroid9);$(TargetFrameworkAndroid10);$(TargetFrameworkNet6Ios);$(TargetFrameworkNet6Android);$(TargetFrameworkNet6Mac);$(TargetFrameworkNet6)</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Linux')) Or '$(NetCoreOnly)' !='' ">$(TargetFrameworkNetStandard);$(TargetFrameworkNet6)</TargetFrameworks>
</PropertyGroup>
Expand Down Expand Up @@ -88,7 +88,7 @@
<PropertyGroup Condition="'$(TargetFramework)' == '$(TargetFrameworkAndroid10)'">
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == '$(TargetFrameworkNetDesktop45)' Or '$(TargetFramework)' == '$(TargetFrameworkNetDesktop462)' ">
<PropertyGroup Condition=" '$(TargetFramework)' == '$(TargetFrameworkNetDesktop462)' ">
<!-- These are for MSAL json/* build infra -->
<DefineConstants>$(DefineConstants);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_REFLECTION_EMIT;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;$(AdditionalConstants)</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down Expand Up @@ -184,11 +184,7 @@
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == '$(TargetFrameworkNetDesktop45)' ">
<Compile Remove="$(PathToMsalSources)\PlatformsCommon\Shared\CommonCryptographyManager.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == '$(TargetFrameworkNetDesktop45)' Or '$(TargetFramework)' == '$(TargetFrameworkNetDesktop462)' ">
<ItemGroup Condition=" '$(TargetFramework)' == '$(TargetFrameworkNetDesktop462)' ">
<Compile Include="$(PathToMsalSources)\Platforms\netdesktop\**\*.cs" LinkBase="Platforms\netdesktop" />
<Compile Include="$(PathToMsalSources)\Platforms\Features\DefaultOSBrowser\**\*.cs" />
<Compile Include="$(PathToMsalSources)\Platforms\Features\WinFormsLegacyWebUi\**\*.cs" />
Expand Down
7 changes: 0 additions & 7 deletions src/client/Microsoft.Identity.Client/MsalError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,6 @@ public static class MsalError
/// </summary>
public const string RegionDiscoveryNotEnabled = "region_discovery_unavailable";

/// <summary>
/// <para>What happens?</para>MSAL cannot use the certificate for signing.
/// <para>Mitigation</para>Possible cause: use of CNG certificates with .Net classic 4.6 or lower. Either target a higher version of .NET desktop - 4.6.1 and above, or use a different certificate type (non-CNG)
/// or sign your own assertion as described at https://aka.ms/msal-net-signed-assertion
/// </summary>
public const string CryptoNet45 = "crypto_net45";

/// <summary>
/// <para>What happens?</para>The request has broker enabled and Proof-of-Possession configured but the broker does not support Proof-of-Possession
/// <para>Mitigation</para>only configure Proof-of-Possession for public clients on windows.
Expand Down
8 changes: 0 additions & 8 deletions src/client/Microsoft.Identity.Client/MsalErrorMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,6 @@ public static string RedirectUriMismatch(string expectedUri, string actualUri)

public const string ScopesRequired = "At least one scope needs to be requested for this authentication flow. ";
public const string InvalidAdalCacheMultipleRTs = "The ADAL cache is invalid as it contains multiple refresh token entries for one user. Deleting invalid ADAL cache. ";

public const string CryptoNet45 =
"Could not use the certificate for signing. See inner exception for details. " +
"Possible cause: this may be a known issue with apps build against .NET Desktop 4.6 or lower. " +
"Either target a higher version of .NET desktop - 4.6.1 and above, " +
"or use a different certificate type (non-CNG) or sign your own assertion " +
"as described at https://aka.ms/msal-net-signed-assertion. ";

public static string ExperimentalFeature(string methodName)
{
return string.Format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ private unsafe void AcquireCredentials()

if (_logonId != 0)
{
#if NET45
authIdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long)));
#else
authIdPtr = Marshal.AllocHGlobal(Marshal.SizeOf<long>());
#endif
Marshal.StructureToPtr(_logonId, authIdPtr, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,7 @@ internal static class LibSystem
public static IntPtr GetGlobal(IntPtr handle, string symbol)
{
IntPtr ptr = dlsym(handle, symbol);
#if NET45
var structure = Marshal.PtrToStructure(ptr, typeof(IntPtr));
#else
var structure = Marshal.PtrToStructure<IntPtr>(ptr);
#endif
return (IntPtr)structure;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ public static bool IsWamSupportedOs()
{
try
{
#if NET45
var OsVersionInfo = new OSVERSIONINFOEXW { dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEXW)) };
#else
var OsVersionInfo = new OSVERSIONINFOEXW { dwOSVersionInfoSize = Marshal.SizeOf<OSVERSIONINFOEXW>() };
#endif
if (RtlGetVersion(ref OsVersionInfo) == NT_STATUS_SUCCESS)
{
switch (OsVersionInfo.wProductType)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ private bool TryGetExecutablePath(string executable, out string path)
return false;
}

public override IDeviceAuthManager CreateDeviceAuthManager() => new NetCoreDeviceAuthManager();
public override IDeviceAuthManager CreateDeviceAuthManager()
{
return new DeviceAuthManager(CryptographyManager);
}
}
}
Loading

0 comments on commit 22a4beb

Please sign in to comment.