gpt4 book ai didi

java - Tomcat SecretKeyCredentialHandler 属性?

转载 作者:行者123 更新时间:2023-11-28 22:16:11 24 4
gpt4 key购买 nike

问题:

Tomcat 9 Realm <CredentialHandler>需要适当的算法参数来散列密码并根据密码对用户进行身份验证吗?

无论我向 PBKDF2WithHmacSHA512 算法传递什么参数,我的 webapp 似乎都能够对用户进行身份验证,即使 <CredentialHandler> 上的属性也是如此元素不同,或者没有任何属性。

这是 Tomcat 领域的预期行为吗?如果是这样,这怎么可能? Realm 是否能够从哈希的组成中推断出参数?

背景:

Tomcat 9 通过基于 Java 的 SecretKeyFactory 的 Realm 提供容器管理的安全性算法。

我正在使用 PBKDF2WithHmacSHA512,它有以下选项:

  • 迭代
  • key 长度
  • 盐长度

我的 CredentialHandler 在我的网络应用程序的 context.xml 中定义是

<CredentialHandler
className="org.apache.catalina.realm.SecretKeyCredentialHandler"
algorithm="PBKDF2WithHmacSHA512"
iterations="100000"
keyLength="256"
saltLength="16">
</CredentialHandler>

Tomcat 安装提供了对位于 CATALINA_HOME/bin/digest.[bat|sh] 的散列算法的 CLI 访问. (有关详细信息,请参阅 Tomcat 9 Realm Configuration HOW-To。)

无论我传递给 CLI 哈希算法的选项是什么,Tomcat 都能够从 DataSource 领域(MySQL 数据库)正确验证用户。可以针对以下两项成功验证密码:

示例 #1 匹配 <CredentialHandler> :

$ $CATALINA_HOME/bin/digest.sh -a PBKDF2WithHmacSHA512 -i 100000 -s 
16 -k 256 -h org.apache.catalina.realm.SecretKeyCredentialHandler passw0rd
passw0rd:d0c315b015272b531b0a82cec220d4a1$100000$7ac32ed573fe81e75f611a46622573515
ad11d731dcae4839973ae2702774c51

示例 #2 不同的参数:

$ $CATALINA_HOME/bin/digest.sh -a PBKDF2WithHmacSHA512 -i 100 -s 1 -k 128 
-h org.apache.catalina.realm.SecretKeyCredentialHandler passw0rd
passw0rd:47$100$0e4790b617fa24ee324d55bed38ad4b0

另见

最佳答案

是的,这是 Tomcat Realm 的预期行为,SecretKeyCredentialHandler 定义为 CredentialHandler。 Tomcat 不需要 context.xml 中的迭代、salt 或 key 参数来通过密码对用户进行身份验证。

这怎么可能?

如果您查看 tomcat documentation of the SecretKeyCredentialHandler ,您会注意到存储的密码定义为:

salt $ iterationCount $ encodedCredential - a hex encoded salt, iteration code and a hex encoded credential, each separated by $.

用于加密的saltiterationCount 是存储密码的一部分。 Tomcat 不使用 context.xml 中的 CredentialHandler 标记值进行解密。它使用密码本身的值。如果查看两个生成的密码,您会在其中找到 salt 和 iterationCount,格式为定义的模式。

为什么我必须在 context.xml 中设置值?

你不必。对于解密,仅使用 context.xml 中的算法属性值。那么,其他属性是什么?仔细阅读Tomcat documentation给出答案:

The CredentialHandler can also be used to generate a new stored version of a given credential that would be required, for example, when adding a new user to a Realm or when changing a user's password.

iterations - The number of iterations to use when creating a newstored credential from a clear text credential.

saltLength - The length of the randomly generated salt to use whencreating a new stored credential from a clear text credential.

keyLength - The length of key to generate for the storedcredential. If not specified, a default of 160 is used.

这些 CredentialHandler - 来自 context.xml 的标记属性在通过 CredentialHandler 创建新密码时使用(参见 API 中的方法 mutate ).它用于加密以创建新密码,而不是用于解密现有密码。

关于java - Tomcat SecretKeyCredentialHandler 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49709729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com