terrymanu commented on a change in pull request #11440:
URL: https://github.com/apache/shardingsphere/pull/11440#discussion_r675979737
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUser.java
##########
@@ -35,4 +36,18 @@ public ShardingSphereUser(final String username, final
String password, final St
grantee = new Grantee(username, hostname);
this.password = password;
}
+
+ /**
+ * get decrypt password.
+ * @return String the decrypt password
+ */
+ public String getPassword() {
+ try {
+ return
AlgorithmSecureFactory.getInstance().decryptFrontend(password);
+ // CHECKSTYLE:OFF
+ } catch (Exception e) {
+ //checkstyle:ON
+ return null;
Review comment:
When will the password return null?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AlgorithmSecureFactory.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * ShardingSphere algorithm secure factory.
+ */
+public final class AlgorithmSecureFactory {
+ private static AlgorithmSecureFactory instance = new
AlgorithmSecureFactory();
+
+ private Map<String, AlgorithmSecure> algorithms = new
ConcurrentHashMap<>(2);
+
+ private Map<String, String> secure2AlgType = new ConcurrentHashMap<>(2);
+
+ private boolean isInited;
Review comment:
The class is used by multiple threads, is `isInited` thread safe?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AlgorithmSecureFactory.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * ShardingSphere algorithm secure factory.
+ */
+public final class AlgorithmSecureFactory {
+ private static AlgorithmSecureFactory instance = new
AlgorithmSecureFactory();
Review comment:
Please keep empty line between class name and field declaration.
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AlgorithmSecure.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
+
+/**
+ * Typed of Secure.
Review comment:
Why the JavaDoc is different with class name?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AlgorithmSecure.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
+
+/**
+ * Typed of Secure.
+ */
+public interface AlgorithmSecure extends TypedSPI {
+
+ /**
+ * encrypt input.
+ *
+ * @param input the input password
+ * @param charsetName the password' charset
+ * @return String the encrypted password
+ * @throws Exception when encrypt failed throw this exception
+ */
+ default String encrypt(final String input, final String charsetName)
throws Exception {
+ return encrypt(input.getBytes(charsetName));
+ }
+
+ /**
+ * encrypt input.
+ *
+ * @param input the input password
+ * @return String the encrypted password
+ * @throws Exception when encrypt failed throw this exception
+ */
+ default String encrypt(final String input) throws Exception {
+ return encrypt(input, "UTF-8");
+ }
+
+ /**
+ * encrypt input.
+ *
+ * @param content the password byte array
+ * @return String the encrypted password
+ * @throws Exception when encrypt failed throw this exception
+ */
+ String encrypt(byte[] content) throws Exception;
Review comment:
Is it necessary for encrypt with byte[] in password?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AesAlgorithmSecure.java
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.List;
+
+/**
+ * this is Aes Security Utils for encrypt or decrypt password
+ * NOTICE:
+ * in encrypt, we random get iv and key in 16-bytes to encrypt password, but
in return value, we combain
+ * iv + key + encrypt(passwd) as a string, this is not SAFE!!! iv and key must
save other security file or database!
+ * if you need more security, please implements AlgorithmSecure youself.
+ * in decrypt, we first extract iv and key in 16 bytes, then use it to decrypt
password.
+ */
+public class AesAlgorithmSecure implements AlgorithmSecure {
+ // the iv and key lenght
Review comment:
Can you remove the comment?
Only JavaDoc and TODO permitted
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AlgorithmSecure.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
+
+/**
+ * Typed of Secure.
+ */
+public interface AlgorithmSecure extends TypedSPI {
Review comment:
AlgorithmSecure is not make sense, could you consider about change the
class name?
##########
File path:
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/security/AlgorithmSecure.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.shardingsphere.infra.security;
+
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
+
+/**
+ * Typed of Secure.
+ */
+public interface AlgorithmSecure extends TypedSPI {
+
+ /**
+ * encrypt input.
Review comment:
Please upper case with first letter of JavaDoc
##########
File path:
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/factory/JDBCRawBackendDataSourceFactory.java
##########
@@ -62,7 +63,17 @@ public DataSource build(final String dataSourceName, final
DataSourceParameter d
config.setDriverClassName(driverClassName);
config.setJdbcUrl(dataSourceParameter.getUrl());
config.setUsername(dataSourceParameter.getUsername());
- config.setPassword(dataSourceParameter.getPassword());
+ String decryptPasswd = null;
+ try {
+ decryptPasswd = AlgorithmSecureFactory.getInstance()
+ .decryptBackend(dataSourceParameter.getPassword());
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ log.error("password decrypt failed:", ex);
+ return null;
Review comment:
What happen if null returned?
--
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]