Kafka java consumer SSL handshake Error java.security.cert.CertificateException No subject alternative names present
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When working with Apache Kafka using the Java client over SSL/TLS, you might encounter the SSL handshake error: java.security.cert.CertificateException: No subject alternative names present. This error is fairly common when configuring SSL certificates and can cause considerable confusion if not understood and addressed promptly. This article explores the cause of the error and provides solutions to mitigate it.
Understanding the Error
At its core, the error java.security.cert.CertificateException: No subject alternative names present occurs when the SSL/TLS certificate being used does not contain the Subject Alternative Names (SAN) field, or the field does not include the correct identifiers for the client or server being authenticated.
What are Subject Alternative Names?
Subject Alternative Names are extensions to the X.509 specification that allow various values to be associated with a security certificate. These values can include:
- Domain names
- IP addresses
- Email addresses
The SAN field allows a single certificate to be valid for multiple domain names and IP addresses, enhancing flexibility and management.
Why SAN is Important in SSL/TLS Certificates?
When a Kafka client connects to a server over SSL/TLS, it checks whether the server's certificate contains the SAN entries that correspond with the hostname or IP address the client used in its connection request. This check is a part of the Hostname Verification process, ensuring that the certificate was issued for the server the client is actually talking to, which is vital for preventing Man-In-The-Middle (MITM) attacks.
Tracing the Issue in Java
Java’s SSL/TLS implementation checks the SAN field by default. If the server's certificate lacks a SAN entry that matches the hostname used by the client, Java will throw the CertificateException.
To illustrate, consider the following scenario where the Kafka server's certificate only contains the Common Name (CN) field:
If the client accesses the server at the URL https://example.com but the certificate does not contain a SAN entry for example.com, Java will fail the hostname verification and throw the error.
Resolving the Issue
To solve this problem, you need to ensure that your SSL/TLS certificates contain the appropriate SAN entries. The resolution typically involves the following steps:
- Regenerate Certificates: When creating or renewing your certificates, use a tool or utility (e.g., OpenSSL) that supports SAN. For example, when using OpenSSL, you can specify SANs in the certificate signing request (CSR) or directly in the OpenSSL configuration.
- Configure Java Properly: On the client-side, ensure your Java application is set to use the correct hostname that matches one of the SAN entries in the server's certificate.
- Debugging: Use tools like
openssl s_client -connect <host>:<port>to manually inspect the SSL handshake and view the SAN entries in the server's certificate.
Summary Table
| Aspect | Description |
| Issue | SSL handshake error due to missing SAN in certificates |
| Cause | Certificates without SAN entries or mismatch between accessed hostname and SAN entries |
| Solution | Ensure all certificates contain correct SAN entries for all hostnames and IP addresses used. |
| Verification Tool | openssl s_client -connect <host>:<port> |
| Impact If Unresolved | Failure in establishing secure communication between Kafka client and server |
By understanding the importance of the SAN field in SSL/TLS certificates and ensuring that your certificates are properly configured, you can prevent the java.security.cert.CertificateException: No subject alternative names present error and establish a secure, trusted communication channel in your Kafka environment.

