-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-13418: Support key updates with TLS 1.3 #11966
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
16355ff
Extract Tls12SelectorTest
ijuma ba68610
Remove unused `securityProtocol` and redundant `poll`
ijuma 193b09b
Introduce DefaultTlsSelectorTest
ijuma cd794bb
Support key updates with TLS 1.3
ijuma bee2ee8
Fix checkstyle
ijuma 80850c1
Rename DefaultTlsSelectorTest to Tls13SelectorTest and only run it wi…
ijuma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,10 +110,6 @@ public void tearDown() throws Exception { | |
| } | ||
| } | ||
|
|
||
| public SecurityProtocol securityProtocol() { | ||
| return SecurityProtocol.PLAINTEXT; | ||
| } | ||
|
|
||
| protected Map<String, Object> clientConfigs() { | ||
| return new HashMap<>(); | ||
| } | ||
|
|
@@ -1015,7 +1011,6 @@ public void testChannelCloseWhileProcessingReceives() throws Exception { | |
|
|
||
| private String blockingRequest(String node, String s) throws IOException { | ||
| selector.send(createSend(node, s)); | ||
| selector.poll(1000L); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed since it's redundant. |
||
| while (true) { | ||
| selector.poll(1000L); | ||
| for (NetworkReceive receive : selector.completedReceives()) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
clients/src/test/java/org/apache/kafka/common/network/Tls12SelectorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kafka.common.network; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.net.InetSocketAddress; | ||
| import java.security.GeneralSecurityException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.kafka.common.config.SslConfigs; | ||
| import org.apache.kafka.test.TestSslUtils; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class Tls12SelectorTest extends SslSelectorTest { | ||
|
|
||
| @Override | ||
| protected Map<String, Object> createSslClientConfigs(File trustStoreFile) | ||
| throws GeneralSecurityException, IOException { | ||
| Map<String, Object> configs = TestSslUtils.createSslConfig(false, false, Mode.CLIENT, | ||
| trustStoreFile, "client"); | ||
| configs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, asList("TLSv1.2")); | ||
| return configs; | ||
| } | ||
|
|
||
| /** | ||
| * Renegotiation is not supported when TLS 1.2 is used (renegotiation was removed from TLS 1.3) | ||
| */ | ||
| @Test | ||
| public void testRenegotiationFails() throws Exception { | ||
| String node = "0"; | ||
| // create connections | ||
| InetSocketAddress addr = new InetSocketAddress("localhost", server.port); | ||
| selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE); | ||
|
|
||
| // send echo requests and receive responses | ||
| while (!selector.isChannelReady(node)) { | ||
| selector.poll(1000L); | ||
| } | ||
| selector.send(createSend(node, node + "-" + 0)); | ||
| selector.poll(0L); | ||
| server.renegotiate(); | ||
| selector.send(createSend(node, node + "-" + 1)); | ||
| long expiryTime = System.currentTimeMillis() + 2000; | ||
|
|
||
| List<String> disconnected = new ArrayList<>(); | ||
| while (!disconnected.contains(node) && System.currentTimeMillis() < expiryTime) { | ||
| selector.poll(10); | ||
| disconnected.addAll(selector.disconnected().keySet()); | ||
| } | ||
| assertTrue(disconnected.contains(node), "Renegotiation should cause disconnection"); | ||
| } | ||
| } |
92 changes: 92 additions & 0 deletions
92
clients/src/test/java/org/apache/kafka/common/network/Tls13SelectorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kafka.common.network; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.net.InetSocketAddress; | ||
| import java.security.GeneralSecurityException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.kafka.common.config.SslConfigs; | ||
| import org.apache.kafka.test.TestSslUtils; | ||
| import org.apache.kafka.test.TestUtils; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.condition.EnabledForJreRange; | ||
| import org.junit.jupiter.api.condition.JRE; | ||
|
|
||
| @EnabledForJreRange(min = JRE.JAVA_11) // TLS 1.3 is only supported with Java 11 and newer | ||
| public class Tls13SelectorTest extends SslSelectorTest { | ||
|
|
||
| @Override | ||
| protected Map<String, Object> createSslClientConfigs(File trustStoreFile) throws GeneralSecurityException, IOException { | ||
| Map<String, Object> configs = TestSslUtils.createSslConfig(false, false, Mode.CLIENT, | ||
| trustStoreFile, "client"); | ||
| configs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, asList("TLSv1.3")); | ||
| return configs; | ||
| } | ||
|
|
||
| /** | ||
| * TLS 1.3 has a post-handshake key and IV update, which will update the sending and receiving keys | ||
| * for one side of the connection. | ||
| * | ||
| * Key Usage Limits will trigger an update when the algorithm limits are reached, but the default | ||
| * value is too large (2^37 bytes of plaintext data) for a unit test. This value can be overridden | ||
| * via the security property `jdk.tls.keyLimits`, but that's also difficult to achieve in a unit | ||
| * test. | ||
| * | ||
| * Applications can also trigger an update by calling `SSLSocket.startHandshake()` or | ||
| * `SSLEngine.beginHandshake()` (this would trigger `renegotiation` with TLS 1.2) and that's the | ||
| * approach we take here. | ||
| */ | ||
| @Test | ||
| public void testKeyUpdate() throws Exception { | ||
| String node = "0"; | ||
| // create connections | ||
| InetSocketAddress addr = new InetSocketAddress("localhost", server.port); | ||
| selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE); | ||
| // send echo requests and receive responses | ||
| while (!selector.isChannelReady(node)) { | ||
| selector.poll(1000L); | ||
| } | ||
| selector.send(createSend(node, node + "-" + 0)); | ||
| selector.poll(0L); | ||
| server.renegotiate(); | ||
| selector.send(createSend(node, node + "-" + 1)); | ||
| List<NetworkReceive> received = new ArrayList<>(); | ||
| TestUtils.waitForCondition(() -> { | ||
| try { | ||
| selector.poll(1000L); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| for (NetworkReceive receive : selector.completedReceives()) { | ||
| if (receive.source().equals(node)) | ||
| received.add(receive); | ||
| } | ||
| return received.size() == 2; | ||
| }, "Expected two receives, got " + received.size()); | ||
|
|
||
| assertEquals(asList("0-0", "0-1"), received.stream().map(this::asString).collect(Collectors.toList())); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not used.