You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org> on 2023/04/23 19:21:33 UTC

[GitHub] [calcite] github-code-scanning[bot] commented on a diff in pull request #3174: CALCITE-5671: Add Option to Disable SSL Certificate Validation to ES Adapter

github-code-scanning[bot] commented on code in PR #3174:
URL: https://github.com/apache/calcite/pull/3174#discussion_r1174630880


##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/UnsafeX509ExtendedTrustManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.adapter.elasticsearch;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.X509ExtendedTrustManager;
+import java.net.Socket;
+import java.security.cert.X509Certificate;
+
+/**
+ * This class is used to disable SSL Certificate Verification in ElasticSearch.  This trust
+ * manager will validate any SSL certificate, whether valid or not.
+ * <p>
+ * This should <b>not</b> be used in production environments.
+ * </p>
+ */
+public final class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager {
+
+  /**
+   * Return a new instance of the unsafe, all-trusting trust manager.
+   */
+  static final X509ExtendedTrustManager INSTANCE = new UnsafeX509ExtendedTrustManager();
+  private static final X509Certificate[] EMPTY_CERTIFICATES = new X509Certificate[0];
+
+  private UnsafeX509ExtendedTrustManager() {}
+
+  public static X509ExtendedTrustManager getInstance() {
+    return INSTANCE;
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, Socket socket) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, SSLEngine sslEngine) {
+    // No op
+  }
+
+  @Override
+  public void checkServerTrusted(X509Certificate[] certificates, String authType) {

Review Comment:
   ## Server certificates should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzkg2F6dJxSmTb8y-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzkg2F6dJxSmTb8y&open=AYevjzkg2F6dJxSmTb8y&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/9)



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/UnsafeX509ExtendedTrustManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.adapter.elasticsearch;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.X509ExtendedTrustManager;
+import java.net.Socket;
+import java.security.cert.X509Certificate;
+
+/**
+ * This class is used to disable SSL Certificate Verification in ElasticSearch.  This trust
+ * manager will validate any SSL certificate, whether valid or not.
+ * <p>
+ * This should <b>not</b> be used in production environments.
+ * </p>
+ */
+public final class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager {
+
+  /**
+   * Return a new instance of the unsafe, all-trusting trust manager.
+   */
+  static final X509ExtendedTrustManager INSTANCE = new UnsafeX509ExtendedTrustManager();
+  private static final X509Certificate[] EMPTY_CERTIFICATES = new X509Certificate[0];
+
+  private UnsafeX509ExtendedTrustManager() {}
+
+  public static X509ExtendedTrustManager getInstance() {
+    return INSTANCE;
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, Socket socket) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, SSLEngine sslEngine) {
+    // No op
+  }
+
+  @Override
+  public void checkServerTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkServerTrusted(X509Certificate[] certificates, String authType, Socket socket) {
+    // No op
+  }
+
+  @Override
+  public void checkServerTrusted(X509Certificate[] certificates, String authType, SSLEngine sslEngine) {

Review Comment:
   ## Server certificates should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzkg2F6dJxSmTb80-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzkg2F6dJxSmTb80&open=AYevjzkg2F6dJxSmTb80&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/6)



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/UnsafeX509ExtendedTrustManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.adapter.elasticsearch;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.X509ExtendedTrustManager;
+import java.net.Socket;
+import java.security.cert.X509Certificate;
+
+/**
+ * This class is used to disable SSL Certificate Verification in ElasticSearch.  This trust
+ * manager will validate any SSL certificate, whether valid or not.
+ * <p>
+ * This should <b>not</b> be used in production environments.
+ * </p>
+ */
+public final class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager {
+
+  /**
+   * Return a new instance of the unsafe, all-trusting trust manager.
+   */
+  static final X509ExtendedTrustManager INSTANCE = new UnsafeX509ExtendedTrustManager();
+  private static final X509Certificate[] EMPTY_CERTIFICATES = new X509Certificate[0];
+
+  private UnsafeX509ExtendedTrustManager() {}
+
+  public static X509ExtendedTrustManager getInstance() {
+    return INSTANCE;
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, Socket socket) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, SSLEngine sslEngine) {

Review Comment:
   ## Server certificates should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzkg2F6dJxSmTb8x-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzkg2F6dJxSmTb8x&open=AYevjzkg2F6dJxSmTb8x&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/8)



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/UnsafeX509ExtendedTrustManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.adapter.elasticsearch;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.X509ExtendedTrustManager;
+import java.net.Socket;
+import java.security.cert.X509Certificate;
+
+/**
+ * This class is used to disable SSL Certificate Verification in ElasticSearch.  This trust
+ * manager will validate any SSL certificate, whether valid or not.
+ * <p>
+ * This should <b>not</b> be used in production environments.
+ * </p>
+ */
+public final class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager {
+
+  /**
+   * Return a new instance of the unsafe, all-trusting trust manager.
+   */
+  static final X509ExtendedTrustManager INSTANCE = new UnsafeX509ExtendedTrustManager();
+  private static final X509Certificate[] EMPTY_CERTIFICATES = new X509Certificate[0];
+
+  private UnsafeX509ExtendedTrustManager() {}
+
+  public static X509ExtendedTrustManager getInstance() {
+    return INSTANCE;
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, Socket socket) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, SSLEngine sslEngine) {
+    // No op
+  }
+
+  @Override
+  public void checkServerTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkServerTrusted(X509Certificate[] certificates, String authType, Socket socket) {

Review Comment:
   ## Server certificates should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzkg2F6dJxSmTb8z-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzkg2F6dJxSmTb8z&open=AYevjzkg2F6dJxSmTb8z&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/10)



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java:
##########
@@ -173,6 +187,16 @@
                 httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
           }
 
+          if (disableSSLVerification) {
+            SSLContext sslContext = SSLContext.getInstance("TLS");
+            sslContext.init(null, new TrustManager[] { UnsafeX509ExtendedTrustManager.INSTANCE },
+                null);
+
+            builder.setHttpClientConfigCallback(httpClientBuilder ->
+                httpClientBuilder.setSSLContext(sslContext)
+                    .setSSLHostnameVerifier((host, session) -> true));

Review Comment:
   ## Server hostnames should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzgB2F6dJxSmTb8u-->Enable server hostname verification on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzgB2F6dJxSmTb8u&open=AYevjzgB2F6dJxSmTb8u&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/4)



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/UnsafeX509ExtendedTrustManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.adapter.elasticsearch;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.X509ExtendedTrustManager;
+import java.net.Socket;
+import java.security.cert.X509Certificate;
+
+/**
+ * This class is used to disable SSL Certificate Verification in ElasticSearch.  This trust
+ * manager will validate any SSL certificate, whether valid or not.
+ * <p>
+ * This should <b>not</b> be used in production environments.
+ * </p>
+ */
+public final class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager {
+
+  /**
+   * Return a new instance of the unsafe, all-trusting trust manager.
+   */
+  static final X509ExtendedTrustManager INSTANCE = new UnsafeX509ExtendedTrustManager();
+  private static final X509Certificate[] EMPTY_CERTIFICATES = new X509Certificate[0];
+
+  private UnsafeX509ExtendedTrustManager() {}
+
+  public static X509ExtendedTrustManager getInstance() {
+    return INSTANCE;
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType) {
+    // No op
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType, Socket socket) {

Review Comment:
   ## Server certificates should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzkg2F6dJxSmTb8w-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzkg2F6dJxSmTb8w&open=AYevjzkg2F6dJxSmTb8w&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/7)



##########
elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/UnsafeX509ExtendedTrustManager.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.adapter.elasticsearch;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.X509ExtendedTrustManager;
+import java.net.Socket;
+import java.security.cert.X509Certificate;
+
+/**
+ * This class is used to disable SSL Certificate Verification in ElasticSearch.  This trust
+ * manager will validate any SSL certificate, whether valid or not.
+ * <p>
+ * This should <b>not</b> be used in production environments.
+ * </p>
+ */
+public final class UnsafeX509ExtendedTrustManager extends X509ExtendedTrustManager {
+
+  /**
+   * Return a new instance of the unsafe, all-trusting trust manager.
+   */
+  static final X509ExtendedTrustManager INSTANCE = new UnsafeX509ExtendedTrustManager();
+  private static final X509Certificate[] EMPTY_CERTIFICATES = new X509Certificate[0];
+
+  private UnsafeX509ExtendedTrustManager() {}
+
+  public static X509ExtendedTrustManager getInstance() {
+    return INSTANCE;
+  }
+
+  @Override
+  public void checkClientTrusted(X509Certificate[] certificates, String authType) {

Review Comment:
   ## Server certificates should be verified during SSL/TLS connections
   
   <!--SONAR_ISSUE_KEY:AYevjzkf2F6dJxSmTb8v-->Enable server certificate validation on this SSL/TLS connection. <p>See more on <a href="https://sonarcloud.io/project/issues?id=apache_calcite&issues=AYevjzkf2F6dJxSmTb8v&open=AYevjzkf2F6dJxSmTb8v&pullRequest=3174">SonarCloud</a></p>
   
   [Show more details](https://github.com/apache/calcite/security/code-scanning/5)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org