You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "strawberry-crisis (via GitHub)" <gi...@apache.org> on 2023/04/04 12:45:22 UTC

[GitHub] [shardingsphere] strawberry-crisis opened a new pull request, #25009: Improve properties verification of EncryptAlgorithm

strawberry-crisis opened a new pull request, #25009:
URL: https://github.com/apache/shardingsphere/pull/25009

   Fixes #24747.
   
   Changes proposed in this pull request:
     - Improve properties verification of EncryptAlgorithm
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] strawberry-crisis commented on a diff in pull request #25009: Improve properties verification of EncryptAlgorithm

Posted by "strawberry-crisis (via GitHub)" <gi...@apache.org>.
strawberry-crisis commented on code in PR #25009:
URL: https://github.com/apache/shardingsphere/pull/25009#discussion_r1168117866


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithm.java:
##########
@@ -30,27 +31,26 @@
  * RC4 encrypt algorithm.
  */
 public final class RC4EncryptAlgorithm implements StandardEncryptAlgorithm<Object, String> {
-    
+
     private static final String RC4_KEY = "rc4-key-value";
-    
+
     private static final int SBOX_LENGTH = 256;
-    
+
     private static final int KEY_MIN_LENGTH = 5;
-    
+
     private volatile byte[] key = new byte[SBOX_LENGTH - 1];
-    
+
     private volatile int[] sBox = new int[SBOX_LENGTH];
-    
+
     @Override
     public void init(final Properties props) {
         reset();
         setKey(props.getProperty(RC4_KEY, "").getBytes(StandardCharsets.UTF_8));
     }
-    
+

Review Comment:
   OK, I'll fix it



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] Pace2Car commented on a diff in pull request #25009: Improve properties verification of EncryptAlgorithm

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #25009:
URL: https://github.com/apache/shardingsphere/pull/25009#discussion_r1168121292


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithm.java:
##########
@@ -30,27 +31,26 @@
  * RC4 encrypt algorithm.
  */
 public final class RC4EncryptAlgorithm implements StandardEncryptAlgorithm<Object, String> {
-    
+
     private static final String RC4_KEY = "rc4-key-value";
-    
+
     private static final int SBOX_LENGTH = 256;
-    
+
     private static final int KEY_MIN_LENGTH = 5;
-    
+
     private volatile byte[] key = new byte[SBOX_LENGTH - 1];
-    
+
     private volatile int[] sBox = new int[SBOX_LENGTH];
-    
+
     @Override
     public void init(final Properties props) {
         reset();
         setKey(props.getProperty(RC4_KEY, "").getBytes(StandardCharsets.UTF_8));
     }
-    
+
     private void setKey(final byte[] key) {
-        if (!(key.length >= KEY_MIN_LENGTH && key.length < SBOX_LENGTH)) {
-            throw new EncryptAlgorithmInitializationException("RC4", "Key length has to be between " + KEY_MIN_LENGTH + " and " + (SBOX_LENGTH - 1));
-        }
+        ShardingSpherePreconditions.checkState(key.length >= KEY_MIN_LENGTH && key.length < SBOX_LENGTH,

Review Comment:
   Keep constants is in front of logical symbols



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] Pace2Car commented on a diff in pull request #25009: Improve properties verification of EncryptAlgorithm

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #25009:
URL: https://github.com/apache/shardingsphere/pull/25009#discussion_r1168123655


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithm.java:
##########
@@ -50,8 +50,10 @@ public void init(final Properties props) {
     }
     
     private byte[] createSecretKey(final Properties props) {
-        ShardingSpherePreconditions.checkState(props.containsKey(AES_KEY), () -> new EncryptAlgorithmInitializationException("AES", String.format("%s can not be null", AES_KEY)));
-        return Arrays.copyOf(DigestUtils.sha1(props.getProperty(AES_KEY)), 16);
+        String aesKey = props.getProperty(AES_KEY);
+        ShardingSpherePreconditions.checkState(null != aesKey && !aesKey.isEmpty(),
+                () -> new EncryptAlgorithmInitializationException(getType(), String.format("%s can not be null or empty", AES_KEY)));

Review Comment:
   Please add a test case where AES_KEY is empty



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] RaigorJiang merged pull request #25009: Improve properties verification of EncryptAlgorithm

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang merged PR #25009:
URL: https://github.com/apache/shardingsphere/pull/25009


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] Pace2Car commented on a diff in pull request #25009: Improve properties verification of EncryptAlgorithm

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #25009:
URL: https://github.com/apache/shardingsphere/pull/25009#discussion_r1168117137


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithm.java:
##########
@@ -30,27 +31,26 @@
  * RC4 encrypt algorithm.
  */
 public final class RC4EncryptAlgorithm implements StandardEncryptAlgorithm<Object, String> {
-    
+
     private static final String RC4_KEY = "rc4-key-value";
-    
+
     private static final int SBOX_LENGTH = 256;
-    
+
     private static final int KEY_MIN_LENGTH = 5;
-    
+
     private volatile byte[] key = new byte[SBOX_LENGTH - 1];
-    
+
     private volatile int[] sBox = new int[SBOX_LENGTH];
-    
+
     @Override
     public void init(final Properties props) {
         reset();
         setKey(props.getProperty(RC4_KEY, "").getBytes(StandardCharsets.UTF_8));
     }
-    
+

Review Comment:
   Please keep indentation consistent with the previous line, even empty lines



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] Pace2Car commented on a diff in pull request #25009: Improve properties verification of EncryptAlgorithm

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on code in PR #25009:
URL: https://github.com/apache/shardingsphere/pull/25009#discussion_r1168120611


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithm.java:
##########
@@ -50,8 +50,10 @@ public void init(final Properties props) {
     }
     
     private byte[] createSecretKey(final Properties props) {
-        ShardingSpherePreconditions.checkState(props.containsKey(AES_KEY), () -> new EncryptAlgorithmInitializationException("AES", String.format("%s can not be null", AES_KEY)));
-        return Arrays.copyOf(DigestUtils.sha1(props.getProperty(AES_KEY)), 16);
+        String aesKey = props.getProperty(AES_KEY);
+        ShardingSpherePreconditions.checkState(null != aesKey && !aesKey.isEmpty(),

Review Comment:
   Here you can use guava `!Strings.isNullOrEmpty()` instead



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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