keith-turner commented on code in PR #2707:
URL: https://github.com/apache/accumulo/pull/2707#discussion_r873811513


##########
server/base/src/main/java/org/apache/accumulo/server/security/handler/ZKSecurityTool.java:
##########
@@ -114,16 +120,27 @@ public static byte[] createPass(byte[] password) throws 
AccumuloException {
     return cryptHash.getBytes(UTF_8);
   }
 
+  private static final Map<List<Byte>,String> CHECKED_CRYPT_PASSWORDS =

Review Comment:
   Hadoop's Text or Accumulo's ByteSequence would probably be more efficient 
for the key than List<Byte>.
   
   ```suggestion
     private static final Map<ByteSequence,String> CHECKED_CRYPT_PASSWORDS =
   ```
   
   Also thinking a guava cache w/ extremely short TTL (like 1 min) would be 
better than fixed size lrumap.  An extremely short duration should still 
amortize the cost nicely.
   



##########
server/base/src/main/java/org/apache/accumulo/server/security/handler/ZKSecurityTool.java:
##########
@@ -114,16 +120,27 @@ public static byte[] createPass(byte[] password) throws 
AccumuloException {
     return cryptHash.getBytes(UTF_8);
   }
 
+  private static final Map<List<Byte>,String> CHECKED_CRYPT_PASSWORDS =
+      Collections.synchronizedMap(new LRUMap<>(16));
+
   public static boolean checkCryptPass(byte[] password, byte[] zkData) {
+    List<Byte> key = Bytes.asList(password);
     String zkDataString = new String(zkData, UTF_8);
+    if (CHECKED_CRYPT_PASSWORDS.getOrDefault(key, "").equals(zkDataString)) {
+      return true;
+    }
     String cryptHash;
     try {
       cryptHash = Crypt.crypt(password, zkDataString);

Review Comment:
   Feels more safe to me if we explicitly cache the input and output of the 
cryptHash function. So something like the followin psuedocode (not sure of the 
best way to write it w/o looking at cache APIs)
   
   ```
      var key = password  + zkData
      cryptHash = getFromCache(key)
      if(cryptHash == null) {
          cryptHash = Crypt.crypt(password, zkDataString);
          putInCache(key, cryptHash);
      }
      
      boolean matches = MessageDigest.isEqual(zkData, 
cryptHash.getBytes(UTF_8));
   ```
   



-- 
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