4646public final class TransportSocketSnapshot implements Snapshot <TransportSocket > {
4747
4848 private static final Logger logger = LoggerFactory .getLogger (TransportSocketSnapshot .class );
49- private static boolean warnedNoVerify ;
5049
5150 private final TransportSocket transportSocket ;
5251 @ Nullable
@@ -106,8 +105,12 @@ private static ClientTlsSpec buildClientTlsSpec(
106105 @ Nullable UpstreamTlsContext upstreamTlsContext ,
107106 @ Nullable TlsCertificateSnapshot tlsCertificate ,
108107 @ Nullable CertificateValidationContextSnapshot validationContext ) {
109- final ClientTlsSpecBuilder specBuilder = ClientTlsSpec .builder ()
110- .endpointIdentificationAlgorithm ("" );
108+ final ClientTlsSpecBuilder specBuilder = ClientTlsSpec .builder ();
109+ final boolean autoSniSanValidation = upstreamTlsContext != null &&
110+ upstreamTlsContext .getAutoSniSanValidation ();
111+ if (!autoSniSanValidation ) {
112+ specBuilder .endpointIdentificationAlgorithm ("" );
113+ }
111114 if (upstreamTlsContext != null ) {
112115 final List <String > alpn = upstreamTlsContext .getCommonTlsContext ().getAlpnProtocolsList ();
113116 if (!alpn .isEmpty ()) {
@@ -122,10 +125,15 @@ private static ClientTlsSpec buildClientTlsSpec(
122125 if (trustedCa != null ) {
123126 specBuilder .trustedCertificates (trustedCa );
124127 } else if (systemRootCerts ) {
125- // use java default root CAs, also enable JSSE
126- specBuilder .endpointIdentificationAlgorithm ("HTTPS" );
128+ // use java default root CAs
127129 } else {
128- warnNoVerifyOnce ();
130+ if (autoSniSanValidation ) {
131+ throw new IllegalArgumentException (
132+ "'auto_sni_san_validation' was configured without configuring a trusted CA" );
133+ }
134+ logger .warn ("TLS peer verification is disabled: validation_context has no " +
135+ "trusted_ca and system_root_certs is unset. " +
136+ "Set 'system_root_certs: \\ {}' or provide trusted_ca." );
129137 verifiersBuilder .add (TlsPeerVerifierFactory .noVerify ());
130138 }
131139
@@ -136,7 +144,9 @@ private static ClientTlsSpec buildClientTlsSpec(
136144 verifiersBuilder .addAll (verifierFactories );
137145 }
138146 } else {
139- // don't verify ca certs if no validation context is configured
147+ // No validation context — don't verify peer certs (matches Envoy SSL_VERIFY_NONE).
148+ logger .warn ("TLS peer verification is disabled: no validation_context configured. " +
149+ "Configure a validation_context with trusted_ca or system_root_certs." );
140150 verifiersBuilder .add (TlsPeerVerifierFactory .noVerify ());
141151 }
142152 if (tlsCertificate != null ) {
@@ -152,16 +162,6 @@ private static ClientTlsSpec buildClientTlsSpec(
152162 return specBuilder .build ();
153163 }
154164
155- private static void warnNoVerifyOnce () {
156- if (!warnedNoVerify ) {
157- warnedNoVerify = true ;
158- logger .warn ("TLS peer verification is disabled because validation context has no trusted CA " +
159- "and system_root_certs is unset. " +
160- "Set 'system_root_certs: {}' in the validation context " +
161- "to use the default Java TLS roots." );
162- }
163- }
164-
165165 @ Override
166166 public boolean equals (Object object ) {
167167 if (this == object ) {
0 commit comments