Tomcat SecretKeyCredentialHandler 属性?
Tomcat SecretKeyCredentialHandler Attributes?
问题:
Tomcat 9 Realm <CredentialHandler>
是否需要正确的算法参数来散列密码并根据密码对用户进行身份验证?
无论我向 PBKDF2WithHmacSHA512 算法传递什么参数,我的 webapp 似乎都能够对用户进行身份验证,即使 <CredentialHandler>
元素上的属性不同,或者没有任何属性。
这是 Tomcat 领域的预期行为吗?如果是这样,这怎么可能? Realm 是否能够从散列的组成中推断出参数?
背景:
Tomcat 9 通过基于 Java 的 SecretKeyFactory 算法的领域提供容器管理的安全性。
我正在使用 PBKDF2WithHmacSHA512,它有选项:
- 迭代次数
- 密钥长度
- 盐长度
我的 Web 应用程序 context.xml
中定义的 CredentialHandler 是
<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:d0c315b015272b531b0a82cec220d4a10000ac32ed573fe81e75f611a46622573515
ad11d731dcae4839973ae2702774c51
示例 #2 不同的参数:
$ $CATALINA_HOME/bin/digest.sh -a PBKDF2WithHmacSHA512 -i 100 -s 1 -k 128
-h org.apache.catalina.realm.SecretKeyCredentialHandler passw0rd
passw0rd:470[=13=]e4790b617fa24ee324d55bed38ad4b0
另见
- Tomcat - Understanding CredentialHandler
是的,这是 Tomcat Realm 的预期行为,其中 SecretKeyCredentialHandler 定义为 CredentialHandler。 Tomcat 不需要 context.xml 中的迭代、salt 或密钥参数来通过密码对用户进行身份验证。
这怎么可能?
如果您查看 tomcat documentation of the SecretKeyCredentialHandler,您会注意到存储的密码定义为:
salt $ iterationCount $ encodedCredential - a hex encoded salt, iteration code and a hex encoded credential, each separated by $.
用于加密的salt和iterationCount是存储密码的一部分。 Tomcat 不使用来自 context.xml 的 CredentialHandler-Tag 的值进行解密。它使用密码本身的值。如果查看两个生成的密码,您会在其中找到 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 new
stored credential from a clear text credential.
saltLength - The length of the randomly generated salt to use when
creating a new stored credential from a clear text credential.
keyLength - The length of key to generate for the stored
credential. If not specified, a default of 160 is used.
这些 CredentialHandler-来自 context.xml 的标记属性在通过 CredentialHandler 创建新密码时使用(参见方法 变异 在API)。它用于加密以创建新密码,而不是用于解密现有密码。
问题:
Tomcat 9 Realm <CredentialHandler>
是否需要正确的算法参数来散列密码并根据密码对用户进行身份验证?
无论我向 PBKDF2WithHmacSHA512 算法传递什么参数,我的 webapp 似乎都能够对用户进行身份验证,即使 <CredentialHandler>
元素上的属性不同,或者没有任何属性。
这是 Tomcat 领域的预期行为吗?如果是这样,这怎么可能? Realm 是否能够从散列的组成中推断出参数?
背景:
Tomcat 9 通过基于 Java 的 SecretKeyFactory 算法的领域提供容器管理的安全性。
我正在使用 PBKDF2WithHmacSHA512,它有选项:
- 迭代次数
- 密钥长度
- 盐长度
我的 Web 应用程序 context.xml
中定义的 CredentialHandler 是
<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:d0c315b015272b531b0a82cec220d4a10000ac32ed573fe81e75f611a46622573515
ad11d731dcae4839973ae2702774c51
示例 #2 不同的参数:
$ $CATALINA_HOME/bin/digest.sh -a PBKDF2WithHmacSHA512 -i 100 -s 1 -k 128
-h org.apache.catalina.realm.SecretKeyCredentialHandler passw0rd
passw0rd:470[=13=]e4790b617fa24ee324d55bed38ad4b0
另见
- Tomcat - Understanding CredentialHandler
是的,这是 Tomcat Realm 的预期行为,其中 SecretKeyCredentialHandler 定义为 CredentialHandler。 Tomcat 不需要 context.xml 中的迭代、salt 或密钥参数来通过密码对用户进行身份验证。
这怎么可能?
如果您查看 tomcat documentation of the SecretKeyCredentialHandler,您会注意到存储的密码定义为:
salt $ iterationCount $ encodedCredential - a hex encoded salt, iteration code and a hex encoded credential, each separated by $.
用于加密的salt和iterationCount是存储密码的一部分。 Tomcat 不使用来自 context.xml 的 CredentialHandler-Tag 的值进行解密。它使用密码本身的值。如果查看两个生成的密码,您会在其中找到 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 new stored credential from a clear text credential.
saltLength - The length of the randomly generated salt to use when creating a new stored credential from a clear text credential.
keyLength - The length of key to generate for the stored credential. If not specified, a default of 160 is used.
这些 CredentialHandler-来自 context.xml 的标记属性在通过 CredentialHandler 创建新密码时使用(参见方法 变异 在API)。它用于加密以创建新密码,而不是用于解密现有密码。