You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "lasdf1234 (via GitHub)" <gi...@apache.org> on 2026/06/22 09:46:14 UTC

[PR] [#11756] fix(idp): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

lasdf1234 opened a new pull request, #11761:
URL: https://github.com/apache/gravitino/pull/11761

   ### What changes were proposed in this pull request?
   
   - Replace Argon2id + Bouncy Castle with JDK `MessageDigest` SHA3-512 password hashing for the built-in IdP
   - Add `Sha3512PasswordHasher` with PHC-style stored hashes: `$sha3-512$i=100000$<salt>$<hash>`
   - Remove `bcprov-jdk18on` from `plugins:idp-basic` dependencies and from distribution `libs/`
   - Remove Bouncy Castle entries from `LICENSE.bin`, `NOTICE.bin`, and `licenses/bouncycastle.txt`
   - Update `design-docs/gravitino-local-authentication.md`
   
   Fixes #11756
   
   ### Why are the changes needed?
   
   Gravitino 1.3 bundled Bouncy Castle for Argon2id IdP password hashing, which introduced third-party cryptographic components in the server distribution and ASF export-control overhead. This change uses the JDK built-in SHA3-512 digest API instead, removing the Bouncy Castle dependency from the distribution.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   
   1. New IdP password hashes use SHA3-512 (`$sha3-512$...`) instead of Argon2id (`$argon2id$...`).
   2. Existing Argon2id hashes in `idp_user_meta` are not migrated by this PR; deployments that already stored Argon2id hashes need re-initialization or a separate migration if applicable.
   
   ### How was this patch tested?
   
   - `./gradlew :plugins:idp-basic:spotlessApply`
   - `./gradlew :plugins:idp-basic:test --tests TestSha3512PasswordHasher -PskipITs`
   
   
   Made with [Cursor](https://cursor.com)


-- 
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@gravitino.apache.org

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


Re: [PR] [#11756] fix(authn): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on code in PR #11761:
URL: https://github.com/apache/gravitino/pull/11761#discussion_r3451501710


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/Sha3512PasswordHasher.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.gravitino.idp.basic.password;
+
+import com.google.common.base.Preconditions;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+import java.util.Base64;
+import org.apache.commons.lang3.StringUtils;
+
+/** SHA3-512 password hasher backed by the JDK {@link MessageDigest} API. */
+public class Sha3512PasswordHasher implements PasswordHasher {
+
+  private static final String PHC_PREFIX = Sha3512Defaults.PHC_PREFIX;
+  private static final String INVALID_HASH_FORMAT = "Invalid SHA3-512 hash format";
+  private static final String UNSUPPORTED_HASH_PARAMETERS = "Unsupported SHA3-512 hash parameters";
+  private static final SecureRandom SECURE_RANDOM = new SecureRandom();
+
+  @Override
+  public String hash(String plainPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+
+    byte[] salt = new byte[Sha3512Defaults.DEFAULT_SALT_LENGTH];
+    SECURE_RANDOM.nextBytes(salt);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    try {
+      byte[] hash =
+          digestPassword(
+              passwordBytes,
+              salt,
+              Sha3512Defaults.DEFAULT_ITERATIONS,
+              Sha3512Defaults.DEFAULT_HASH_LENGTH);
+      return toPhcString(salt, hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(salt, (byte) 0);
+    }
+  }
+
+  @Override
+  public boolean verify(String plainPassword, String hashedPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(hashedPassword), "Hashed password must not be blank");
+
+    ParsedHash parsedHash = parse(hashedPassword);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    byte[] actualHash =
+        digestPassword(
+            passwordBytes, parsedHash.salt, parsedHash.iterations, parsedHash.hash.length);
+    try {
+      return MessageDigest.isEqual(actualHash, parsedHash.hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(actualHash, (byte) 0);
+      Arrays.fill(parsedHash.salt, (byte) 0);
+      Arrays.fill(parsedHash.hash, (byte) 0);
+    }

Review Comment:
   Got resolved.



-- 
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@gravitino.apache.org

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


Re: [PR] [#11756] fix(authn): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

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


-- 
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@gravitino.apache.org

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


Re: [PR] [#11756] fix(authn): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11761:
URL: https://github.com/apache/gravitino/pull/11761#issuecomment-4768332630

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|67.15% **`+0.02%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|90.54%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.82%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.4%|:red_circle:|
   |catalog-fileset|80.23%|:green_circle:|
   |catalog-glue|66.91%|:green_circle:|
   |catalog-hive|79.42%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|44.22%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|58.53%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.86%|:green_circle:|
   |catalog-lakehouse-paimon|82.14%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|78.01%|:green_circle:|
   |common|50.17%|:green_circle:|
   |core|82.59%|:green_circle:|
   |filesystem-hadoop3|77.27%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|47.12%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.88%|:red_circle:|
   |hive-metastore-common|53.77%|:green_circle:|
   |iceberg-common|58.15%|:green_circle:|
   |iceberg-rest-server|73.98%|:green_circle:|
   |idp-basic|85.71% **`+0.39%`**|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.83%|:red_circle:|
   |lance-rest-server|60.13%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.95%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.96%|:green_circle:|
   |server-common|74.18%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|41.66%|:green_circle:|
   |trino-connector|40.25%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |idp-basic|[PasswordHasherFactory.java](https://github.com/lasdf1234/gravitino/blob/7b8cb0ad9fec3897e68cb3da2b154b665a3e5cbf/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/PasswordHasherFactory.java)|100.0%|:green_circle:|
   ||[Sha3512PasswordHasher.java](https://github.com/lasdf1234/gravitino/blob/7b8cb0ad9fec3897e68cb3da2b154b665a3e5cbf/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/Sha3512PasswordHasher.java)|90.41%|:green_circle:|
   ||[Sha3512Defaults.java](https://github.com/lasdf1234/gravitino/blob/7b8cb0ad9fec3897e68cb3da2b154b665a3e5cbf/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/Sha3512Defaults.java)|0.0%|:red_circle:|
   
   </details>


-- 
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@gravitino.apache.org

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


Re: [PR] [#11756] fix(authn): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11761:
URL: https://github.com/apache/gravitino/pull/11761#discussion_r3451403961


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/Sha3512PasswordHasher.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.gravitino.idp.basic.password;
+
+import com.google.common.base.Preconditions;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+import java.util.Base64;
+import org.apache.commons.lang3.StringUtils;
+
+/** SHA3-512 password hasher backed by the JDK {@link MessageDigest} API. */
+public class Sha3512PasswordHasher implements PasswordHasher {
+
+  private static final String PHC_PREFIX = Sha3512Defaults.PHC_PREFIX;
+  private static final String INVALID_HASH_FORMAT = "Invalid SHA3-512 hash format";
+  private static final String UNSUPPORTED_HASH_PARAMETERS = "Unsupported SHA3-512 hash parameters";
+  private static final SecureRandom SECURE_RANDOM = new SecureRandom();
+
+  @Override
+  public String hash(String plainPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+
+    byte[] salt = new byte[Sha3512Defaults.DEFAULT_SALT_LENGTH];
+    SECURE_RANDOM.nextBytes(salt);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    try {
+      byte[] hash =
+          digestPassword(
+              passwordBytes,
+              salt,
+              Sha3512Defaults.DEFAULT_ITERATIONS,
+              Sha3512Defaults.DEFAULT_HASH_LENGTH);
+      return toPhcString(salt, hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(salt, (byte) 0);
+    }
+  }
+
+  @Override
+  public boolean verify(String plainPassword, String hashedPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(hashedPassword), "Hashed password must not be blank");
+
+    ParsedHash parsedHash = parse(hashedPassword);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    byte[] actualHash =
+        digestPassword(
+            passwordBytes, parsedHash.salt, parsedHash.iterations, parsedHash.hash.length);
+    try {
+      return MessageDigest.isEqual(actualHash, parsedHash.hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(actualHash, (byte) 0);
+      Arrays.fill(parsedHash.salt, (byte) 0);
+      Arrays.fill(parsedHash.hash, (byte) 0);
+    }
+  }
+
+  private static byte[] digestPassword(
+      byte[] passwordBytes, byte[] salt, int iterations, int hashLength) {
+    MessageDigest digest = newDigest();
+    digest.update(salt);
+    digest.update(passwordBytes);
+    byte[] hash = digest.digest();
+    for (int i = 1; i < iterations; i++) {
+      hash = digest.digest(hash);
+    }
+    if (hash.length == hashLength) {
+      return hash;
+    }
+    return Arrays.copyOf(hash, hashLength);
+  }

Review Comment:
   Iterating a raw SHA3-512 digest (salt||password, then repeated digest-of-digest) is not a standard password hashing/KDF construction and is significantly less resistant to GPU/ASIC cracking than memory-hard KDFs (Argon2id/scrypt) or even PBKDF2 (which is available in the JDK via `SecretKeyFactory`). If the goal is to remove third-party crypto while keeping a safer construction, consider switching to PBKDF2 (e.g., PBKDF2WithHmacSHA512 / PBKDF2WithHmacSHA256 depending on JDK support) or scrypt (if acceptable), and encode parameters in the PHC string accordingly.



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/Sha3512PasswordHasher.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.gravitino.idp.basic.password;
+
+import com.google.common.base.Preconditions;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+import java.util.Base64;
+import org.apache.commons.lang3.StringUtils;
+
+/** SHA3-512 password hasher backed by the JDK {@link MessageDigest} API. */
+public class Sha3512PasswordHasher implements PasswordHasher {
+
+  private static final String PHC_PREFIX = Sha3512Defaults.PHC_PREFIX;
+  private static final String INVALID_HASH_FORMAT = "Invalid SHA3-512 hash format";
+  private static final String UNSUPPORTED_HASH_PARAMETERS = "Unsupported SHA3-512 hash parameters";
+  private static final SecureRandom SECURE_RANDOM = new SecureRandom();
+
+  @Override
+  public String hash(String plainPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+
+    byte[] salt = new byte[Sha3512Defaults.DEFAULT_SALT_LENGTH];
+    SECURE_RANDOM.nextBytes(salt);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    try {
+      byte[] hash =
+          digestPassword(
+              passwordBytes,
+              salt,
+              Sha3512Defaults.DEFAULT_ITERATIONS,
+              Sha3512Defaults.DEFAULT_HASH_LENGTH);
+      return toPhcString(salt, hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(salt, (byte) 0);
+    }
+  }
+
+  @Override
+  public boolean verify(String plainPassword, String hashedPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(hashedPassword), "Hashed password must not be blank");
+
+    ParsedHash parsedHash = parse(hashedPassword);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    byte[] actualHash =
+        digestPassword(
+            passwordBytes, parsedHash.salt, parsedHash.iterations, parsedHash.hash.length);
+    try {
+      return MessageDigest.isEqual(actualHash, parsedHash.hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(actualHash, (byte) 0);
+      Arrays.fill(parsedHash.salt, (byte) 0);
+      Arrays.fill(parsedHash.hash, (byte) 0);
+    }

Review Comment:
   If `digestPassword(...)` throws (e.g., provider issues inside `newDigest()`), the `finally` block is never reached and sensitive byte arrays won’t be cleared. Move the `digestPassword(...)` call inside the `try` so the cleanup always runs after `passwordBytes` is allocated.



-- 
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@gravitino.apache.org

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


Re: [PR] [#11756] fix(authn): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on PR #11761:
URL: https://github.com/apache/gravitino/pull/11761#issuecomment-4767086005

   @mchades If you have the time, could you please review the code for me?


-- 
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@gravitino.apache.org

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


Re: [PR] [#11756] fix(authn): Switch built-in IdP password hashing to JDK SHA3-512 [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on code in PR #11761:
URL: https://github.com/apache/gravitino/pull/11761#discussion_r3451495807


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/password/Sha3512PasswordHasher.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.gravitino.idp.basic.password;
+
+import com.google.common.base.Preconditions;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+import java.util.Base64;
+import org.apache.commons.lang3.StringUtils;
+
+/** SHA3-512 password hasher backed by the JDK {@link MessageDigest} API. */
+public class Sha3512PasswordHasher implements PasswordHasher {
+
+  private static final String PHC_PREFIX = Sha3512Defaults.PHC_PREFIX;
+  private static final String INVALID_HASH_FORMAT = "Invalid SHA3-512 hash format";
+  private static final String UNSUPPORTED_HASH_PARAMETERS = "Unsupported SHA3-512 hash parameters";
+  private static final SecureRandom SECURE_RANDOM = new SecureRandom();
+
+  @Override
+  public String hash(String plainPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+
+    byte[] salt = new byte[Sha3512Defaults.DEFAULT_SALT_LENGTH];
+    SECURE_RANDOM.nextBytes(salt);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    try {
+      byte[] hash =
+          digestPassword(
+              passwordBytes,
+              salt,
+              Sha3512Defaults.DEFAULT_ITERATIONS,
+              Sha3512Defaults.DEFAULT_HASH_LENGTH);
+      return toPhcString(salt, hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(salt, (byte) 0);
+    }
+  }
+
+  @Override
+  public boolean verify(String plainPassword, String hashedPassword) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(plainPassword), "Plain password must not be blank");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(hashedPassword), "Hashed password must not be blank");
+
+    ParsedHash parsedHash = parse(hashedPassword);
+    byte[] passwordBytes = plainPassword.getBytes(StandardCharsets.UTF_8);
+    byte[] actualHash =
+        digestPassword(
+            passwordBytes, parsedHash.salt, parsedHash.iterations, parsedHash.hash.length);
+    try {
+      return MessageDigest.isEqual(actualHash, parsedHash.hash);
+    } finally {
+      Arrays.fill(passwordBytes, (byte) 0);
+      Arrays.fill(actualHash, (byte) 0);
+      Arrays.fill(parsedHash.salt, (byte) 0);
+      Arrays.fill(parsedHash.hash, (byte) 0);
+    }
+  }
+
+  private static byte[] digestPassword(
+      byte[] passwordBytes, byte[] salt, int iterations, int hashLength) {
+    MessageDigest digest = newDigest();
+    digest.update(salt);
+    digest.update(passwordBytes);
+    byte[] hash = digest.digest();
+    for (int i = 1; i < iterations; i++) {
+      hash = digest.digest(hash);
+    }
+    if (hash.length == hashLength) {
+      return hash;
+    }
+    return Arrays.copyOf(hash, hashLength);
+  }

Review Comment:
   Built-in IdP password hashing is limited to the JDK JCA provider to reduce EAR Category 5D002 export-control scope for ASF binary releases.
   So there is no need to modify it to PBKDF2WithHmacSHA512.
   Comments have been added to the code.



-- 
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@gravitino.apache.org

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