Skip to content

Commit 294d5b8

Browse files
committed
fix x509 for new socketshandler
do not use automatic wrapper for dotnet 5+
1 parent 996fac6 commit 294d5b8

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/Docker.DotNet.X509/CertificateCredentials.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,39 @@ public override HttpMessageHandler GetHandler(HttpMessageHandler handler)
4242

4343
#if NET6_0_OR_GREATER
4444
if (handler is SocketsHttpHandler nativeHandler)
45+
{
46+
nativeHandler.UseProxy = true;
47+
nativeHandler.AllowAutoRedirect = true;
48+
nativeHandler.MaxAutomaticRedirections = 20;
49+
nativeHandler.Proxy = WebRequest.DefaultWebProxy;
50+
nativeHandler.SslOptions = new System.Net.Security.SslClientAuthenticationOptions
51+
{
52+
ClientCertificates = new X509CertificateCollection { _certificate },
53+
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
54+
EnabledSslProtocols = SslProtocols.Tls12,
55+
RemoteCertificateValidationCallback = (message, certificate, chain, errors) => ServerCertificateValidationCallback?.Invoke(message, certificate, chain, errors) ?? false
56+
};
57+
return nativeHandler;
58+
}
4559
#else
4660
if (handler is HttpClientHandler nativeHandler)
47-
#endif
4861
{
4962
if (!nativeHandler.ClientCertificates.Contains(_certificate))
5063
{
5164
nativeHandler.ClientCertificates.Add(_certificate);
5265
}
5366

54-
nativeHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
55-
nativeHandler.CheckCertificateRevocationList = false;
5667
nativeHandler.UseProxy = true;
5768
nativeHandler.AllowAutoRedirect = true;
5869
nativeHandler.MaxAutomaticRedirections = 20;
5970
nativeHandler.Proxy = WebRequest.DefaultWebProxy;
71+
nativeHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
72+
nativeHandler.CheckCertificateRevocationList = false;
6073
nativeHandler.SslProtocols = SslProtocols.Tls12;
6174
nativeHandler.ServerCertificateCustomValidationCallback += (message, certificate, chain, errors) => ServerCertificateValidationCallback?.Invoke(message, certificate, chain, errors) ?? false;
62-
6375
return nativeHandler;
6476
}
77+
#endif
6578

6679
return handler;
6780
}

0 commit comments

Comments
 (0)