Search in sources :

Example 1 with UpstreamTlsContext

use of io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext in project grpc-java by grpc.

the class TlsContextManagerImpl method findOrCreateClientSslContextProvider.

@Override
public SslContextProvider findOrCreateClientSslContextProvider(UpstreamTlsContext upstreamTlsContext) {
    checkNotNull(upstreamTlsContext, "upstreamTlsContext");
    CommonTlsContext.Builder builder = upstreamTlsContext.getCommonTlsContext().toBuilder();
    upstreamTlsContext = new UpstreamTlsContext(builder.build());
    return mapForClients.get(upstreamTlsContext);
}
Also used : UpstreamTlsContext(io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext) CommonTlsContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext)

Example 2 with UpstreamTlsContext

use of io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext in project grpc-java by grpc.

the class SdsProtocolNegotiatorsTest method clientSdsProtocolNegotiatorNewHandler_withTlsContextAttribute.

@Test
public void clientSdsProtocolNegotiatorNewHandler_withTlsContextAttribute() {
    UpstreamTlsContext upstreamTlsContext = CommonTlsContextTestsUtil.buildUpstreamTlsContext(CommonTlsContext.newBuilder().build());
    ClientSdsProtocolNegotiator pn = new ClientSdsProtocolNegotiator(InternalProtocolNegotiators.plaintext());
    GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
    ChannelLogger logger = mock(ChannelLogger.class);
    doNothing().when(logger).log(any(ChannelLogLevel.class), anyString());
    when(mockHandler.getNegotiationLogger()).thenReturn(logger);
    TlsContextManager mockTlsContextManager = mock(TlsContextManager.class);
    when(mockHandler.getEagAttributes()).thenReturn(Attributes.newBuilder().set(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER, new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager)).build());
    ChannelHandler newHandler = pn.newHandler(mockHandler);
    assertThat(newHandler).isNotNull();
    assertThat(newHandler).isInstanceOf(ClientSdsHandler.class);
}
Also used : ClientSdsProtocolNegotiator(io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator) UpstreamTlsContext(io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext) TlsContextManager(io.grpc.xds.TlsContextManager) ChannelLogger(io.grpc.ChannelLogger) NoopChannelLogger(io.grpc.internal.TestUtils.NoopChannelLogger) ChannelHandler(io.netty.channel.ChannelHandler) GrpcHttp2ConnectionHandler(io.grpc.netty.GrpcHttp2ConnectionHandler) ChannelLogLevel(io.grpc.ChannelLogger.ChannelLogLevel) Test(org.junit.Test)

Example 3 with UpstreamTlsContext

use of io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext in project grpc-java by grpc.

the class TlsContextManagerTest method createClientSslContextProvider_releaseInstance.

@Test
public void createClientSslContextProvider_releaseInstance() {
    UpstreamTlsContext upstreamTlsContext = CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true);
    TlsContextManagerImpl tlsContextManagerImpl = new TlsContextManagerImpl(mockClientFactory, mockServerFactory);
    SslContextProvider mockProvider = mock(SslContextProvider.class);
    when(mockClientFactory.create(upstreamTlsContext)).thenReturn(mockProvider);
    SslContextProvider clientSecretProvider = tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext);
    assertThat(clientSecretProvider).isSameInstanceAs(mockProvider);
    verify(mockProvider, never()).close();
    when(mockProvider.getUpstreamTlsContext()).thenReturn(upstreamTlsContext);
    tlsContextManagerImpl.releaseClientSslContextProvider(mockProvider);
    verify(mockProvider, times(1)).close();
}
Also used : UpstreamTlsContext(io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext) Test(org.junit.Test)

Example 4 with UpstreamTlsContext

use of io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext in project grpc-java by grpc.

the class TlsContextManagerTest method createClientSslContextProvider.

@Test
public void createClientSslContextProvider() {
    Bootstrapper.BootstrapInfo bootstrapInfoForClient = CommonBootstrapperTestUtils.buildBootstrapInfo("google_cloud_private_spiffe-client", CLIENT_KEY_FILE, CLIENT_PEM_FILE, CA_PEM_FILE, null, null, null, null);
    UpstreamTlsContext upstreamTlsContext = CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe-client", false);
    TlsContextManagerImpl tlsContextManagerImpl = new TlsContextManagerImpl(bootstrapInfoForClient);
    SslContextProvider clientSecretProvider = tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext);
    assertThat(clientSecretProvider).isNotNull();
    SslContextProvider clientSecretProvider1 = tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext);
    assertThat(clientSecretProvider1).isSameInstanceAs(clientSecretProvider);
}
Also used : Bootstrapper(io.grpc.xds.Bootstrapper) UpstreamTlsContext(io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext) Test(org.junit.Test)

Example 5 with UpstreamTlsContext

use of io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext in project grpc-java by grpc.

the class TlsContextManagerTest method createClientSslContextProvider_differentInstance.

@Test
public void createClientSslContextProvider_differentInstance() {
    Bootstrapper.BootstrapInfo bootstrapInfoForClient = CommonBootstrapperTestUtils.buildBootstrapInfo("google_cloud_private_spiffe-client", CLIENT_KEY_FILE, CLIENT_PEM_FILE, CA_PEM_FILE, "cert-instance-2", CLIENT_KEY_FILE, CLIENT_PEM_FILE, CA_PEM_FILE);
    UpstreamTlsContext upstreamTlsContext = CommonTlsContextTestsUtil.buildUpstreamTlsContext("google_cloud_private_spiffe-client", false);
    TlsContextManagerImpl tlsContextManagerImpl = new TlsContextManagerImpl(bootstrapInfoForClient);
    SslContextProvider clientSecretProvider = tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext);
    assertThat(clientSecretProvider).isNotNull();
    UpstreamTlsContext upstreamTlsContext1 = CommonTlsContextTestsUtil.buildUpstreamTlsContext("cert-instance-2", true);
    SslContextProvider clientSecretProvider1 = tlsContextManagerImpl.findOrCreateClientSslContextProvider(upstreamTlsContext1);
    assertThat(clientSecretProvider1).isNotSameInstanceAs(clientSecretProvider);
}
Also used : Bootstrapper(io.grpc.xds.Bootstrapper) UpstreamTlsContext(io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext) Test(org.junit.Test)

Aggregations

UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)24 Test (org.junit.Test)21 Bootstrapper (io.grpc.xds.Bootstrapper)11 CertProviderClientSslContextProvider (io.grpc.xds.internal.certprovider.CertProviderClientSslContextProvider)7 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)5 StatusRuntimeException (io.grpc.StatusRuntimeException)4 DownstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext)4 CertificateValidationContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 CommonTlsContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext)2 FakeClock (io.grpc.internal.FakeClock)2 ClientSdsHandler (io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsHandler)2 SslContext (io.netty.handler.ssl.SslContext)2 SSLException (javax.net.ssl.SSLException)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Thresholds (io.envoyproxy.envoy.config.cluster.v3.CircuitBreakers.Thresholds)1 Cluster (io.envoyproxy.envoy.config.cluster.v3.Cluster)1 DiscoveryType (io.envoyproxy.envoy.config.cluster.v3.Cluster.DiscoveryType)1 SocketAddress (io.envoyproxy.envoy.config.core.v3.SocketAddress)1 ClusterLoadAssignment (io.envoyproxy.envoy.config.endpoint.v3.ClusterLoadAssignment)1