Skip to content

Commit 79ebe40

Browse files
committed
Introduce flag for fallback to use the xds channel authority if no SNI is determined to be used.
1 parent a734f83 commit 79ebe40

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,6 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
634634
X509TrustManager x509TrustManager) {
635635
super(next, negotiationLogger);
636636
this.sslContext = Preconditions.checkNotNull(sslContext, "sslContext");
637-
// TODO: For empty authority and fallback flag
638-
// GRPC_USE_CHANNEL_AUTHORITY_IF_NO_SNI_APPLICABLE present, we should parse authority
639-
// but prevent it from being used for SAN validation in the TrustManager.
640637
if (authority != null) {
641638
HostPort hostPort = parseAuthority(authority);
642639
this.host = hostPort.host;

xds/src/main/java/io/grpc/xds/internal/security/DynamicSslContextProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public abstract class DynamicSslContextProvider extends SslContextProvider {
4444
@Nullable protected final CertificateValidationContext staticCertificateValidationContext;
4545
@Nullable protected AbstractMap.SimpleImmutableEntry<SslContext, X509TrustManager>
4646
sslContextAndTrustManager;
47-
private boolean autoSniSanValidationDoesNotApply;
47+
protected boolean autoSniSanValidationDoesNotApply;
4848

4949
protected DynamicSslContextProvider(
5050
BaseTlsContext tlsContext, CertificateValidationContext staticCertValidationContext) {

xds/src/main/java/io/grpc/xds/internal/security/SecurityProtocolNegotiators.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static final class ClientSecurityHandler
194194
private final GrpcHttp2ConnectionHandler grpcHandler;
195195
private final SslContextProviderSupplier sslContextProviderSupplier;
196196
private final String sni;
197+
private final boolean autoSniSanValidationDoesNotApply;
197198

198199
ClientSecurityHandler(
199200
GrpcHttp2ConnectionHandler grpcHandler,
@@ -215,10 +216,19 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
215216
EnvoyServerProtoData.BaseTlsContext tlsContext = sslContextProviderSupplier.getTlsContext();
216217
UpstreamTlsContext upstreamTlsContext = ((UpstreamTlsContext) tlsContext);
217218
if (CertificateUtils.isXdsSniEnabled) {
218-
sni = upstreamTlsContext.getAutoHostSni() && !Strings.isNullOrEmpty(endpointHostname)
219+
String sniToUse = upstreamTlsContext.getAutoHostSni()
220+
&& !Strings.isNullOrEmpty(endpointHostname)
219221
? endpointHostname : upstreamTlsContext.getSni();
222+
if (sniToUse.isEmpty() && CertificateUtils.useChannelAuthorityIfNoSniApplicable) {
223+
sniToUse = grpcHandler.getAuthority();
224+
autoSniSanValidationDoesNotApply = true;
225+
} else {
226+
autoSniSanValidationDoesNotApply = false;
227+
}
228+
sni = sniToUse;
220229
} else {
221230
sni = grpcHandler.getAuthority();
231+
autoSniSanValidationDoesNotApply = false;
222232
}
223233
}
224234

@@ -261,7 +271,7 @@ public void onException(Throwable throwable) {
261271
ctx.fireExceptionCaught(throwable);
262272
}
263273
},
264-
false);
274+
autoSniSanValidationDoesNotApply);
265275
}
266276

267277
@Override

xds/src/main/java/io/grpc/xds/internal/security/trust/CertificateUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
public final class CertificateUtils {
3333
public static boolean isXdsSniEnabled = GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_SNI", false);
34+
public static boolean useChannelAuthorityIfNoSniApplicable
35+
= GrpcUtil.getFlag("GRPC_USE_CHANNEL_AUTHORITY_IF_NO_SNI_APPLICABLE", false);
3436

3537
/**
3638
* Generates X509Certificate array from a file on disk.

0 commit comments

Comments
 (0)