Skip to content

Commit 45810c8

Browse files
authoredFeb 5, 2025··
Merge pull request #253 from gasbytes/HttpsURLConnection/ImpactOnSNI-patch
wolfjsse: auto-enable SNI for HttpsURLConnection
2 parents 1e530a9 + d075893 commit 45810c8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed
 

‎src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,23 @@ private void setLocalServerNames() {
890890
* This allows users to enable legacy hostname-based SNI behavior
891891
* through java.security configuration rather than JVM arguments. */
892892
boolean autoSNI = "true".equalsIgnoreCase(
893-
Security.getProperty("wolfjsse.autoSNI"));
893+
Security.getProperty("wolfjsse.autoSNI"));
894+
895+
/* Detect HttpsURLConnection usage by checking:
896+
* - Client mode is set (client-side connection)
897+
* - Has hostname from URL
898+
* - Has peer address from socket
899+
* - No explicit SNI configuration
900+
* This pattern is unique to HttpsURLConnection initialization
901+
*/
902+
boolean isHttpsConnection = this.clientMode &&
903+
this.hostname != null &&
904+
this.peerAddr != null &&
905+
this.params.getServerNames() == null;
906+
907+
/* Enable SNI if explicitly requested via property or if
908+
* HttpsURLConnection is detected */
909+
autoSNI = autoSNI || isHttpsConnection;
894910

895911
if (!enableSNI) {
896912
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,

0 commit comments

Comments
 (0)
Please sign in to comment.