github-advanced-security[bot] commented on code in PR #16944:
URL: https://github.com/apache/iotdb/pull/16944#discussion_r2641708171


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/IoTDBKeyStoreLoaderClient.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.iotdb.db.pipe.sink.protocol.opcua.client;
+
+import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+class IoTDBKeyStoreLoaderClient {
+
+  private static final Pattern IP_ADDR_PATTERN =
+      
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+  private static final String CLIENT_ALIAS = "client-ai";
+  private static final char[] PASSWORD = "root".toCharArray();
+
+  private X509Certificate[] clientCertificateChain;
+  private X509Certificate clientCertificate;
+  private KeyPair clientKeyPair;
+
+  IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
+    final KeyStore keyStore = KeyStore.getInstance("PKCS12");
+
+    final Path serverKeyStore = baseDir.resolve("example-client.pfx");
+
+    System.out.println("Loading KeyStore at " + serverKeyStore);
+
+    if (!Files.exists(serverKeyStore)) {
+      keyStore.load(null, PASSWORD);

Review Comment:
   ## Credentials should not be hard-coded
   
   <!--SONAR_ISSUE_KEY:AZtI8gYYsWnBInRPYSPo-->Revoke and change this password, 
as it is compromised. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZtI8gYYsWnBInRPYSPo&open=AZtI8gYYsWnBInRPYSPo&pullRequest=16944";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/iotdb/security/code-scanning/400)



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/IoTDBKeyStoreLoaderClient.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.iotdb.db.pipe.sink.protocol.opcua.client;
+
+import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+class IoTDBKeyStoreLoaderClient {
+
+  private static final Pattern IP_ADDR_PATTERN =
+      
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+  private static final String CLIENT_ALIAS = "client-ai";
+  private static final char[] PASSWORD = "root".toCharArray();
+
+  private X509Certificate[] clientCertificateChain;
+  private X509Certificate clientCertificate;
+  private KeyPair clientKeyPair;
+
+  IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
+    final KeyStore keyStore = KeyStore.getInstance("PKCS12");
+
+    final Path serverKeyStore = baseDir.resolve("example-client.pfx");
+
+    System.out.println("Loading KeyStore at " + serverKeyStore);
+
+    if (!Files.exists(serverKeyStore)) {
+      keyStore.load(null, PASSWORD);
+
+      final KeyPair keyPair = 
SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
+
+      final SelfSignedCertificateBuilder builder =
+          new SelfSignedCertificateBuilder(keyPair)
+              .setCommonName("Eclipse Milo Example Client")
+              .setOrganization("digitalpetri")
+              .setOrganizationalUnit("dev")
+              .setLocalityName("Folsom")
+              .setStateName("CA")
+              .setCountryCode("US")
+              .setApplicationUri("urn:eclipse:milo:examples:client")
+              .addDnsName("localhost")
+              .addIpAddress("127.0.0.1");
+
+      // Get as many hostnames and IP addresses as we can listed in the 
certificate.
+      for (String hostname : HostnameUtil.getHostnames("0.0.0.0")) {
+        if (IP_ADDR_PATTERN.matcher(hostname).matches()) {
+          builder.addIpAddress(hostname);
+        } else {
+          builder.addDnsName(hostname);
+        }
+      }
+
+      final X509Certificate certificate = builder.build();
+
+      keyStore.setKeyEntry(
+          CLIENT_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] 
{certificate});
+      try (OutputStream out = Files.newOutputStream(serverKeyStore)) {
+        keyStore.store(out, PASSWORD);

Review Comment:
   ## Credentials should not be hard-coded
   
   <!--SONAR_ISSUE_KEY:AZtI8gYYsWnBInRPYSPq-->Revoke and change this password, 
as it is compromised. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZtI8gYYsWnBInRPYSPq&open=AZtI8gYYsWnBInRPYSPq&pullRequest=16944";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/iotdb/security/code-scanning/402)



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/IoTDBKeyStoreLoaderClient.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.iotdb.db.pipe.sink.protocol.opcua.client;
+
+import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+class IoTDBKeyStoreLoaderClient {
+
+  private static final Pattern IP_ADDR_PATTERN =
+      
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+  private static final String CLIENT_ALIAS = "client-ai";
+  private static final char[] PASSWORD = "root".toCharArray();
+
+  private X509Certificate[] clientCertificateChain;
+  private X509Certificate clientCertificate;
+  private KeyPair clientKeyPair;
+
+  IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
+    final KeyStore keyStore = KeyStore.getInstance("PKCS12");
+
+    final Path serverKeyStore = baseDir.resolve("example-client.pfx");
+
+    System.out.println("Loading KeyStore at " + serverKeyStore);
+
+    if (!Files.exists(serverKeyStore)) {
+      keyStore.load(null, PASSWORD);
+
+      final KeyPair keyPair = 
SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
+
+      final SelfSignedCertificateBuilder builder =
+          new SelfSignedCertificateBuilder(keyPair)
+              .setCommonName("Eclipse Milo Example Client")
+              .setOrganization("digitalpetri")
+              .setOrganizationalUnit("dev")
+              .setLocalityName("Folsom")
+              .setStateName("CA")
+              .setCountryCode("US")
+              .setApplicationUri("urn:eclipse:milo:examples:client")
+              .addDnsName("localhost")
+              .addIpAddress("127.0.0.1");
+
+      // Get as many hostnames and IP addresses as we can listed in the 
certificate.
+      for (String hostname : HostnameUtil.getHostnames("0.0.0.0")) {
+        if (IP_ADDR_PATTERN.matcher(hostname).matches()) {
+          builder.addIpAddress(hostname);
+        } else {
+          builder.addDnsName(hostname);
+        }
+      }
+
+      final X509Certificate certificate = builder.build();
+
+      keyStore.setKeyEntry(
+          CLIENT_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] 
{certificate});
+      try (OutputStream out = Files.newOutputStream(serverKeyStore)) {
+        keyStore.store(out, PASSWORD);
+      }
+    } else {
+      try (InputStream in = Files.newInputStream(serverKeyStore)) {
+        keyStore.load(in, PASSWORD);
+      }
+    }
+
+    final Key clientPrivateKey = keyStore.getKey(CLIENT_ALIAS, PASSWORD);

Review Comment:
   ## Credentials should not be hard-coded
   
   <!--SONAR_ISSUE_KEY:AZtI8gYZsWnBInRPYSPs-->Revoke and change this password, 
as it is compromised. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZtI8gYZsWnBInRPYSPs&open=AZtI8gYZsWnBInRPYSPs&pullRequest=16944";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/iotdb/security/code-scanning/404)



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/IoTDBKeyStoreLoaderClient.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.iotdb.db.pipe.sink.protocol.opcua.client;
+
+import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+class IoTDBKeyStoreLoaderClient {
+
+  private static final Pattern IP_ADDR_PATTERN =
+      
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+  private static final String CLIENT_ALIAS = "client-ai";
+  private static final char[] PASSWORD = "root".toCharArray();
+
+  private X509Certificate[] clientCertificateChain;
+  private X509Certificate clientCertificate;
+  private KeyPair clientKeyPair;
+
+  IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
+    final KeyStore keyStore = KeyStore.getInstance("PKCS12");
+
+    final Path serverKeyStore = baseDir.resolve("example-client.pfx");
+
+    System.out.println("Loading KeyStore at " + serverKeyStore);
+
+    if (!Files.exists(serverKeyStore)) {
+      keyStore.load(null, PASSWORD);
+
+      final KeyPair keyPair = 
SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
+
+      final SelfSignedCertificateBuilder builder =
+          new SelfSignedCertificateBuilder(keyPair)
+              .setCommonName("Eclipse Milo Example Client")
+              .setOrganization("digitalpetri")
+              .setOrganizationalUnit("dev")
+              .setLocalityName("Folsom")
+              .setStateName("CA")
+              .setCountryCode("US")
+              .setApplicationUri("urn:eclipse:milo:examples:client")
+              .addDnsName("localhost")
+              .addIpAddress("127.0.0.1");
+
+      // Get as many hostnames and IP addresses as we can listed in the 
certificate.
+      for (String hostname : HostnameUtil.getHostnames("0.0.0.0")) {
+        if (IP_ADDR_PATTERN.matcher(hostname).matches()) {
+          builder.addIpAddress(hostname);
+        } else {
+          builder.addDnsName(hostname);
+        }
+      }
+
+      final X509Certificate certificate = builder.build();
+
+      keyStore.setKeyEntry(
+          CLIENT_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] 
{certificate});
+      try (OutputStream out = Files.newOutputStream(serverKeyStore)) {
+        keyStore.store(out, PASSWORD);
+      }
+    } else {
+      try (InputStream in = Files.newInputStream(serverKeyStore)) {
+        keyStore.load(in, PASSWORD);

Review Comment:
   ## Credentials should not be hard-coded
   
   <!--SONAR_ISSUE_KEY:AZtI8gYYsWnBInRPYSPr-->Revoke and change this password, 
as it is compromised. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZtI8gYYsWnBInRPYSPr&open=AZtI8gYYsWnBInRPYSPr&pullRequest=16944";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/iotdb/security/code-scanning/403)



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/client/IoTDBKeyStoreLoaderClient.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.iotdb.db.pipe.sink.protocol.opcua.client;
+
+import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
+import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+class IoTDBKeyStoreLoaderClient {
+
+  private static final Pattern IP_ADDR_PATTERN =
+      
Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+  private static final String CLIENT_ALIAS = "client-ai";
+  private static final char[] PASSWORD = "root".toCharArray();
+
+  private X509Certificate[] clientCertificateChain;
+  private X509Certificate clientCertificate;
+  private KeyPair clientKeyPair;
+
+  IoTDBKeyStoreLoaderClient load(Path baseDir) throws Exception {
+    final KeyStore keyStore = KeyStore.getInstance("PKCS12");
+
+    final Path serverKeyStore = baseDir.resolve("example-client.pfx");
+
+    System.out.println("Loading KeyStore at " + serverKeyStore);
+
+    if (!Files.exists(serverKeyStore)) {
+      keyStore.load(null, PASSWORD);
+
+      final KeyPair keyPair = 
SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
+
+      final SelfSignedCertificateBuilder builder =
+          new SelfSignedCertificateBuilder(keyPair)
+              .setCommonName("Eclipse Milo Example Client")
+              .setOrganization("digitalpetri")
+              .setOrganizationalUnit("dev")
+              .setLocalityName("Folsom")
+              .setStateName("CA")
+              .setCountryCode("US")
+              .setApplicationUri("urn:eclipse:milo:examples:client")
+              .addDnsName("localhost")
+              .addIpAddress("127.0.0.1");
+
+      // Get as many hostnames and IP addresses as we can listed in the 
certificate.
+      for (String hostname : HostnameUtil.getHostnames("0.0.0.0")) {
+        if (IP_ADDR_PATTERN.matcher(hostname).matches()) {
+          builder.addIpAddress(hostname);
+        } else {
+          builder.addDnsName(hostname);
+        }
+      }
+
+      final X509Certificate certificate = builder.build();
+
+      keyStore.setKeyEntry(
+          CLIENT_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] 
{certificate});

Review Comment:
   ## Credentials should not be hard-coded
   
   <!--SONAR_ISSUE_KEY:AZtI8gYYsWnBInRPYSPp-->Revoke and change this password, 
as it is compromised. <p>See more on <a 
href="https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZtI8gYYsWnBInRPYSPp&open=AZtI8gYYsWnBInRPYSPp&pullRequest=16944";>SonarQube
 Cloud</a></p>
   
   [Show more 
details](https://github.com/apache/iotdb/security/code-scanning/401)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to