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

Custom cipher list with BoringSSL breaks in 4.1.31.Final #8442

Closed
njhill opened this issue Oct 30, 2018 · 7 comments
Closed

Custom cipher list with BoringSSL breaks in 4.1.31.Final #8442

njhill opened this issue Oct 30, 2018 · 7 comments

Comments

@njhill
Copy link
Member

njhill commented Oct 30, 2018

Expected behavior

TLS continues to work in 4.1.31.Final when providing an explicit list of ciphers via SslContextBuilder.ciphers(...).

Actual behavior

After upgrading, my SslContextBuilder.build() throws:

Caused by: java.lang.IllegalArgumentException: unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384(ECDHE-ECDSA-AES256-SHA384)
       at io.netty.handler.ssl.CipherSuiteConverter.convertToCipherStrings(CipherSuiteConverter.java:418)
       at io.netty.handler.ssl.ReferenceCountedOpenSslContext.<init>(ReferenceCountedOpenSslContext.java:252)
       ... 34 more

It looks like this is due to changes in #8293, in particular this check in CipherSuiteConverter.convertToCipherStrings() which throws if false. Should it just continue instead of throwing so that the current cipherSuite is excluded from the lists being built (since a later cipher in the list may be available)? I verified that it works as before with this modification.

Minimal yet complete reproducer code (or URL to code)

KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(null,null);
String[] ciphers = ((SSLSocketFactory)SSLSocketFactory.getDefault()).getDefaultCipherSuites();
SslContextBuilder.forServer(kmf).sslProvider(SslProvider.OPENSSL) 
    .ciphers(Arrays.asList(ciphers)).build();

Netty version

4.1.31.Final

JVM version (e.g. java -version)

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

OS version (e.g. uname -a)

Linux 3.10.0-862.14.4.el7.x86_64

@normanmaurer
Copy link
Member

normanmaurer commented Oct 30, 2018 via email

@normanmaurer
Copy link
Member

Seems like before we only did the check in ReferenceCountedSslEngine. I just wonder what is more correct as it could also be surprising to configure something and then have Netty partial ignore it

@normanmaurer
Copy link
Member

@njhill actually yeah let’s just do what you proposed as this should give the least surprises to people. Will change and do a release after it

@normanmaurer
Copy link
Member

normanmaurer commented Oct 30, 2018

@njhill actually no... I think it works as expected now as this is consistent across SSLEngine implementations:

    @Test
    public void test() throws Exception {
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(null,null);
        String[] ciphers = ((SSLSocketFactory)SSLSocketFactory.getDefault()).getDefaultCipherSuites();
        List<String> cipherList = new ArrayList<String>();
        Collections.addAll(cipherList, ciphers);
        cipherList.add("CustomCipher");
        SSLEngine client = null;
        try {
            clientSslCtx = SslContextBuilder.forServer(kmf).sslProvider(sslClientProvider())
                                            .ciphers(cipherList).build();
            client = clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
            fail();
        } catch (IllegalArgumentException expected) {
            
        } catch (SSLException expected) {

        } finally {
            cleanupClientSslEngine(client);
        }
    }

This now pass with all SSLEngine implementations we test (JDK, netty-tcnative, netty-tcnative-boringssl-static, conscrypt). WDYT ?

normanmaurer added a commit that referenced this issue Oct 30, 2018
…implementations correctly.

Motivation:

#8442 reported that we fail to build a SslContext when an invalid cipher is used with netty-tcnative-boringssl-static, while it worked before. This test verifies that this is now consistent with all other SSLEngine implementations.

Modifications:

Add test-case to verify consistent behaviour

Result:

More tests to assert consistent behaviour across SSLEngine implementations
@normanmaurer
Copy link
Member

@njhill #8443

normanmaurer added a commit that referenced this issue Oct 30, 2018
…implementations correctly.

Motivation:

#8442 reported that we fail to build a SslContext when an invalid cipher is used with netty-tcnative-boringssl-static, while it worked before. This test verifies that this is now consistent with all other SSLEngine implementations.

Modifications:

Add test-case to verify consistent behaviour

Result:

More tests to assert consistent behaviour across SSLEngine implementations
@njhill
Copy link
Member Author

njhill commented Oct 30, 2018

Thanks @normanmaurer and sorry for leaving you hanging, I was debugging late and open this right before I fell asleep :)

To answer your questions - yes it worked before with openssl (boringssl) and still works with the JDK provider (since the ciphers are valid in that case).

Now I understand more what's going on I agree the new behaviour seems reasonable, however my code actually does this:

String[] ciphers = ((SSLSocketFactory)SSLSocketFactory.getDefault()).getDefaultCipherSuites();
SslContextBuilder.forServer(kmf).sslProvider(OpenSsl.supportsKeyManagerFactory()
        ? SslProvider.OPENSSL : SslProvider.JDK).ciphers(cipherList).build();

So the difference now is that the cipher suite list needs to be tailored depending on the provider type provided, rather than having the builder choose the valid subset in each case. This sounds fine to me, since I guess like you said it will catch unsupported ones earlier in the case they are included unintentionally.

normanmaurer added a commit that referenced this issue Oct 30, 2018
…implementations correctly. (#8443)

Motivation:

#8442 reported that we fail to build a SslContext when an invalid cipher is used with netty-tcnative-boringssl-static, while it worked before. This test verifies that this is now consistent with all other SSLEngine implementations.

Modifications:

Add test-case to verify consistent behaviour

Result:

More tests to assert consistent behaviour across SSLEngine implementations
@normanmaurer
Copy link
Member

As discussed works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants