Skip to content

Commit

Permalink
Sets sslProtocol per dotnet version (#836)
Browse files Browse the repository at this point in the history
* Sets sslProtocol per dotnet version

* Removes 'await' from 'using' and adds lint changes

---------

Co-authored-by: Ersan Bozduman <ersanbozduman@gmail.com>
  • Loading branch information
ebozduman and Ersan Bozduman authored Aug 22, 2023
1 parent e1ef9f5 commit 59865de
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Minio/Credentials/CertificateIdentityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
* limitations under the License.
*/


using System.Globalization;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web;
using CommunityToolkit.HighPerformance;
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.
Expand Down Expand Up @@ -72,8 +77,7 @@ public async ValueTask<AccessCredentials> GetCredentialsAsync()
{
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
using var stream = Encoding.UTF8.GetBytes(content).AsMemory().AsStream();
certResponse =
Utils.DeserializeXml<CertificateResponse>(stream);
certResponse = Utils.DeserializeXml<CertificateResponse>(stream);
}

if (Credentials is null && certResponse?.Cr is not null)
Expand Down Expand Up @@ -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) };

Expand Down

0 comments on commit 59865de

Please sign in to comment.