diff --git a/build/dependencies.props b/build/dependencies.props index bb1ce285ef..766072a622 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -79,7 +79,7 @@ 2.2.3 2.2.1 2.2.2 - 2.2.2 + 2.2.3 2.2.0 2.2.1 2.2.3 diff --git a/src/HealthChecks.Elasticsearch/ElasticsearchHealthCheck.cs b/src/HealthChecks.Elasticsearch/ElasticsearchHealthCheck.cs index b90785aee5..20433f3368 100644 --- a/src/HealthChecks.Elasticsearch/ElasticsearchHealthCheck.cs +++ b/src/HealthChecks.Elasticsearch/ElasticsearchHealthCheck.cs @@ -35,6 +35,11 @@ public async Task CheckHealthAsync(HealthCheckContext context settings = settings.ClientCertificate(_options.Certificate); } + if (_options.CertificateValidationCallback != null) + { + settings = settings.ServerCertificateValidationCallback(_options.CertificateValidationCallback); + } + lowLevelClient = new ElasticClient(settings); if (!_connections.TryAdd(_options.Uri, lowLevelClient)) diff --git a/src/HealthChecks.Elasticsearch/ElasticsearchOptions.cs b/src/HealthChecks.Elasticsearch/ElasticsearchOptions.cs index c9734c9545..cb18ed4a11 100644 --- a/src/HealthChecks.Elasticsearch/ElasticsearchOptions.cs +++ b/src/HealthChecks.Elasticsearch/ElasticsearchOptions.cs @@ -1,4 +1,5 @@ using System; +using System.Net.Security; using System.Security.Cryptography.X509Certificates; namespace HealthChecks.Elasticsearch @@ -11,6 +12,7 @@ public class ElasticsearchOptions public X509Certificate Certificate { get; private set; } public bool AuthenticateWithBasicCredentials { get; private set; } = false; public bool AuthenticateWithCertificate { get; private set; } = false; + public Func CertificateValidationCallback { get; private set; } public ElasticsearchOptions UseBasicAuthentication(string name, string password) { UserName = name ?? throw new ArgumentNullException(nameof(name)); @@ -37,5 +39,10 @@ public ElasticsearchOptions UseServer(string uri) return this; } + public ElasticsearchOptions UseCertificateValidationCallback(Func callback) + { + CertificateValidationCallback = callback; + return this; + } } } \ No newline at end of file