mirror of https://github.com/grpc/grpc-java.git
xds: security code refactoring/renaming (#9555)
* xds: security code refactoring/renaming 1) move certprovider package under security 2) refactor inner Factory into CertProviderClientSslContextProviderFactory and CertProviderServerSslContextProviderFactory 3) Make CertProviderClientSslContextProvider and CertProviderServerSslContextProvider non-public 4) use only public (non package private) types like SslContextProvider (instead of CertProviderClientSslContextProvider etc)
This commit is contained in:
parent
0cda133c52
commit
6f8e44a7f5
|
@ -20,23 +20,23 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import io.grpc.xds.Bootstrapper.BootstrapInfo;
|
import io.grpc.xds.Bootstrapper.BootstrapInfo;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
import io.grpc.xds.internal.certprovider.CertProviderClientSslContextProvider;
|
|
||||||
import io.grpc.xds.internal.security.ReferenceCountingMap.ValueFactory;
|
import io.grpc.xds.internal.security.ReferenceCountingMap.ValueFactory;
|
||||||
|
import io.grpc.xds.internal.security.certprovider.CertProviderClientSslContextProviderFactory;
|
||||||
|
|
||||||
/** Factory to create client-side SslContextProvider from UpstreamTlsContext. */
|
/** Factory to create client-side SslContextProvider from UpstreamTlsContext. */
|
||||||
final class ClientSslContextProviderFactory
|
final class ClientSslContextProviderFactory
|
||||||
implements ValueFactory<UpstreamTlsContext, SslContextProvider> {
|
implements ValueFactory<UpstreamTlsContext, SslContextProvider> {
|
||||||
|
|
||||||
private BootstrapInfo bootstrapInfo;
|
private BootstrapInfo bootstrapInfo;
|
||||||
private final CertProviderClientSslContextProvider.Factory
|
private final CertProviderClientSslContextProviderFactory
|
||||||
certProviderClientSslContextProviderFactory;
|
certProviderClientSslContextProviderFactory;
|
||||||
|
|
||||||
ClientSslContextProviderFactory(BootstrapInfo bootstrapInfo) {
|
ClientSslContextProviderFactory(BootstrapInfo bootstrapInfo) {
|
||||||
this(bootstrapInfo, CertProviderClientSslContextProvider.Factory.getInstance());
|
this(bootstrapInfo, CertProviderClientSslContextProviderFactory.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientSslContextProviderFactory(
|
ClientSslContextProviderFactory(
|
||||||
BootstrapInfo bootstrapInfo, CertProviderClientSslContextProvider.Factory factory) {
|
BootstrapInfo bootstrapInfo, CertProviderClientSslContextProviderFactory factory) {
|
||||||
this.bootstrapInfo = bootstrapInfo;
|
this.bootstrapInfo = bootstrapInfo;
|
||||||
this.certProviderClientSslContextProviderFactory = factory;
|
this.certProviderClientSslContextProviderFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
|
import io.grpc.Internal;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
||||||
import io.netty.handler.ssl.ApplicationProtocolConfig;
|
import io.netty.handler.ssl.ApplicationProtocolConfig;
|
||||||
|
@ -34,6 +35,7 @@ import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** Base class for dynamic {@link SslContextProvider}s. */
|
/** Base class for dynamic {@link SslContextProvider}s. */
|
||||||
|
@Internal
|
||||||
public abstract class DynamicSslContextProvider extends SslContextProvider {
|
public abstract class DynamicSslContextProvider extends SslContextProvider {
|
||||||
|
|
||||||
protected final List<Callback> pendingCallbacks = new ArrayList<>();
|
protected final List<Callback> pendingCallbacks = new ArrayList<>();
|
||||||
|
|
|
@ -20,23 +20,23 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import io.grpc.xds.Bootstrapper.BootstrapInfo;
|
import io.grpc.xds.Bootstrapper.BootstrapInfo;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
import io.grpc.xds.internal.certprovider.CertProviderServerSslContextProvider;
|
|
||||||
import io.grpc.xds.internal.security.ReferenceCountingMap.ValueFactory;
|
import io.grpc.xds.internal.security.ReferenceCountingMap.ValueFactory;
|
||||||
|
import io.grpc.xds.internal.security.certprovider.CertProviderServerSslContextProviderFactory;
|
||||||
|
|
||||||
/** Factory to create server-side SslContextProvider from DownstreamTlsContext. */
|
/** Factory to create server-side SslContextProvider from DownstreamTlsContext. */
|
||||||
final class ServerSslContextProviderFactory
|
final class ServerSslContextProviderFactory
|
||||||
implements ValueFactory<DownstreamTlsContext, SslContextProvider> {
|
implements ValueFactory<DownstreamTlsContext, SslContextProvider> {
|
||||||
|
|
||||||
private BootstrapInfo bootstrapInfo;
|
private BootstrapInfo bootstrapInfo;
|
||||||
private final CertProviderServerSslContextProvider.Factory
|
private final CertProviderServerSslContextProviderFactory
|
||||||
certProviderServerSslContextProviderFactory;
|
certProviderServerSslContextProviderFactory;
|
||||||
|
|
||||||
ServerSslContextProviderFactory(BootstrapInfo bootstrapInfo) {
|
ServerSslContextProviderFactory(BootstrapInfo bootstrapInfo) {
|
||||||
this(bootstrapInfo, CertProviderServerSslContextProvider.Factory.getInstance());
|
this(bootstrapInfo, CertProviderServerSslContextProviderFactory.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerSslContextProviderFactory(
|
ServerSslContextProviderFactory(
|
||||||
BootstrapInfo bootstrapInfo, CertProviderServerSslContextProvider.Factory factory) {
|
BootstrapInfo bootstrapInfo, CertProviderServerSslContextProviderFactory factory) {
|
||||||
this.bootstrapInfo = bootstrapInfo;
|
this.bootstrapInfo = bootstrapInfo;
|
||||||
this.certProviderServerSslContextProviderFactory = factory;
|
this.certProviderServerSslContextProviderFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
|
import io.grpc.Internal;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
|
@ -39,6 +40,7 @@ import java.util.concurrent.Executor;
|
||||||
* stream that is receiving the requested secret(s) or it could represent file-system based
|
* stream that is receiving the requested secret(s) or it could represent file-system based
|
||||||
* secret(s) that are dynamic.
|
* secret(s) that are dynamic.
|
||||||
*/
|
*/
|
||||||
|
@Internal
|
||||||
public abstract class SslContextProvider implements Closeable {
|
public abstract class SslContextProvider implements Closeable {
|
||||||
|
|
||||||
protected final BaseTlsContext tlsContext;
|
protected final BaseTlsContext tlsContext;
|
||||||
|
|
|
@ -14,15 +14,13 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import io.envoyproxy.envoy.config.core.v3.Node;
|
import io.envoyproxy.envoy.config.core.v3.Node;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
import io.grpc.Internal;
|
|
||||||
import io.grpc.netty.GrpcSslContexts;
|
import io.grpc.netty.GrpcSslContexts;
|
||||||
import io.grpc.xds.Bootstrapper.CertificateProviderInfo;
|
import io.grpc.xds.Bootstrapper.CertificateProviderInfo;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
|
@ -34,10 +32,9 @@ import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** A client SslContext provider using CertificateProviderInstance to fetch secrets. */
|
/** A client SslContext provider using CertificateProviderInstance to fetch secrets. */
|
||||||
@Internal
|
final class CertProviderClientSslContextProvider extends CertProviderSslContextProvider {
|
||||||
public final class CertProviderClientSslContextProvider extends CertProviderSslContextProvider {
|
|
||||||
|
|
||||||
private CertProviderClientSslContextProvider(
|
CertProviderClientSslContextProvider(
|
||||||
Node node,
|
Node node,
|
||||||
@Nullable Map<String, CertificateProviderInfo> certProviders,
|
@Nullable Map<String, CertificateProviderInfo> certProviders,
|
||||||
CommonTlsContext.CertificateProviderInstance certInstance,
|
CommonTlsContext.CertificateProviderInstance certInstance,
|
||||||
|
@ -71,42 +68,4 @@ public final class CertProviderClientSslContextProvider extends CertProviderSslC
|
||||||
return sslContextBuilder;
|
return sslContextBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates CertProviderClientSslContextProvider. */
|
|
||||||
@Internal
|
|
||||||
public static final class Factory {
|
|
||||||
private static final Factory DEFAULT_INSTANCE =
|
|
||||||
new Factory(CertificateProviderStore.getInstance());
|
|
||||||
private final CertificateProviderStore certificateProviderStore;
|
|
||||||
|
|
||||||
@VisibleForTesting public Factory(CertificateProviderStore certificateProviderStore) {
|
|
||||||
this.certificateProviderStore = certificateProviderStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Factory getInstance() {
|
|
||||||
return DEFAULT_INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a {@link CertProviderClientSslContextProvider}. */
|
|
||||||
public CertProviderClientSslContextProvider getProvider(
|
|
||||||
UpstreamTlsContext upstreamTlsContext,
|
|
||||||
Node node,
|
|
||||||
@Nullable Map<String, CertificateProviderInfo> certProviders) {
|
|
||||||
checkNotNull(upstreamTlsContext, "upstreamTlsContext");
|
|
||||||
CommonTlsContext commonTlsContext = upstreamTlsContext.getCommonTlsContext();
|
|
||||||
CertificateValidationContext staticCertValidationContext = getStaticValidationContext(
|
|
||||||
commonTlsContext);
|
|
||||||
CommonTlsContext.CertificateProviderInstance rootCertInstance = getRootCertProviderInstance(
|
|
||||||
commonTlsContext);
|
|
||||||
CommonTlsContext.CertificateProviderInstance certInstance = getCertProviderInstance(
|
|
||||||
commonTlsContext);
|
|
||||||
return new CertProviderClientSslContextProvider(
|
|
||||||
node,
|
|
||||||
certProviders,
|
|
||||||
certInstance,
|
|
||||||
rootCertInstance,
|
|
||||||
staticCertValidationContext,
|
|
||||||
upstreamTlsContext,
|
|
||||||
certificateProviderStore);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2022 The gRPC Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import io.envoyproxy.envoy.config.core.v3.Node;
|
||||||
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
||||||
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
|
import io.grpc.Internal;
|
||||||
|
import io.grpc.xds.Bootstrapper.CertificateProviderInfo;
|
||||||
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
|
import io.grpc.xds.internal.security.SslContextProvider;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates CertProviderClientSslContextProvider.
|
||||||
|
*/
|
||||||
|
@Internal
|
||||||
|
public final class CertProviderClientSslContextProviderFactory {
|
||||||
|
|
||||||
|
private static final CertProviderClientSslContextProviderFactory DEFAULT_INSTANCE =
|
||||||
|
new CertProviderClientSslContextProviderFactory(CertificateProviderStore.getInstance());
|
||||||
|
private final CertificateProviderStore certificateProviderStore;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public CertProviderClientSslContextProviderFactory(
|
||||||
|
CertificateProviderStore certificateProviderStore) {
|
||||||
|
this.certificateProviderStore = certificateProviderStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CertProviderClientSslContextProviderFactory getInstance() {
|
||||||
|
return DEFAULT_INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link CertProviderClientSslContextProvider}.
|
||||||
|
*/
|
||||||
|
public SslContextProvider getProvider(
|
||||||
|
UpstreamTlsContext upstreamTlsContext,
|
||||||
|
Node node,
|
||||||
|
@Nullable Map<String, CertificateProviderInfo> certProviders) {
|
||||||
|
checkNotNull(upstreamTlsContext, "upstreamTlsContext");
|
||||||
|
CommonTlsContext commonTlsContext = upstreamTlsContext.getCommonTlsContext();
|
||||||
|
CertificateValidationContext staticCertValidationContext
|
||||||
|
= CertProviderSslContextProvider.getStaticValidationContext(commonTlsContext);
|
||||||
|
CommonTlsContext.CertificateProviderInstance rootCertInstance
|
||||||
|
= CertProviderSslContextProvider.getRootCertProviderInstance(commonTlsContext);
|
||||||
|
CommonTlsContext.CertificateProviderInstance certInstance
|
||||||
|
= CertProviderSslContextProvider.getCertProviderInstance(commonTlsContext);
|
||||||
|
return new CertProviderClientSslContextProvider(
|
||||||
|
node,
|
||||||
|
certProviders,
|
||||||
|
certInstance,
|
||||||
|
rootCertInstance,
|
||||||
|
staticCertValidationContext,
|
||||||
|
upstreamTlsContext,
|
||||||
|
certificateProviderStore);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,21 +14,18 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import io.envoyproxy.envoy.config.core.v3.Node;
|
import io.envoyproxy.envoy.config.core.v3.Node;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
import io.grpc.Internal;
|
|
||||||
import io.grpc.netty.GrpcSslContexts;
|
import io.grpc.netty.GrpcSslContexts;
|
||||||
import io.grpc.xds.Bootstrapper.CertificateProviderInfo;
|
import io.grpc.xds.Bootstrapper.CertificateProviderInfo;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
import io.grpc.xds.internal.security.trust.XdsTrustManagerFactory;
|
import io.grpc.xds.internal.security.trust.XdsTrustManagerFactory;
|
||||||
import io.netty.handler.ssl.SslContextBuilder;
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.cert.CertStoreException;
|
import java.security.cert.CertStoreException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
|
@ -37,17 +34,16 @@ import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/** A server SslContext provider using CertificateProviderInstance to fetch secrets. */
|
/** A server SslContext provider using CertificateProviderInstance to fetch secrets. */
|
||||||
@Internal
|
final class CertProviderServerSslContextProvider extends CertProviderSslContextProvider {
|
||||||
public final class CertProviderServerSslContextProvider extends CertProviderSslContextProvider {
|
|
||||||
|
|
||||||
private CertProviderServerSslContextProvider(
|
CertProviderServerSslContextProvider(
|
||||||
Node node,
|
Node node,
|
||||||
@Nullable Map<String, CertificateProviderInfo> certProviders,
|
@Nullable Map<String, CertificateProviderInfo> certProviders,
|
||||||
CommonTlsContext.CertificateProviderInstance certInstance,
|
CommonTlsContext.CertificateProviderInstance certInstance,
|
||||||
CommonTlsContext.CertificateProviderInstance rootCertInstance,
|
CommonTlsContext.CertificateProviderInstance rootCertInstance,
|
||||||
CertificateValidationContext staticCertValidationContext,
|
CertificateValidationContext staticCertValidationContext,
|
||||||
DownstreamTlsContext downstreamTlsContext,
|
DownstreamTlsContext downstreamTlsContext,
|
||||||
CertificateProviderStore certificateProviderStore) {
|
CertificateProviderStore certificateProviderStore) {
|
||||||
super(
|
super(
|
||||||
node,
|
node,
|
||||||
certProviders,
|
certProviders,
|
||||||
|
@ -74,42 +70,4 @@ public final class CertProviderServerSslContextProvider extends CertProviderSslC
|
||||||
return sslContextBuilder;
|
return sslContextBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates CertProviderServerSslContextProvider. */
|
|
||||||
@Internal
|
|
||||||
public static final class Factory {
|
|
||||||
private static final Factory DEFAULT_INSTANCE =
|
|
||||||
new Factory(CertificateProviderStore.getInstance());
|
|
||||||
private final CertificateProviderStore certificateProviderStore;
|
|
||||||
|
|
||||||
@VisibleForTesting public Factory(CertificateProviderStore certificateProviderStore) {
|
|
||||||
this.certificateProviderStore = certificateProviderStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Factory getInstance() {
|
|
||||||
return DEFAULT_INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a {@link CertProviderServerSslContextProvider}. */
|
|
||||||
public CertProviderServerSslContextProvider getProvider(
|
|
||||||
DownstreamTlsContext downstreamTlsContext,
|
|
||||||
Node node,
|
|
||||||
@Nullable Map<String, CertificateProviderInfo> certProviders) {
|
|
||||||
checkNotNull(downstreamTlsContext, "downstreamTlsContext");
|
|
||||||
CommonTlsContext commonTlsContext = downstreamTlsContext.getCommonTlsContext();
|
|
||||||
CertificateValidationContext staticCertValidationContext = getStaticValidationContext(
|
|
||||||
commonTlsContext);
|
|
||||||
CommonTlsContext.CertificateProviderInstance rootCertInstance = getRootCertProviderInstance(
|
|
||||||
commonTlsContext);
|
|
||||||
CommonTlsContext.CertificateProviderInstance certInstance = getCertProviderInstance(
|
|
||||||
commonTlsContext);
|
|
||||||
return new CertProviderServerSslContextProvider(
|
|
||||||
node,
|
|
||||||
certProviders,
|
|
||||||
certInstance,
|
|
||||||
rootCertInstance,
|
|
||||||
staticCertValidationContext,
|
|
||||||
downstreamTlsContext,
|
|
||||||
certificateProviderStore);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2022 The gRPC Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import io.envoyproxy.envoy.config.core.v3.Node;
|
||||||
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
||||||
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext;
|
||||||
|
import io.grpc.Internal;
|
||||||
|
import io.grpc.xds.Bootstrapper.CertificateProviderInfo;
|
||||||
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
|
import io.grpc.xds.internal.security.SslContextProvider;
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates CertProviderServerSslContextProvider.
|
||||||
|
*/
|
||||||
|
@Internal
|
||||||
|
public final class CertProviderServerSslContextProviderFactory {
|
||||||
|
|
||||||
|
private static final CertProviderServerSslContextProviderFactory DEFAULT_INSTANCE =
|
||||||
|
new CertProviderServerSslContextProviderFactory(CertificateProviderStore.getInstance());
|
||||||
|
private final CertificateProviderStore certificateProviderStore;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public CertProviderServerSslContextProviderFactory(
|
||||||
|
CertificateProviderStore certificateProviderStore) {
|
||||||
|
this.certificateProviderStore = certificateProviderStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CertProviderServerSslContextProviderFactory getInstance() {
|
||||||
|
return DEFAULT_INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link CertProviderServerSslContextProvider}.
|
||||||
|
*/
|
||||||
|
public SslContextProvider getProvider(
|
||||||
|
DownstreamTlsContext downstreamTlsContext,
|
||||||
|
Node node,
|
||||||
|
@Nullable Map<String, CertificateProviderInfo> certProviders) {
|
||||||
|
checkNotNull(downstreamTlsContext, "downstreamTlsContext");
|
||||||
|
CommonTlsContext commonTlsContext = downstreamTlsContext.getCommonTlsContext();
|
||||||
|
CertificateValidationContext staticCertValidationContext
|
||||||
|
= CertProviderSslContextProvider.getStaticValidationContext(commonTlsContext);
|
||||||
|
CommonTlsContext.CertificateProviderInstance rootCertInstance
|
||||||
|
= CertProviderSslContextProvider.getRootCertProviderInstance(commonTlsContext);
|
||||||
|
CommonTlsContext.CertificateProviderInstance certInstance
|
||||||
|
= CertProviderSslContextProvider.getCertProviderInstance(commonTlsContext);
|
||||||
|
return new CertProviderServerSslContextProvider(
|
||||||
|
node,
|
||||||
|
certProviders,
|
||||||
|
certInstance,
|
||||||
|
rootCertInstance,
|
||||||
|
staticCertValidationContext,
|
||||||
|
downstreamTlsContext,
|
||||||
|
certificateProviderStore);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import io.envoyproxy.envoy.config.core.v3.Node;
|
import io.envoyproxy.envoy.config.core.v3.Node;
|
||||||
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import io.grpc.Internal;
|
import io.grpc.Internal;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProvider.Watcher;
|
import io.grpc.xds.internal.security.certprovider.CertificateProvider.Watcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider of {@link CertificateProvider}s. Implemented by the implementer of the plugin. We may
|
* Provider of {@link CertificateProvider}s. Implemented by the implementer of the plugin. We may
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
|
@ -14,12 +14,11 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProvider.Watcher;
|
|
||||||
import io.grpc.xds.internal.security.ReferenceCountingMap;
|
import io.grpc.xds.internal.security.ReferenceCountingMap;
|
||||||
|
import io.grpc.xds.internal.security.certprovider.CertificateProvider.Watcher;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
@ -32,12 +32,12 @@ import io.grpc.xds.Bootstrapper;
|
||||||
import io.grpc.xds.CommonBootstrapperTestUtils;
|
import io.grpc.xds.CommonBootstrapperTestUtils;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
import io.grpc.xds.XdsInitializationException;
|
import io.grpc.xds.XdsInitializationException;
|
||||||
import io.grpc.xds.internal.certprovider.CertProviderClientSslContextProvider;
|
import io.grpc.xds.internal.security.certprovider.CertProviderClientSslContextProviderFactory;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProvider;
|
import io.grpc.xds.internal.security.certprovider.CertificateProvider;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProviderProvider;
|
import io.grpc.xds.internal.security.certprovider.CertificateProviderProvider;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProviderRegistry;
|
import io.grpc.xds.internal.security.certprovider.CertificateProviderRegistry;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProviderStore;
|
import io.grpc.xds.internal.security.certprovider.CertificateProviderStore;
|
||||||
import io.grpc.xds.internal.certprovider.TestCertificateProvider;
|
import io.grpc.xds.internal.security.certprovider.TestCertificateProvider;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -53,7 +53,7 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
|
|
||||||
CertificateProviderRegistry certificateProviderRegistry;
|
CertificateProviderRegistry certificateProviderRegistry;
|
||||||
CertificateProviderStore certificateProviderStore;
|
CertificateProviderStore certificateProviderStore;
|
||||||
CertProviderClientSslContextProvider.Factory certProviderClientSslContextProviderFactory;
|
CertProviderClientSslContextProviderFactory certProviderClientSslContextProviderFactory;
|
||||||
ClientSslContextProviderFactory clientSslContextProviderFactory;
|
ClientSslContextProviderFactory clientSslContextProviderFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -61,7 +61,7 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
certificateProviderRegistry = new CertificateProviderRegistry();
|
certificateProviderRegistry = new CertificateProviderRegistry();
|
||||||
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
||||||
certProviderClientSslContextProviderFactory =
|
certProviderClientSslContextProviderFactory =
|
||||||
new CertProviderClientSslContextProvider.Factory(certificateProviderStore);
|
new CertProviderClientSslContextProviderFactory(certificateProviderStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -84,12 +84,14 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
// verify that bootstrapInfo is cached...
|
// verify that bootstrapInfo is cached...
|
||||||
sslContextProvider =
|
sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -117,7 +119,8 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +145,8 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +179,8 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
certProviderClientSslContextProviderFactory);
|
certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +209,8 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
||||||
}
|
}
|
||||||
|
@ -240,7 +246,8 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
||||||
}
|
}
|
||||||
|
@ -273,7 +280,8 @@ public class ClientSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
bootstrapInfo, certProviderClientSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
clientSslContextProviderFactory.create(upstreamTlsContext);
|
clientSslContextProviderFactory.create(upstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderClientSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderClientSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,9 @@ import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
|
||||||
import io.grpc.xds.InternalXdsAttributes;
|
import io.grpc.xds.InternalXdsAttributes;
|
||||||
import io.grpc.xds.TlsContextManager;
|
import io.grpc.xds.TlsContextManager;
|
||||||
import io.grpc.xds.internal.certprovider.CommonCertProviderTestUtils;
|
|
||||||
import io.grpc.xds.internal.security.SecurityProtocolNegotiators.ClientSdsHandler;
|
import io.grpc.xds.internal.security.SecurityProtocolNegotiators.ClientSdsHandler;
|
||||||
import io.grpc.xds.internal.security.SecurityProtocolNegotiators.ClientSdsProtocolNegotiator;
|
import io.grpc.xds.internal.security.SecurityProtocolNegotiators.ClientSdsProtocolNegotiator;
|
||||||
|
import io.grpc.xds.internal.security.certprovider.CommonCertProviderTestUtils;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
|
|
@ -29,10 +29,10 @@ import io.grpc.xds.CommonBootstrapperTestUtils;
|
||||||
import io.grpc.xds.EnvoyServerProtoData;
|
import io.grpc.xds.EnvoyServerProtoData;
|
||||||
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
|
||||||
import io.grpc.xds.XdsInitializationException;
|
import io.grpc.xds.XdsInitializationException;
|
||||||
import io.grpc.xds.internal.certprovider.CertProviderServerSslContextProvider;
|
import io.grpc.xds.internal.security.certprovider.CertProviderServerSslContextProviderFactory;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProvider;
|
import io.grpc.xds.internal.security.certprovider.CertificateProvider;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProviderRegistry;
|
import io.grpc.xds.internal.security.certprovider.CertificateProviderRegistry;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProviderStore;
|
import io.grpc.xds.internal.security.certprovider.CertificateProviderStore;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -44,7 +44,7 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
|
|
||||||
CertificateProviderRegistry certificateProviderRegistry;
|
CertificateProviderRegistry certificateProviderRegistry;
|
||||||
CertificateProviderStore certificateProviderStore;
|
CertificateProviderStore certificateProviderStore;
|
||||||
CertProviderServerSslContextProvider.Factory certProviderServerSslContextProviderFactory;
|
CertProviderServerSslContextProviderFactory certProviderServerSslContextProviderFactory;
|
||||||
ServerSslContextProviderFactory serverSslContextProviderFactory;
|
ServerSslContextProviderFactory serverSslContextProviderFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -52,7 +52,7 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
certificateProviderRegistry = new CertificateProviderRegistry();
|
certificateProviderRegistry = new CertificateProviderRegistry();
|
||||||
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
||||||
certProviderServerSslContextProviderFactory =
|
certProviderServerSslContextProviderFactory =
|
||||||
new CertProviderServerSslContextProvider.Factory(certificateProviderStore);
|
new CertProviderServerSslContextProviderFactory(certificateProviderStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -76,12 +76,14 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
// verify that bootstrapInfo is cached...
|
// verify that bootstrapInfo is cached...
|
||||||
sslContextProvider =
|
sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -113,7 +115,8 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +142,8 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +177,8 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +208,8 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
||||||
}
|
}
|
||||||
|
@ -241,7 +247,8 @@ public class ServerSslContextProviderFactoryTest {
|
||||||
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
bootstrapInfo, certProviderServerSslContextProviderFactory);
|
||||||
SslContextProvider sslContextProvider =
|
SslContextProvider sslContextProvider =
|
||||||
serverSslContextProviderFactory.create(downstreamTlsContext);
|
serverSslContextProviderFactory.create(downstreamTlsContext);
|
||||||
assertThat(sslContextProvider).isInstanceOf(CertProviderServerSslContextProvider.class);
|
assertThat(sslContextProvider.getClass().getSimpleName()).isEqualTo(
|
||||||
|
"CertProviderServerSslContextProvider");
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
verifyWatcher(sslContextProvider, watcherCaptor[0]);
|
||||||
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
verifyWatcher(sslContextProvider, watcherCaptor[1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static io.grpc.xds.internal.certprovider.CommonCertProviderTestUtils.getCertFromResourceName;
|
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CA_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CA_PEM_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CLIENT_KEY_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CLIENT_KEY_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CLIENT_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CLIENT_PEM_FILE;
|
||||||
|
@ -26,6 +25,7 @@ import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_0_P
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_KEY_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_KEY_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_PEM_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.doChecksOnSslContext;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.doChecksOnSslContext;
|
||||||
|
import static io.grpc.xds.internal.security.certprovider.CommonCertProviderTestUtils.getCertFromResourceName;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -56,14 +56,14 @@ public class CertProviderClientSslContextProviderTest {
|
||||||
|
|
||||||
CertificateProviderRegistry certificateProviderRegistry;
|
CertificateProviderRegistry certificateProviderRegistry;
|
||||||
CertificateProviderStore certificateProviderStore;
|
CertificateProviderStore certificateProviderStore;
|
||||||
private CertProviderClientSslContextProvider.Factory certProviderClientSslContextProviderFactory;
|
private CertProviderClientSslContextProviderFactory certProviderClientSslContextProviderFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
certificateProviderRegistry = new CertificateProviderRegistry();
|
certificateProviderRegistry = new CertificateProviderRegistry();
|
||||||
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
||||||
certProviderClientSslContextProviderFactory =
|
certProviderClientSslContextProviderFactory =
|
||||||
new CertProviderClientSslContextProvider.Factory(certificateProviderStore);
|
new CertProviderClientSslContextProviderFactory(certificateProviderStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper method to build CertProviderClientSslContextProvider. */
|
/** Helper method to build CertProviderClientSslContextProvider. */
|
||||||
|
@ -81,10 +81,11 @@ public class CertProviderClientSslContextProviderTest {
|
||||||
"root-default",
|
"root-default",
|
||||||
alpnProtocols,
|
alpnProtocols,
|
||||||
staticCertValidationContext);
|
staticCertValidationContext);
|
||||||
return certProviderClientSslContextProviderFactory.getProvider(
|
return (CertProviderClientSslContextProvider)
|
||||||
upstreamTlsContext,
|
certProviderClientSslContextProviderFactory.getProvider(
|
||||||
bootstrapInfo.node().toEnvoyProtoNode(),
|
upstreamTlsContext,
|
||||||
bootstrapInfo.certProviders());
|
bootstrapInfo.node().toEnvoyProtoNode(),
|
||||||
|
bootstrapInfo.certProviders());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper method to build CertProviderClientSslContextProvider. */
|
/** Helper method to build CertProviderClientSslContextProvider. */
|
||||||
|
@ -102,7 +103,8 @@ public class CertProviderClientSslContextProviderTest {
|
||||||
"root-default",
|
"root-default",
|
||||||
alpnProtocols,
|
alpnProtocols,
|
||||||
staticCertValidationContext);
|
staticCertValidationContext);
|
||||||
return certProviderClientSslContextProviderFactory.getProvider(
|
return (CertProviderClientSslContextProvider)
|
||||||
|
certProviderClientSslContextProviderFactory.getProvider(
|
||||||
upstreamTlsContext,
|
upstreamTlsContext,
|
||||||
bootstrapInfo.node().toEnvoyProtoNode(),
|
bootstrapInfo.node().toEnvoyProtoNode(),
|
||||||
bootstrapInfo.certProviders());
|
bootstrapInfo.certProviders());
|
|
@ -14,10 +14,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static io.grpc.xds.internal.certprovider.CommonCertProviderTestUtils.getCertFromResourceName;
|
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CA_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CA_PEM_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CLIENT_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CLIENT_PEM_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_0_KEY_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_0_KEY_FILE;
|
||||||
|
@ -25,6 +24,7 @@ import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_0_P
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_KEY_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_KEY_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.SERVER_1_PEM_FILE;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.doChecksOnSslContext;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.doChecksOnSslContext;
|
||||||
|
import static io.grpc.xds.internal.security.certprovider.CommonCertProviderTestUtils.getCertFromResourceName;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -35,9 +35,9 @@ import io.envoyproxy.envoy.type.matcher.v3.StringMatcher;
|
||||||
import io.grpc.xds.Bootstrapper;
|
import io.grpc.xds.Bootstrapper;
|
||||||
import io.grpc.xds.CommonBootstrapperTestUtils;
|
import io.grpc.xds.CommonBootstrapperTestUtils;
|
||||||
import io.grpc.xds.EnvoyServerProtoData;
|
import io.grpc.xds.EnvoyServerProtoData;
|
||||||
import io.grpc.xds.internal.certprovider.CertProviderClientSslContextProviderTest.QueuedExecutor;
|
|
||||||
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
||||||
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil.TestCallback;
|
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil.TestCallback;
|
||||||
|
import io.grpc.xds.internal.security.certprovider.CertProviderClientSslContextProviderTest.QueuedExecutor;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -50,14 +50,14 @@ public class CertProviderServerSslContextProviderTest {
|
||||||
|
|
||||||
CertificateProviderRegistry certificateProviderRegistry;
|
CertificateProviderRegistry certificateProviderRegistry;
|
||||||
CertificateProviderStore certificateProviderStore;
|
CertificateProviderStore certificateProviderStore;
|
||||||
private CertProviderServerSslContextProvider.Factory certProviderServerSslContextProviderFactory;
|
private CertProviderServerSslContextProviderFactory certProviderServerSslContextProviderFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
certificateProviderRegistry = new CertificateProviderRegistry();
|
certificateProviderRegistry = new CertificateProviderRegistry();
|
||||||
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
certificateProviderStore = new CertificateProviderStore(certificateProviderRegistry);
|
||||||
certProviderServerSslContextProviderFactory =
|
certProviderServerSslContextProviderFactory =
|
||||||
new CertProviderServerSslContextProvider.Factory(certificateProviderStore);
|
new CertProviderServerSslContextProviderFactory(certificateProviderStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper method to build CertProviderServerSslContextProvider. */
|
/** Helper method to build CertProviderServerSslContextProvider. */
|
||||||
|
@ -77,10 +77,11 @@ public class CertProviderServerSslContextProviderTest {
|
||||||
alpnProtocols,
|
alpnProtocols,
|
||||||
staticCertValidationContext,
|
staticCertValidationContext,
|
||||||
requireClientCert);
|
requireClientCert);
|
||||||
return certProviderServerSslContextProviderFactory.getProvider(
|
return (CertProviderServerSslContextProvider)
|
||||||
downstreamTlsContext,
|
certProviderServerSslContextProviderFactory.getProvider(
|
||||||
bootstrapInfo.node().toEnvoyProtoNode(),
|
downstreamTlsContext,
|
||||||
bootstrapInfo.certProviders());
|
bootstrapInfo.node().toEnvoyProtoNode(),
|
||||||
|
bootstrapInfo.certProviders());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper method to build CertProviderServerSslContextProvider. */
|
/** Helper method to build CertProviderServerSslContextProvider. */
|
||||||
|
@ -100,7 +101,8 @@ public class CertProviderServerSslContextProviderTest {
|
||||||
alpnProtocols,
|
alpnProtocols,
|
||||||
staticCertValidationContext,
|
staticCertValidationContext,
|
||||||
requireClientCert);
|
requireClientCert);
|
||||||
return certProviderServerSslContextProviderFactory.getProvider(
|
return (CertProviderServerSslContextProvider)
|
||||||
|
certProviderServerSslContextProviderFactory.getProvider(
|
||||||
downstreamTlsContext,
|
downstreamTlsContext,
|
||||||
bootstrapInfo.node().toEnvoyProtoNode(),
|
bootstrapInfo.node().toEnvoyProtoNode(),
|
||||||
bootstrapInfo.certProviders());
|
bootstrapInfo.certProviders());
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import com.google.common.io.CharStreams;
|
||||||
import io.grpc.internal.FakeClock;
|
import io.grpc.internal.FakeClock;
|
||||||
import io.grpc.internal.TimeProvider;
|
import io.grpc.internal.TimeProvider;
|
||||||
import io.grpc.internal.testing.TestUtils;
|
import io.grpc.internal.testing.TestUtils;
|
||||||
import io.grpc.xds.internal.certprovider.FileWatcherCertificateProviderProvider.ScheduledExecutorServiceFactory;
|
import io.grpc.xds.internal.security.certprovider.FileWatcherCertificateProviderProvider.ScheduledExecutorServiceFactory;
|
||||||
import io.grpc.xds.internal.security.trust.CertificateUtils;
|
import io.grpc.xds.internal.security.trust.CertificateUtils;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CA_PEM_FILE;
|
import static io.grpc.xds.internal.security.CommonTlsContextTestsUtil.CA_PEM_FILE;
|
||||||
|
@ -34,8 +34,8 @@ import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.internal.TimeProvider;
|
import io.grpc.internal.TimeProvider;
|
||||||
import io.grpc.xds.internal.certprovider.CertificateProvider.DistributorWatcher;
|
|
||||||
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
|
||||||
|
import io.grpc.xds.internal.security.certprovider.CertificateProvider.DistributorWatcher;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.grpc.xds.internal.certprovider;
|
package io.grpc.xds.internal.security.certprovider;
|
||||||
|
|
||||||
public class TestCertificateProvider extends CertificateProvider {
|
public class TestCertificateProvider extends CertificateProvider {
|
||||||
Object config;
|
Object config;
|
Loading…
Reference in New Issue