Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to configure SSL/TLS verification level #1460

Closed
Lucas3oo opened this issue Oct 13, 2020 · 8 comments
Closed

Option to configure SSL/TLS verification level #1460

Lucas3oo opened this issue Oct 13, 2020 · 8 comments
Labels
type: feature A new feature
Milestone

Comments

@Lucas3oo
Copy link

Feature Request

Need an option to only skip host name verification of the server certificate.
Typically when using AWS Redis the host name is a random name.
So we use a pre-defined DNS name for it instead but then the certificate by AWS will not match the hostname.

There is an option called "verifyPeer" but when that is set to false not only host name verification is skipped also all kinds of verification of certificates are skipped. So that option can't be use in production.

Describe the solution you'd like

A dedicated option to only skip host name verification just like standard SSL factory has.

Describe alternatives you've considered

Teachability, Documentation, Adoption, Migration Strategy

@Lucas3oo Lucas3oo added the type: feature A new feature label Oct 13, 2020
@mp911de
Copy link
Collaborator

mp911de commented Oct 13, 2020

What a few drivers provide is a SSL mode enum (like disabled, enabled, verify ca, verify full). On the other side, there are several ways how to verify a certificate (subject/SAN check, issuer trust relationship, validity period, fingerprinting). Especially fingerprint checking gains on popularity. I wonder whether we can combine these aspects somehow.

@mp911de
Copy link
Collaborator

mp911de commented Nov 21, 2020

Probably, there's a misconception. Java's HostnameVerifier runs after TrustManager has performed the SSL handshake and has validated certificates. Note that you can already configure a custom TrustManagerFactory.

What we can do here is introducing an SSL verification level as we're additionally configuring SSLParameters.setEndpointIdentificationAlgorithm("HTTPS") by default.

That intent could be expressed through RedisUri.setVerifyPeer(Verification.CERT) vs. RedisUri.setVerifyPeer(Verification.FULL) (corresponds with setVerifyPeer(true)).

@mp911de mp911de added this to the 6.1 M1 milestone Nov 21, 2020
@KowalczykBartek
Copy link
Contributor

Is there any other option to implement this than providing custom X509ExtendedTrustManager to sslContextBuilder in SslConnectionBuilder ?

sslContextBuilder.trustManager(new TrustManagerFactory(new TrustManagerFactorySpi() {
    @Override
    protected void engineInit(KeyStore keyStore) {
        // NOOP
    }
    @Override
    protected TrustManager[] engineGetTrustManagers() {
        // Provide a custom trust manager, this manager trust all certificates
        return new TrustManager[] {
                new X509ExtendedTrustManager() {
                    @Override
                    public void checkClientTrusted(final X509Certificate[] chain, final String authType,
                            final Socket socket) throws CertificateException
                    {
                        // NOOP
                    }

                    @Override
                    public void checkServerTrusted(final X509Certificate[] chain, final String authType,
                            final Socket socket) throws CertificateException
                    {
                        // NOOP
                    }

                    @Override
                    public void checkClientTrusted(final X509Certificate[] chain, final String authType,
                            final SSLEngine engine) throws CertificateException
                    {
                        // NOOP
                    }

                    @Override
                    public void checkServerTrusted(final X509Certificate[] chain, final String authType,
                            final SSLEngine engine) throws CertificateException
                    {
                        // NOOP
                    }

                    @Override
                    public void checkClientTrusted(
                            java.security.cert.X509Certificate[] x509Certificates, String s) {
                        // NOOP
                    }

                    @Override
                    public void checkServerTrusted(
                            java.security.cert.X509Certificate[] x509Certificates, String s) {
                        // NOOP
                    }

                    @Override
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return EmptyArrays.EMPTY_X509_CERTIFICATES;
                    }
                }
        };
    }

    @Override
    protected void engineInit(ManagerFactoryParameters managerFactoryParameters) {
    }
}, null, TrustManagerFactory.getDefaultAlgorithm()) {
});

@mp911de mp911de changed the title Option to skip host name verification when using SSL/TLS Option to configure SSL/TLS verification level Jan 8, 2021
mp911de added a commit that referenced this issue Jan 8, 2021
RedisURI.setVerifyPeer(…) now accepts SslVerifyMode to configure the level of SSL verification. setVerifyPeer(true) (default) maps to FULL,  setVerifyPeer(false) maps to NONE. SslVerifyMode.CA allows verifying the certificate validity using the default (or configured) trust manager without peer name verification.
@mp911de
Copy link
Collaborator

mp911de commented Jan 8, 2021

That's in place now via RedisURI.setVerifyPeer(CA).

@mp911de mp911de closed this as completed Jan 8, 2021
@shikharkhanna
Copy link

can TLS 1.2 be configured now using Lettuce??

@mp911de
Copy link
Collaborator

mp911de commented Mar 16, 2021

Yes, via SslOptions.sslParameters(…).

@shikharkhanna
Copy link

cool thanks

@vikasmav
Copy link

setVerifyPeer

If we are using Spring Data Redis with Lettuce Client then how can we set this flag. Currently I do not see any provision to set this up who are using spring data redis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

5 participants