From 59865de5f13de5f4fe15bdde832cf790422e2708 Mon Sep 17 00:00:00 2001 From: ebozduman Date: Tue, 22 Aug 2023 10:22:07 -0700 Subject: [PATCH] Sets sslProtocol per dotnet version (#836) * Sets sslProtocol per dotnet version * Removes 'await' from 'using' and adds lint changes --------- Co-authored-by: Ersan Bozduman --- .../CertificateIdentityProvider.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Minio/Credentials/CertificateIdentityProvider.cs b/Minio/Credentials/CertificateIdentityProvider.cs index d6f914e0..6dae299a 100644 --- a/Minio/Credentials/CertificateIdentityProvider.cs +++ b/Minio/Credentials/CertificateIdentityProvider.cs @@ -15,8 +15,8 @@ * limitations under the License. */ + using System.Globalization; -using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Web; @@ -24,6 +24,11 @@ using Minio.DataModel; using Minio.Exceptions; using Minio.Helper; +#if (NET472_OR_GREATER || NET6_0_OR_GREATER) +using System.Security.Authentication; +#else +using System.Net; +#endif /* * Certificate Identity Credential provider. @@ -72,8 +77,7 @@ public async ValueTask GetCredentialsAsync() { var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); using var stream = Encoding.UTF8.GetBytes(content).AsMemory().AsStream(); - certResponse = - Utils.DeserializeXml(stream); + certResponse = Utils.DeserializeXml(stream); } if (Credentials is null && certResponse?.Cr is not null) @@ -118,10 +122,12 @@ public CertificateIdentityProvider Build() builder.Query = query.ToString(); PostEndpoint = builder.Uri; - var handler = new HttpClientHandler - { - ClientCertificateOptions = ClientCertificateOption.Manual, SslProtocols = SslProtocols.Tls12 - }; + var handler = new HttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual }; +#if (NET472_OR_GREATER || NET6_0_OR_GREATER) + handler.SslProtocols = SslProtocols.Tls12; +#else + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; +#endif _ = handler.ClientCertificates.Add(ClientCertificate); HttpClient ??= new HttpClient(handler) { BaseAddress = new Uri(StsEndpoint) };