We generate certificates that are intended to be used for server authentication in a couple of places:

- `bin/elasticsearch-certutil http` command  ( See `CertGenUtils.generateSignedCertificate` in `HttpCertificateCommand` )
- TLS auto-configuraion for node startup ( see [`AutoConfigureNode`](https://github.com/elastic/elasticsearch/blob/814f7f9f52cb8c05db6465b9bfc818ea5d76c575/x-pack/plugin/security/cli/src/main/java/org/elasticsearch/xpack/security/cli/AutoConfigureNode.java#L454) )

In these cases we know that the certificate is meant to be used for server authentication, so we can set Extended Key Usage extension to `1.3.6.1.5.5.7.3.1`
x-pack/plugin/security/cli/src/test/java/org/elasticsearch/xpack/security/cli/CertGenUtilsTests.java
true,
            notBefore,
            notAfter,
            null
        );
        final X509Certificate[] certChain = new X509Certificate[] { endEntityCert, subCaCert, rootCaCert };
        
        assertThat(endEntityCert.getIssuerX500Principal(), equalTo(subCaCert.getSubjectX500Principal()));
        assertThat(subCaCert.getIssuerX500Principal(), equalTo(rootCaCert.getSubjectX500Principal()));
        assertThat(rootCaCert.getIssuerX500Principal(), equalTo(rootCaCert.getSubjectX500Principal()));
        
        final KeyStore trustStore = KeyStore.getInstance("PKCS12", "SunJSSE"); 
        trustStore.load(null, null);
        trustStore.setCertificateEntry("trustAnchor", rootCaCert); 
        validateEndEntityTlsChain(trustStore, certChain, true, true);
    }
    /**
     * Perform PKIX TLS certificate chain validation. This validates trust and chain correctness, not server hostname verification.
     * Wrap TrustStore with TrustManager[], and select first element that implements the X509ExtendedTrustManager interface.
     * Use it to call checkClientTrusted() and/or checkServerTrusted().
     *
     * @param trustStore       TrustStore must contain at least one trust anchor (ex: root/sub/cross/link CA certs, self-signed end entity)
     * @param certChain        Cert chain to be validated using trust anchor(s) in TrustStore. Partial chains are supported.
     * @param doTlsClientCheck Flag to enable TLS client end entity validation checking.
     * @param doTlsServerCheck Flag to enable TLS server end entity validation checking.
     * @throws Exception X509ExtendedTrustManager initialization failed, or cert chain validation failed.
     */
    public static void validateEndEntityTlsChain(
        final KeyStore trustStore,
        final X509Certificate[] certChain,