Skip to content

Commit fc00a17

Browse files
committed
Update Working with certificates docs
1 parent 6e8debc commit fc00a17

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/Tests/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,25 @@ namespace Tests.ClientConcepts.Certificates
1616
{
1717
/**=== Working with certificates
1818
*
19-
* If you've enabled SSL on Elasticsearch with https://www.elastic.co/products/x-pack[X-Pack] or through a
19+
* If you've enabled SSL on Elasticsearch with https://www.elastic.co/products/elastic-stack[Elastic Stack Security features], or through a
2020
* proxy in front of Elasticsearch, and the Certificate Authority (CA)
21-
* that generated the certificate is trusted by the machine running the client code, there should be nothing you'll have to do to talk
21+
* that generated the certificate is trusted by the machine running the client code, there should be nothing for you to do to talk
2222
* to the cluster over HTTPS with the client.
2323
*
24-
* If you are using your own CA which is not trusted however, .NET won't allow you to make HTTPS calls to that endpoint by default. With .NET,
25-
* you can pre-empt this though a custom validation callback on the global static
24+
* If you are using your own CA which is not trusted however, .NET won't allow you to make HTTPS calls to that endpoint by default.
25+
* With .NET Framework, you can pre-empt this though a custom validation callback on the global static
2626
* `ServicePointManager.ServerCertificateValidationCallback`. Most examples you will find doing this this will simply return `true` from the
2727
* validation callback and merrily whistle off into the sunset. **This is not advisable** as it allows *any* HTTPS traffic through in the
2828
* current `AppDomain` *without* any validation. Here's a concrete example:
2929
*
3030
*/
3131
public class WorkingWithCertificates
3232
{
33-
/** Imagine you deploy a web application that talks to Elasticsearch over HTTPS through NEST, and also uses some third party SOAP/WSDL endpoint;
34-
* by setting
33+
/** Imagine you deploy a web application that talks to Elasticsearch over HTTPS using NEST, and also uses some third party SOAP/WSDL endpoint.
34+
* By setting the following
3535
*/
36-
#if !DOTNETCORE
3736
public void ServerValidationCallback() => ServicePointManager.ServerCertificateValidationCallback +=
3837
(sender, cert, chain, errors) => true;
39-
#endif
4038
/**
4139
* validation will not be performed for HTTPS connections to *both* Elasticsearch *and* that external web service.
4240
*
@@ -58,7 +56,7 @@ public class DenyAllCertificatesCluster : SslAndKpiXPackCluster
5856
{
5957
protected override ConnectionSettings ConnectionSettings(ConnectionSettings s) => s
6058
.ServerCertificateValidationCallback((o, certificate, chain, errors) => false)
61-
.ServerCertificateValidationCallback(CertificateValidations.DenyAll); // <1> synonymous with the previous lambda expression
59+
.ServerCertificateValidationCallback(CertificateValidations.DenyAll); // <1> use a lambda expression or `CertificateValidations.DenyAll` to deny all validation
6260
}
6361

6462
//hide
@@ -85,8 +83,8 @@ protected override ConnectionSettings ConnectionSettings(ConnectionSettings s) =
8583
public class AllowAllCertificatesCluster : SslAndKpiXPackCluster
8684
{
8785
protected override ConnectionSettings ConnectionSettings(ConnectionSettings s) => s
88-
.ServerCertificateValidationCallback((o, certificate, chain, errors) => true)
89-
.ServerCertificateValidationCallback(CertificateValidations.AllowAll); // <1> synonymous with the previous lambda expression
86+
.ServerCertificateValidationCallback((o, certificate, chain, errors) => true) // <1>
87+
.ServerCertificateValidationCallback(CertificateValidations.AllowAll); // <1> use a lambda expression or `CertificateValidations.AllowAll` to allow all validation
9088
}
9189
/**
9290
* This is not recommended in production.
@@ -109,15 +107,15 @@ protected override ConnectionSettings ConnectionSettings(ConnectionSettings s) =
109107
* If your client application has access to the public CA certificate locally, Elasticsearch.NET and NEST ship with some handy helpers
110108
* that can assert that a certificate the server presents is one that came from the local CA.
111109
*
112-
* If you use X-Pack's {ref_current}/certutil.html[+certutil+ tool] to generate SSL certificates, the generated node certificate
110+
* If you use {ref_current}/certutil.html[+elasticsearch-certutil+ tool] to generate SSL certificates, the generated node certificate
113111
* does not include the CA in the certificate chain, in order to cut down on SSL handshake size. In those case you can use
114112
* `CertificateValidations.AuthorityIsRoot` and pass it your local copy of the CA public key to assert that
115113
* the certificate the server presented was generated using it
116114
*/
117115
public class CertgenCaCluster : SslAndKpiXPackCluster
118116
{
119117
public CertgenCaCluster() : this(new SslAndKpiClusterConfiguration()) { }
120-
public CertgenCaCluster(SslAndKpiClusterConfiguration configuration) : base(configuration) { }
118+
public CertgenCaCluster(SslAndKpiClusterConfiguration configuration) : base(configuration) { }
121119
protected override ConnectionSettings ConnectionSettings(ConnectionSettings s) => s
122120
.ServerCertificateValidationCallback(
123121
CertificateValidations.AuthorityIsRoot(new X509Certificate(this.ClusterConfiguration.FileSystem.CaCertificate))
@@ -176,14 +174,13 @@ protected override ConnectionSettings ConnectionSettings(ConnectionSettings s) =
176174
/**
177175
* ==== Client Certificates
178176
*
179-
* X-Pack also allows you to configure a {xpack_current}/pki-realm.html[PKI realm] to enable user authentication
180-
* through client certificates. The {ref_current}/certutil.html[+certutil+ tool] included with X-Pack allows you to
181-
* generate client certificates as well and assign the distinguished name (DN) of the
182-
* certificate to a user with a certain role.
177+
* Elastic Stack Security features allow you to configure a {ref_current}/configuring-pki-realm.html[PKI realm] to enable user authentication
178+
* through client certificates. The {ref_current}/certutil.html[+elasticsearch-certutil+ tool] included with the default distribution
179+
* allows you to generate client certificates as well and assign the distinguished name (DN) of the certificate to a user with a certain role.
183180
*
184-
* By default, the `certutil` tool only generates a public certificate (`.cer`) and a private key `.key`. To authenticate with client certificates, you need to present both
185-
* as one certificate. The easiest way to do this is to generate a `pfx` or `p12` file from the `.cer` and `.key`
186-
* and attach these to requests using `new X509Certificate(pathToPfx)`.
181+
* By default, the `elasticsearch-certutil` tool only generates a public certificate (`.cer`) and a private key `.key`.
182+
* To authenticate with client certificates, you need to present both as one certificate. The easiest way to do this is to generate a `pfx`
183+
* or `p12` file from the `.cer` and `.key` and attach these to requests using `new X509Certificate(pathToPfx)`.
187184
*
188185
* If you do not have a way to run `openssl` or `Pvk2Pfx` to do this as part of your deployments the clients ships with a handy helper to generate one
189186
* on the fly by passing the paths to the `.cer` and `.key` files that `certutil` outputs. Sadly, this functonality is not available on .NET Core because
@@ -237,9 +234,7 @@ public class BadPkiCluster : WorkingWithCertificates.PkiCluster
237234
//[IntegrationOnly]
238235
public class BadCustomCertificatePerRequestWinsApiTests : ConnectionErrorTestBase<BadPkiCluster>
239236
{
240-
public BadCustomCertificatePerRequestWinsApiTests(BadPkiCluster cluster, EndpointUsage usage) : base(cluster, usage)
241-
{
242-
}
237+
public BadCustomCertificatePerRequestWinsApiTests(BadPkiCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
243238

244239
// hide
245240
//[I]

0 commit comments

Comments
 (0)