Skip to content

Commit 2a7f62b

Browse files
authored
Add experimental config to disable TLS1.3 (#6025) (#6026)
(cherry picked from commit 9dbd786)
1 parent 3aa3f8b commit 2a7f62b

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
178178
public static IMemoryStreamFactory DefaultMemoryStreamFactory { get; } = Elasticsearch.Net.MemoryStreamFactory.Default;
179179
private bool _enableThreadPoolStats;
180180
private bool _enableApiVersioningHeader;
181+
private bool _unsafeDisableTls13;
181182

182183
private string _userAgent = ConnectionConfiguration.DefaultUserAgent;
183184
private readonly Func<HttpMethod, int, bool> _statusCodeToResponseSuccess;
@@ -239,7 +240,6 @@ false when int.TryParse(apiVersioningEnabled, out var isEnabledValue) => isEnabl
239240
int? IConnectionConfigurationValues.MaxRetries => _maxRetries;
240241
TimeSpan? IConnectionConfigurationValues.MaxRetryTimeout => _maxRetryTimeout;
241242
IMemoryStreamFactory IConnectionConfigurationValues.MemoryStreamFactory => _memoryStreamFactory;
242-
243243
Func<Node, bool> IConnectionConfigurationValues.NodePredicate => _nodePredicate;
244244
Action<IApiCallDetails> IConnectionConfigurationValues.OnRequestCompleted => _completedRequestHandler;
245245
Action<RequestData> IConnectionConfigurationValues.OnRequestDataCreated => _onRequestDataCreated;
@@ -252,10 +252,8 @@ false when int.TryParse(apiVersioningEnabled, out var isEnabledValue) => isEnabl
252252
IElasticsearchSerializer IConnectionConfigurationValues.RequestResponseSerializer => UseThisRequestResponseSerializer;
253253
TimeSpan IConnectionConfigurationValues.RequestTimeout => _requestTimeout;
254254
TimeSpan IConnectionConfigurationValues.DnsRefreshTimeout => _dnsRefreshTimeout;
255-
256255
Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool> IConnectionConfigurationValues.ServerCertificateValidationCallback =>
257256
_serverCertificateValidationCallback;
258-
259257
IReadOnlyCollection<int> IConnectionConfigurationValues.SkipDeserializationForStatusCodes => _skipDeserializationForStatusCodes;
260258
TimeSpan? IConnectionConfigurationValues.SniffInformationLifeSpan => _sniffLifeSpan;
261259
bool IConnectionConfigurationValues.SniffsOnConnectionFault => _sniffOnConnectionFault;
@@ -267,9 +265,9 @@ false when int.TryParse(apiVersioningEnabled, out var isEnabledValue) => isEnabl
267265
bool IConnectionConfigurationValues.TransferEncodingChunked => _transferEncodingChunked;
268266
bool IConnectionConfigurationValues.EnableTcpStats => _enableTcpStats;
269267
bool IConnectionConfigurationValues.EnableThreadPoolStats => _enableThreadPoolStats;
270-
271268
MetaHeaderProvider IConnectionConfigurationValues.MetaHeaderProvider { get; } = new MetaHeaderProvider();
272269
bool IConnectionConfigurationValues.EnableApiVersioningHeader => _enableApiVersioningHeader;
270+
bool IConnectionConfigurationValues.UnsafeDisableTls13 => _unsafeDisableTls13;
273271

274272
void IDisposable.Dispose() => DisposeManagedResources();
275273

@@ -620,6 +618,10 @@ public T SkipDeserializationForStatusCodes(params int[] statusCodes) =>
620618

621619
public T EnableThreadPoolStats(bool enableThreadPoolStats = true) => Assign(enableThreadPoolStats, (a, v) => a._enableThreadPoolStats = v);
622620

621+
/// <inheritdoc cref="IConnectionConfigurationValues.UnsafeDisableTls13"/>
622+
[Obsolete("This API is temporary, experiemental setting and will be removed in a future minor release.")]
623+
public T UnsafeDisableTls13(bool disableTls13 = true) => Assign(disableTls13, (a, v) => a._unsafeDisableTls13 = v);
624+
623625
protected virtual void DisposeManagedResources()
624626
{
625627
_connectionPool?.Dispose();

src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,17 @@ public interface IConnectionConfigurationValues : IDisposable
286286
/// <para> NOTE: You need at least Elasticsearch 7.11 and higher before you can enable this setting on the client</para>
287287
/// </summary>
288288
bool EnableApiVersioningHeader { get; }
289+
290+
/// <summary>
291+
/// This is an EXPERIMENTAL configuration value which forces the use only of TLS 1.1 and 1.2 during the TLS negotiation. This is a
292+
/// temporary workaround for an known TLS negotiation issue with some Cloud regions from Windows 11 for apps targetting .NET 5.0+.
293+
/// It should not be used other than to avoid that specific limitation.
294+
/// <para>
295+
/// This is a temporary, experiemental configuration setting which is likely to be removed in a future release, once the TLS negotiation
296+
/// issue is resolved.
297+
/// </para>
298+
/// </summary>
299+
[Obsolete("This API is temporary, experiemental setting and will be removed in a future minor release.")]
300+
bool UnsafeDisableTls13 { get; }
289301
}
290302
}

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ protected virtual HttpMessageHandler CreateHttpClientHandler(RequestData request
208208
{
209209
var handler = new HttpClientHandler { AutomaticDecompression = requestData.HttpCompression ? GZip | Deflate : None, };
210210

211+
// This supports a temporary workaround for https://github.com/elastic/cloud/issues/87734 which disables the use of TLS 1.3.
212+
#pragma warning disable CS0618 // Type or member is obsolete
213+
if (requestData.ConnectionSettings.UnsafeDisableTls13)
214+
#pragma warning restore CS0618 // Type or member is obsolete
215+
{
216+
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12;
217+
}
218+
211219
// same limit as desktop clr
212220
if (requestData.ConnectionSettings.ConnectionLimit > 0)
213221
try

0 commit comments

Comments
 (0)