This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 9933f39770a6220ec1fa35a1a30a06d4ae98e7a0
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Dec 1 12:02:25 2026 +0000

    Add a test that a secure Tribes channel binds no clear text ports
    
    A channel with secure set to true must only accept channel messages over
    TLS. Check that neither the clear text TCP port nor the UDP port is bound
    and that a connection to the clear text port is refused.
    
    Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
 .../tribes/group/GroupChannelTlsTestBase.java      | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/test/org/apache/catalina/tribes/group/GroupChannelTlsTestBase.java 
b/test/org/apache/catalina/tribes/group/GroupChannelTlsTestBase.java
index 65a8810518..e8d79783fd 100644
--- a/test/org/apache/catalina/tribes/group/GroupChannelTlsTestBase.java
+++ b/test/org/apache/catalina/tribes/group/GroupChannelTlsTestBase.java
@@ -17,6 +17,12 @@
 package org.apache.catalina.tribes.group;
 
 import java.io.Serializable;
+import java.net.ConnectException;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -96,6 +102,46 @@ public class GroupChannelTlsTestBase {
     }
 
 
+    /*
+     * A secure channel must only accept channel messages over TLS. The plain 
(clear text) TCP port, and the UDP port,
+     * must not be bound at all otherwise a host without the pre-shared key 
could send channel messages to them.
+     */
+    @Test
+    public void testClearTextPortsNotBoundWhenSecure() throws Exception {
+        int plainPort;
+        try (ServerSocket probe = new ServerSocket(0, 1, 
InetAddress.getByName("localhost"))) {
+            plainPort = probe.getLocalPort();
+        }
+        int udpPort;
+        try (DatagramSocket probe = new DatagramSocket(0, 
InetAddress.getByName("localhost"))) {
+            udpPort = probe.getLocalPort();
+        }
+
+        GroupChannel channel = createChannel(protocol, digest);
+        // Configuring the PSK enables TLS in addition to the clear text 
ports. Secure disables the clear text ports.
+        channel.setSecure(true);
+        ReceiverBase receiver = (ReceiverBase) channel.getChannelReceiver();
+        receiver.setPort(plainPort);
+        receiver.setUdpPort(udpPort);
+        try {
+            channel.start(Channel.SND_RX_SEQ | Channel.SND_TX_SEQ);
+
+            Assert.assertTrue("The TLS port was not bound", 
receiver.getBoundSecurePort() > 0);
+            Assert.assertEquals("The clear text TCP port was bound", -1, 
receiver.getBoundPort());
+            Assert.assertEquals("The UDP port was bound", -1, 
receiver.getBoundUdpPort());
+
+            // Check with a real connection since that is what a host without 
the key would use
+            try (Socket socket = new Socket()) {
+                Assert.assertThrows("Connected to the clear text port of a 
secure channel", ConnectException.class,
+                        () -> socket.connect(new 
InetSocketAddress(InetAddress.getByName("localhost"), plainPort),
+                                2000));
+            }
+        } finally {
+            channel.stop(Channel.DEFAULT);
+        }
+    }
+
+
     private static GroupChannel createChannel(String protocol, String digest) 
throws Exception {
         GroupChannel channel = new GroupChannel();
         channel.setPskIdentity("tribes-test");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to