Skip to content

Conversation

@tan9
Copy link

@tan9 tan9 commented Dec 22, 2025

Summary

Fixes #2529

This PR fixes SSL certificate validation to properly handle IP address entries (type 7) in the Subject Alternative Name (SAN) extension, in addition to DNS names (type 2).

Problem

When connecting to SQL Server using an IP address with SSL encryption enabled, the driver throws an SSLHandshakeException with "Failed to validate the server name" even when the certificate's SAN contains that IP address. This is because SQLServerCertificateUtils.validateServerNameInCertificate() only checks for DNS name entries (type 2) and ignores IP address entries (type 7).

Solution

Updated the certificate validation logic to also check for IP address entries in the SAN extension. This allows connections via IP address when the certificate's SAN contains that IP, without requiring the hostNameInCertificate workaround.

Changes

  • Modified SQLServerCertificateUtils.java to handle SAN type 7 (IP Address) entries
  • Added unit tests in SSLCertificateValidationTest.java to verify both DNS and IP address validation

@tan9
Copy link
Author

tan9 commented Dec 22, 2025

@microsoft-github-policy-service agree company="Chunghwa Telecom"

Fix SSL certificate validation to check for IP address entries (type 7)
in Subject Alternative Name extension, in addition to DNS names (type 2).
This allows connections via IP address when the certificate's SAN
contains that IP, without requiring the hostNameInCertificate workaround.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server certificate Subject Alternative Name of type IP Address is not taken into account in server name verification

1 participant