Class SslTransportLayerTest

java.lang.Object
org.apache.kafka.common.network.SslTransportLayerTest

@Tag("bazel:size:large") @Tag("bazel:shard_count:4") public class SslTransportLayerTest extends Object
Tests for the SSL transport layer. These use a test harness that runs a simple socket server that echos back responses.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    testApplicationBufferResize(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests handling of BUFFER_OVERFLOW during unwrap when application read buffer is smaller than SSL session application buffer size.
    void
    If the SSL engine ever invokes the matcher with a non-SNIHostName server name (it shouldn't, because we register the matcher for type=host_name only), the matcher must still accept the connection — same reasoning as above.
    void
    Direct unit test for SslTransportLayer.CapturingSniMatcher: when the JDK SSL engine calls matches() with the client's SNIHostName, the matcher must capture the hostname for later read-out and must always return true (returning false would abort the handshake with unrecognized_name and break the SNI-exempt-tenants flow).
    void
    testClientAuthenticationDisabledNotProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server accepts connections from a client that does not provide a certificate if client authentication is disabled
    void
    testClientAuthenticationDisabledUntrustedProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server accepts connections from a client configured with an untrusted certificate if client authentication is disabled
    void
    testClientAuthenticationRequestedNotProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server accepts connections from a client that does not provide a certificate if client authentication is requested but not required
    void
    testClientAuthenticationRequestedValidProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server accepts connections from a client configured with a valid certificate if client authentication is requested
    void
    testClientAuthenticationRequiredNotProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server does not accept connections from clients which don't provide a certificate when client authentication is required.
    void
    testClientAuthenticationRequiredUntrustedProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server does not accept connections from clients with an untrusted certificate when client authentication is required.
    void
    testClientAuthenticationRequiredValidProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server accepts connections from clients with a trusted certificate when client authentication is required.
    void
    testClientEndpointNotValidated(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    According to RFC 2818: Typically, the server has no external knowledge of what the client's identity ought to be and so checks (other than that the client has a certificate chain rooted in an appropriate CA) are not possible.
    void
    testClosePlaintext(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    testCloseSsl(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    testCustomClientAndServerSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests if client and server both can plugin customize ssl.engine.factory and talk to each other!
    void
    testCustomClientSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests if client can plugin customize ssl.engine.factory
    void
    testCustomServerSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests if server can plugin customize ssl.engine.factory
    void
    testDsaKeyPair(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests key-pair created using DSA.
    void
    testECKeyPair(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests key-pair created using EC.
    void
     
    void
    testEndpointIdentificationDisabled(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server certificate with invalid host name is accepted by a client that has disabled endpoint validation
    void
    testEndpointIdentificationNoReverseLookup(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that hostname verification is performed on the host name or address specified by the client without using reverse DNS lookup.
    void
    testEngineFactoryDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
     
    void
    testGracefulRemoteCloseDuringHandshakeRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that if the remote end closes the connection during SSL handshake while reading data, the disconnection is not treated as an authentication failure.
    void
    testGracefulRemoteCloseDuringHandshakeWrite(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that if the remote end closes the connection during SSL handshake while writing data, the disconnection is not treated as an authentication failure.
    void
    testHandleProxyProtocolBuffer(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    SSLEngine implementations may transition from NEED_UNWRAP to NEED_UNWRAP even after reading all the data from the socket.
    void
    A ClientHello with an internally-inconsistent handshakeLength (smaller than the fixed-size header fields) is malformed, not incomplete.
    void
    Partial-then-full read: the first handshakeUnwrap only has part of the ClientHello, so SNI parsing must defer; the second call sees the rest and must actually parse out the SNI host name.
    void
    Malformed bytes that begin with 0x16 but claim a record length larger than the buffer can hold make parseSniServerName return Optional.empty() — the "not enough data yet" signal.
    void
    testInterBrokerSslConfigValidation(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Verifies that inter-broker listener with validation of truststore against keystore works with configs including mutual authentication and hostname verification.
    void
    testInterBrokerSslConfigValidationFailure(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Verifies that inter-broker listener with validation of truststore against keystore fails if certs from keystore are not trusted.
    void
    testInvalidEndpointIdentification(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server certificate with invalid host name is not accepted by a client that validates server endpoint.
    void
    testInvalidKeyPassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that client connections cannot be created to a server if key password is invalid
    void
    testInvalidKeystorePassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that channels cannot be created if keystore cannot be loaded
    void
    testInvalidSecureRandomImplementation(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that an invalid SecureRandom implementation cannot be configured
    void
    testInvalidSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests invalid ssl.engine.factory plugin class
    void
    testInvalidTruststorePassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that channels cannot be created if truststore cannot be loaded
    void
    testIOExceptionsDuringHandshakeRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that IOExceptions from read during SSL handshake are not treated as authentication failures.
    void
    testIOExceptionsDuringHandshakeWrite(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that IOExceptions from write during SSL handshake are not treated as authentication failures.
    void
    testListenerConfigOverride(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that disabling client authentication as a listener override has the desired effect.
    void
    testLogMessageForSslHandshakeException(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Verify the log message from the exception thrown when Endpoint validation fails.
    void
    testNetReadBufferResize(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests handling of BUFFER_UNDERFLOW during unwrap when network read buffer is smaller than SSL session packet buffer size.
    void
    testNetworkThreadTimeRecorded(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that time spent on the network thread is accumulated on each channel
    void
    testNetWriteBufferResize(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests handling of BUFFER_OVERFLOW during wrap when network write buffer is smaller than SSL session packet buffer size.
    void
    testNullTruststorePassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that client connections can be created to a server if null truststore password is used
    void
    testPeerNotifiedOfHandshakeFailure(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that handshake failures are propagated only after writes complete, even when there are delays in writes to ensure that clients see an authentication exception rather than a connection failure.
    void
    testPeerNotifiedOfHandshakeFailureWithClientSideDelay(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    testPemFiles(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests PEM key store and trust store files which don't have store passwords.
    void
    testPemFilesWithoutClientKeyPassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Test with PEM key store files without key password for client key store.
    void
    testPemFilesWithoutServerKeyPassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Test with PEM key store files without key password for server key store.We don't allow this with PEM files since unprotected private key on disk is not safe.
    void
    testProxyEngineConsumesFullSocketRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    testRequestClientAuthDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests dynamic update of ssl.client.auth config
    void
     
    void
    testSelectorPollReadSize(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    selector.poll() should be able to fetch more data than netReadBuffer from the socket.
    void
    testServerCipherDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    testServerKeystoreDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests reconfiguration of server keystore.
    void
    testServerKeystoreDynamicUpdateWithNewSubjectAltName(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    testServerRequestMetrics(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
    End-to-end verification that the JDK SSL engine actually invokes our SslTransportLayer.CapturingSniMatcher during a real server-side handshake, and that SslTransportLayer.sniHostName() returns the value the client sent.
    void
    INC-377 regression, asserting the matcher path and the legacy SslUtil path behave identically for a non-compliant SNI.
    void
    testServerTruststoreDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests reconfiguration of server truststore.
    void
    testSHA1SignedCerts(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Verifies that SHA-1 signed certificates work for backwards compatibility
    void
    testSslEnabledProtocolsDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     
    void
     
    void
    suppliedClusterId() derives the tenant cluster id (used in audit / handshake-failure error reporting) purely from the SNI host name returned by SslTransportLayer.sniHostName(), regardless of whether that host name came from the JDK matcher or the legacy parser.
    void
    testTlsDefaults(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that connection succeeds with the default TLS version.
    void
    testUngracefulRemoteCloseDuringHandshakeRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that if the remote end closes connection ungracefully during SSL handshake while reading data, the disconnection is not treated as an authentication failure.
    void
    testUngracefulRemoteCloseDuringHandshakeWrite(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that if the remote end closes connection ungracefully during SSL handshake while writing data, the disconnection is not treated as an authentication failure.
    void
    testUnsupportedCiphers(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that connections cannot be made with unsupported TLS cipher suites
    void
    testValidEndpointIdentificationCN(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server certificate with CN containing valid hostname is accepted by a client that connects using hostname and validates server endpoint.
    void
    testValidEndpointIdentificationSanDns(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server certificate with SubjectAltName containing the valid hostname is accepted by a client that connects using the hostname and validates server endpoint.
    void
    testValidEndpointIdentificationSanIp(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
    Tests that server certificate with SubjectAltName containing valid IP address is accepted by a client that connects using IP address and validates server endpoint.
    void
    testWithProxyProtocolEngine(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
     

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SslTransportLayerTest

      public SslTransportLayerTest()
  • Method Details

    • teardown

      @AfterEach public void teardown() throws Exception
      Throws:
      Exception
    • testValidEndpointIdentificationSanDns

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testValidEndpointIdentificationSanDns(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server certificate with SubjectAltName containing the valid hostname is accepted by a client that connects using the hostname and validates server endpoint.
      Throws:
      Exception
    • testValidEndpointIdentificationSanIp

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testValidEndpointIdentificationSanIp(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server certificate with SubjectAltName containing valid IP address is accepted by a client that connects using IP address and validates server endpoint.
      Throws:
      Exception
    • testValidEndpointIdentificationCN

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testValidEndpointIdentificationCN(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server certificate with CN containing valid hostname is accepted by a client that connects using hostname and validates server endpoint.
      Throws:
      Exception
    • testEndpointIdentificationNoReverseLookup

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testEndpointIdentificationNoReverseLookup(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that hostname verification is performed on the host name or address specified by the client without using reverse DNS lookup. Certificate is created with hostname, client connection uses IP address. Endpoint validation must fail.
      Throws:
      Exception
    • testClientEndpointNotValidated

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientEndpointNotValidated(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      According to RFC 2818:
      Typically, the server has no external knowledge of what the client's identity ought to be and so checks (other than that the client has a certificate chain rooted in an appropriate CA) are not possible. If a server has such knowledge (typically from some source external to HTTP or TLS) it SHOULD check the identity as described above.
      However, Java SSL engine does not perform any endpoint validation for client IP address. Hence it is safe to avoid reverse DNS lookup while creating the SSL engine. This test checks that client validation does not fail even if the client certificate has an invalid hostname. This test is to ensure that if client endpoint validation is added to Java in future, we can detect and update Kafka SSL code to enable validation on the server-side and provide hostname if required.
      Throws:
      Exception
    • testInvalidEndpointIdentification

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInvalidEndpointIdentification(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server certificate with invalid host name is not accepted by a client that validates server endpoint. Server certificate uses wrong hostname as common name to trigger endpoint validation failure.
      Throws:
      Exception
    • testEndpointIdentificationDisabled

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testEndpointIdentificationDisabled(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server certificate with invalid host name is accepted by a client that has disabled endpoint validation
      Throws:
      Exception
    • testClientAuthenticationRequiredValidProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationRequiredValidProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server accepts connections from clients with a trusted certificate when client authentication is required.
      Throws:
      Exception
    • testListenerConfigOverride

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testListenerConfigOverride(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that disabling client authentication as a listener override has the desired effect.
      Throws:
      Exception
    • testClientAuthenticationRequiredUntrustedProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationRequiredUntrustedProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server does not accept connections from clients with an untrusted certificate when client authentication is required.
      Throws:
      Exception
    • testClientAuthenticationRequiredNotProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationRequiredNotProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server does not accept connections from clients which don't provide a certificate when client authentication is required.
      Throws:
      Exception
    • testClientAuthenticationDisabledUntrustedProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationDisabledUntrustedProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server accepts connections from a client configured with an untrusted certificate if client authentication is disabled
      Throws:
      Exception
    • testClientAuthenticationDisabledNotProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationDisabledNotProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server accepts connections from a client that does not provide a certificate if client authentication is disabled
      Throws:
      Exception
    • testClientAuthenticationRequestedValidProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationRequestedValidProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server accepts connections from a client configured with a valid certificate if client authentication is requested
      Throws:
      Exception
    • testClientAuthenticationRequestedNotProvided

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClientAuthenticationRequestedNotProvided(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that server accepts connections from a client that does not provide a certificate if client authentication is requested but not required
      Throws:
      Exception
    • testSHA1SignedCerts

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testSHA1SignedCerts(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Verifies that SHA-1 signed certificates work for backwards compatibility
      Throws:
      Exception
    • testDsaKeyPair

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsForTLS2Provider.class) public void testDsaKeyPair(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests key-pair created using DSA.
      Throws:
      Exception
    • testECKeyPair

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testECKeyPair(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests key-pair created using EC.
      Throws:
      Exception
    • testPemFiles

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testPemFiles(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests PEM key store and trust store files which don't have store passwords.
      Throws:
      Exception
    • testPemFilesWithoutClientKeyPassword

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testPemFilesWithoutClientKeyPassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Test with PEM key store files without key password for client key store.
      Throws:
      Exception
    • testPemFilesWithoutServerKeyPassword

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testPemFilesWithoutServerKeyPassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Test with PEM key store files without key password for server key store.We don't allow this with PEM files since unprotected private key on disk is not safe.
      Throws:
      Exception
    • testInvalidSecureRandomImplementation

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInvalidSecureRandomImplementation(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
      Tests that an invalid SecureRandom implementation cannot be configured
    • testInvalidTruststorePassword

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInvalidTruststorePassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
      Tests that channels cannot be created if truststore cannot be loaded
    • testInvalidKeystorePassword

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInvalidKeystorePassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
      Tests that channels cannot be created if keystore cannot be loaded
    • testNullTruststorePassword

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testNullTruststorePassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that client connections can be created to a server if null truststore password is used
      Throws:
      Exception
    • testInvalidKeyPassword

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInvalidKeyPassword(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that client connections cannot be created to a server if key password is invalid
      Throws:
      Exception
    • testTlsDefaults

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testTlsDefaults(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that connection succeeds with the default TLS version.
      Throws:
      Exception
    • testUnsupportedCiphers

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testUnsupportedCiphers(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that connections cannot be made with unsupported TLS cipher suites
      Throws:
      Exception
    • testServerRequestMetrics

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testServerRequestMetrics(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testSelectorPollReadSize

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testSelectorPollReadSize(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      selector.poll() should be able to fetch more data than netReadBuffer from the socket.
      Throws:
      Exception
    • testNetReadBufferResize

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testNetReadBufferResize(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests handling of BUFFER_UNDERFLOW during unwrap when network read buffer is smaller than SSL session packet buffer size.
      Throws:
      Exception
    • testNetWriteBufferResize

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testNetWriteBufferResize(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests handling of BUFFER_OVERFLOW during wrap when network write buffer is smaller than SSL session packet buffer size.
      Throws:
      Exception
    • testApplicationBufferResize

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testApplicationBufferResize(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests handling of BUFFER_OVERFLOW during unwrap when application read buffer is smaller than SSL session application buffer size.
      Throws:
      Exception
    • testNetworkThreadTimeRecorded

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) @Disabled public void testNetworkThreadTimeRecorded(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that time spent on the network thread is accumulated on each channel
      Throws:
      Exception
    • testIOExceptionsDuringHandshakeRead

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testIOExceptionsDuringHandshakeRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that IOExceptions from read during SSL handshake are not treated as authentication failures.
      Throws:
      Exception
    • testIOExceptionsDuringHandshakeWrite

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testIOExceptionsDuringHandshakeWrite(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that IOExceptions from write during SSL handshake are not treated as authentication failures.
      Throws:
      Exception
    • testUngracefulRemoteCloseDuringHandshakeRead

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testUngracefulRemoteCloseDuringHandshakeRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that if the remote end closes connection ungracefully during SSL handshake while reading data, the disconnection is not treated as an authentication failure.
      Throws:
      Exception
    • testUngracefulRemoteCloseDuringHandshakeWrite

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testUngracefulRemoteCloseDuringHandshakeWrite(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that if the remote end closes connection ungracefully during SSL handshake while writing data, the disconnection is not treated as an authentication failure.
      Throws:
      Exception
    • testGracefulRemoteCloseDuringHandshakeRead

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testGracefulRemoteCloseDuringHandshakeRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that if the remote end closes the connection during SSL handshake while reading data, the disconnection is not treated as an authentication failure.
      Throws:
      Exception
    • testGracefulRemoteCloseDuringHandshakeWrite

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testGracefulRemoteCloseDuringHandshakeWrite(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that if the remote end closes the connection during SSL handshake while writing data, the disconnection is not treated as an authentication failure.
      Throws:
      Exception
    • testPeerNotifiedOfHandshakeFailure

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testPeerNotifiedOfHandshakeFailure(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests that handshake failures are propagated only after writes complete, even when there are delays in writes to ensure that clients see an authentication exception rather than a connection failure.
      Throws:
      Exception
    • testPeerNotifiedOfHandshakeFailureWithClientSideDelay

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testPeerNotifiedOfHandshakeFailureWithClientSideDelay(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testCloseSsl

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testCloseSsl(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testClosePlaintext

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testClosePlaintext(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testInterBrokerSslConfigValidation

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInterBrokerSslConfigValidation(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Verifies that inter-broker listener with validation of truststore against keystore works with configs including mutual authentication and hostname verification.
      Throws:
      Exception
    • testInterBrokerSslConfigValidationFailure

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInterBrokerSslConfigValidationFailure(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
      Verifies that inter-broker listener with validation of truststore against keystore fails if certs from keystore are not trusted.
    • testServerKeystoreDynamicUpdate

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testServerKeystoreDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests reconfiguration of server keystore. Verifies that existing connections continue to work with old keystore and new connections work with new keystore.
      Throws:
      Exception
    • testServerKeystoreDynamicUpdateWithNewSubjectAltName

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testServerKeystoreDynamicUpdateWithNewSubjectAltName(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testServerTruststoreDynamicUpdate

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testServerTruststoreDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests reconfiguration of server truststore. Verifies that existing connections continue to work with old truststore and new connections work with new truststore.
      Throws:
      Exception
    • testServerCipherDynamicUpdate

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testServerCipherDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testSslEnabledProtocolsDynamicUpdate

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testSslEnabledProtocolsDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testEngineFactoryDynamicUpdate

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testEngineFactoryDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testRequestClientAuthDynamicUpdate

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testRequestClientAuthDynamicUpdate(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests dynamic update of ssl.client.auth config
      Throws:
      Exception
    • testCustomClientSslEngineFactory

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testCustomClientSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests if client can plugin customize ssl.engine.factory
      Throws:
      Exception
    • testCustomServerSslEngineFactory

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testCustomServerSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests if server can plugin customize ssl.engine.factory
      Throws:
      Exception
    • testCustomClientAndServerSslEngineFactory

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testCustomClientAndServerSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Tests if client and server both can plugin customize ssl.engine.factory and talk to each other!
      Throws:
      Exception
    • testInvalidSslEngineFactory

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testInvalidSslEngineFactory(org.apache.kafka.common.network.SslTransportLayerTest.Args args)
      Tests invalid ssl.engine.factory plugin class
    • testLogMessageForSslHandshakeException

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testLogMessageForSslHandshakeException(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Verify the log message from the exception thrown when Endpoint validation fails.
      Throws:
      Exception
    • testWithProxyProtocolEngine

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testWithProxyProtocolEngine(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testProxyEngineConsumesFullSocketRead

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testProxyEngineConsumesFullSocketRead(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testHandleProxyProtocolBuffer

      @ParameterizedTest @ArgumentsSource(org.apache.kafka.common.network.SslTransportLayerTest.SslTransportLayerArgumentsProvider.class) public void testHandleProxyProtocolBuffer(org.apache.kafka.common.network.SslTransportLayerTest.Args args) throws Exception
      Throws:
      Exception
    • testHandshakeUnwrapContinuesUnwrappingOnNeedUnwrapAfterAllBytesRead

      @Test public void testHandshakeUnwrapContinuesUnwrappingOnNeedUnwrapAfterAllBytesRead() throws IOException
      SSLEngine implementations may transition from NEED_UNWRAP to NEED_UNWRAP even after reading all the data from the socket. This test ensures we continue unwrapping and not break early. Please refer KAFKA-16305 for more information.
      Throws:
      IOException
    • testSSLEngineCloseInboundInvokedOnClose

      @Test public void testSSLEngineCloseInboundInvokedOnClose() throws IOException
      Throws:
      IOException
    • testGatheringWrite

      @Test @Disabled("This test needs to be fixed for ce-kafka") public void testGatheringWrite() throws IOException
      Throws:
      IOException
    • testScatteringRead

      @Test public void testScatteringRead() throws IOException
      Throws:
      IOException
    • testEnableIpFiltering

      @Test public void testEnableIpFiltering()
    • testCapturingSniMatcherCapturesHostNameAndAccepts

      @Test public void testCapturingSniMatcherCapturesHostNameAndAccepts()
      Direct unit test for SslTransportLayer.CapturingSniMatcher: when the JDK SSL engine calls matches() with the client's SNIHostName, the matcher must capture the hostname for later read-out and must always return true (returning false would abort the handshake with unrecognized_name and break the SNI-exempt-tenants flow).
    • testCapturingSniMatcherAcceptsNonHostNameServerNameWithoutCapturing

      @Test public void testCapturingSniMatcherAcceptsNonHostNameServerNameWithoutCapturing()
      If the SSL engine ever invokes the matcher with a non-SNIHostName server name (it shouldn't, because we register the matcher for type=host_name only), the matcher must still accept the connection — same reasoning as above. We just don't capture anything in that case.
    • testServerSslTransportLayerRejectsNonCompliantSniCleanly

      @ParameterizedTest @ValueSource(booleans={true,false}) public void testServerSslTransportLayerRejectsNonCompliantSniCleanly(boolean useJdkSniMatcher) throws Exception
      INC-377 regression, asserting the matcher path and the legacy SslUtil path behave identically for a non-compliant SNI. A client host_name with non-LDH characters (e.g. an underscore) is rejected by the JDK engine itself during ClientHello processing — with a checked
      invalid reference
      SSLProtocolException
      — regardless of which SNI extraction path is configured, because the engine's extension decoder (not our matcher or parser) is what rejects it. So switching to the JDK matcher does not change the behaviour: the malformed SNI still fails the handshake cleanly with a checked SSLException, never letting an unchecked exception escape the handshake path the way the original SslUtil parser did. Nothing is captured in either mode.

      SNIHostName's own constructor rejects non-LDH names, so we put a raw server name of type host_name on the wire to reproduce what a non-compliant client actually sends.

      Throws:
      Exception
    • testSuppliedClusterIdExtractedFromSniHostName

      @Test public void testSuppliedClusterIdExtractedFromSniHostName()
      suppliedClusterId() derives the tenant cluster id (used in audit / handshake-failure error reporting) purely from the SNI host name returned by SslTransportLayer.sniHostName(), regardless of whether that host name came from the JDK matcher or the legacy parser. It must extract lkc-<id> from an lkc-prefixed host name and return empty for anything else.
    • testHandshakeUnwrapTreatsBufferUnderflowAsTransient

      @Test public void testHandshakeUnwrapTreatsBufferUnderflowAsTransient() throws IOException
      Malformed bytes that begin with 0x16 but claim a record length larger than the buffer can hold make parseSniServerName return Optional.empty() — the "not enough data yet" signal. It must not crash handshakeUnwrap and must not be latched as a permanent parse failure (more bytes might still arrive).
      Throws:
      IOException
    • testHandshakeUnwrapLatchesPermanentSniParseFailureOnMalformedClientHello

      @Test public void testHandshakeUnwrapLatchesPermanentSniParseFailureOnMalformedClientHello() throws IOException
      A ClientHello with an internally-inconsistent handshakeLength (smaller than the fixed-size header fields) is malformed, not incomplete. parseSniServerName converts this into an SSLProtocolException via parseHandshake's catch, which parseSNIHostNameIfPresent then latches as a permanent failure so downstream rejection (KafkaChannel#sniHostNameIsValid) can fail the connection cleanly.
      Throws:
      IOException
    • testHandshakeUnwrapRetriesSniParseAcrossPartialReads

      @Test public void testHandshakeUnwrapRetriesSniParseAcrossPartialReads() throws IOException
      Partial-then-full read: the first handshakeUnwrap only has part of the ClientHello, so SNI parsing must defer; the second call sees the rest and must actually parse out the SNI host name. This exercises the retry path: limit-bounding the buffer to received bytes, not latching sniParsingFailed on an empty Optional, and not single-shot-clearing shouldParseSNI after the first attempt.
      Throws:
      IOException
    • testServerSslTransportLayerCapturesSniDuringRealHandshake

      @ParameterizedTest @ValueSource(strings={"TLSv1.2","TLSv1.3"}) public void testServerSslTransportLayerCapturesSniDuringRealHandshake(String tlsProtocol) throws Exception
      End-to-end verification that the JDK SSL engine actually invokes our SslTransportLayer.CapturingSniMatcher during a real server-side handshake, and that SslTransportLayer.sniHostName() returns the value the client sent. Builds a matched client/server pair of real SSLEngines via the production SslFactory, constructs the server SslTransportLayer through the same constructor used in production (so installSniMatcherIfNeeded runs), drives the handshake in-memory until completion, and asserts capture.

      Parameterized over TLS 1.2 and 1.3 — TLS 1.3 specifically is the version that triggered INC-10922 because its larger and immediately-sent ClientHello widened the partial-read race window that exposed the bug in the old custom parser. Both versions must capture SNI correctly through the new matcher path.

      Throws:
      Exception