|
16 | 16 | import io.grpc.stub.StreamObserver; |
17 | 17 | import io.grpc.stub.CallStreamObserver; |
18 | 18 | import io.grpc.StatusRuntimeException; |
| 19 | +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; |
| 20 | +import io.netty.handler.ssl.SslContext; |
19 | 21 | import com.google.protobuf.ByteString; |
20 | 22 | import com.trend.cloudone.amaas.scan.ScanGrpc; |
21 | 23 | import com.trend.cloudone.amaas.scan.ScanOuterClass; |
@@ -84,27 +86,34 @@ public AMaasClient(final String region, final String host, final String apiKey, |
84 | 86 | } |
85 | 87 | if (enabledTLS) { |
86 | 88 | log(Level.FINE, "Using prod grpc service {0}", target); |
87 | | - if (caCertPath != null && !caCertPath.isEmpty()) { |
88 | | - // Bring Your Own Certificate case |
89 | | - try { |
90 | | - File certFile = Paths.get(caCertPath).toFile(); |
91 | | - this.channel = NettyChannelBuilder.forTarget(target) |
92 | | - .sslContext(GrpcSslContexts.forClient().trustManager(certFile).build()) |
93 | | - .build(); |
94 | | - } catch (SSLException | UnsupportedOperationException e) { |
95 | | - throw new AMaasException(AMaasErrorCode.MSG_ID_ERR_LOAD_SSL_CERT); |
96 | | - } |
97 | | - } else { |
98 | | - // Default SSL credentials case |
99 | | - try { |
100 | | - log(Level.FINE, "Using prod grpc service {0}", target); |
101 | | - this.channel = NettyChannelBuilder.forTarget(target) |
102 | | - .sslContext(GrpcSslContexts.forClient().build()) |
103 | | - .build(); |
104 | | - } catch (SSLException e) { |
105 | | - throw new AMaasException(AMaasErrorCode.MSG_ID_ERR_LOAD_SSL_CERT); |
| 89 | + String verifyCertEnv = System.getenv("TM_AM_DISABLE_CERT_VERIFY"); |
| 90 | + boolean verifyCert = !("1".equals(verifyCertEnv)); |
| 91 | + SslContext context; |
| 92 | + |
| 93 | + try { |
| 94 | + if (!verifyCert) { |
| 95 | + // Bypassing certificate verification |
| 96 | + log(Level.FINE, "Bypassing certificate verification"); |
| 97 | + context = GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); |
| 98 | + } else { |
| 99 | + if (caCertPath != null && !caCertPath.isEmpty()) { |
| 100 | + // Bring Your Own Certificate case |
| 101 | + log(Level.FINE, "Using certificate {0}", caCertPath); |
| 102 | + File certFile = Paths.get(caCertPath).toFile(); |
| 103 | + context = GrpcSslContexts.forClient().trustManager(certFile).build(); |
| 104 | + } else { |
| 105 | + // Default SSL credentials case |
| 106 | + log(Level.FINE, "Using default certificate"); |
| 107 | + context = GrpcSslContexts.forClient().build(); |
| 108 | + } |
106 | 109 | } |
| 110 | + } catch (SSLException | UnsupportedOperationException e) { |
| 111 | + throw new AMaasException(AMaasErrorCode.MSG_ID_ERR_LOAD_SSL_CERT); |
107 | 112 | } |
| 113 | + |
| 114 | + this.channel = NettyChannelBuilder.forTarget(target) |
| 115 | + .sslContext(context) |
| 116 | + .build(); |
108 | 117 | } else { |
109 | 118 | log(Level.FINE, "Using grpc service with TLS disenabled {0}", target); |
110 | 119 | this.channel = NettyChannelBuilder.forTarget(target) |
|
0 commit comments