除了pascal-thivent 的出色回答:
密钥库密码有两个用途 - 如果未提供,则keytool
拒绝让您用新内容替换存储的内容,例如删除现有的或添加新的证书条目。
当然,如果您有写入权限来使用keytool
(它不是 setuid)更新密钥库文件,您可以使用另一个不检查密码的工具替换内容。而且我们知道存储及其格式无需密码即可读取,因此大概我们可以在那里编写我们想要的内容。
这就是验证密码的来源。当存储条目被写出时,提供的存储密码用于计算存储内容的摘要,由密码加盐。这是一种单向哈希/摘要,因此没有密码,您无法验证存储内容是否已被篡改。同样,不知道密码的恶意人员也无法修改存储的内容并生成由该密码生成的摘要哈希。
这就是为什么当你提供无密码时,keytool
只是警告你它无法验证商店没有被篡改。如果您提供的密码无效,或者商店已被篡改,您将收到不同的消息:
Enter keystore password:
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
keytool
无法根据当前存储内容和您提供的密码重新创建现有的哈希摘要,因此密码不正确或密钥库已泄露 -keytool
无法判断,但假设您或读取存储的软件知道.
Note that whilst the term keystore is used generally, it refers equally to keystores and truststores. Less-generally, a keystore is more often an identity store and contains identities and their secret, private keys, as used e.g. by a server running HTTPS. A truststore more often contains only public keys and no private keys, so no secrets, but is important to determine what identities a client trusts.