Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sets sslProtocol per dotnet version #836

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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