我知道密钥存储库通常保存私有/公共密钥,而信任存储库只存储公共密钥(并且表示您打算与之通信的受信任方的列表)。嗯,这是我的第一个假设,所以如果这不是正确的,我可能没有很好地开始……

虽然我有兴趣了解如何/当你使用keytool区分商店。

至此,我已经使用

keytool -import -alias bob -file bob.crt -keystore keystore.ks

它创建了我的密钥存储库。ks文件。对于我是否信任bob的问题,我的回答是肯定的,但我不清楚这是否创建了keystore文件或信任库文件?我可以设置我的应用程序使用该文件。

-Djavax.net.ssl.keyStore=keystore.ks -Djavax.net.ssl.keyStorePassword=x
-Djavax.net.ssl.trustStore=keystore.ks -Djavax.net.ssl.trustStorePassword=x

和系统。setProperty("javax.net.debug", "ssl")设置后,我可以在受信任的证书下看到证书(但不在keystore部分下)。我正在导入的特定证书只有一个公钥,我打算使用它通过SSL连接向Bob发送内容(但这可能最好留给另一个问题!)。

任何指示或澄清将非常感激。keytool的输出是否与您导入的任何内容相同,只是约定说一个是密钥存储库,另一个是信任存储库?使用SSL等时是什么关系?


当前回答

解释:用一般的用法/目的或外行的方式解释:

TrustStore:用于存储证书 信任实体。进程可以维护所有受信任方的证书存储 它信任这一点。 keyStore:用于存储服务器密钥(公共密钥和私有密钥) 连同已签名的证书。

在SSL握手期间,

A client tries to access https:// And thus, Server responds by providing a SSL certificate (which is stored in its keyStore) Now, the client receives the SSL certificate and verifies it via trustStore (i.e the client's trustStore already has pre-defined set of certificates which it trusts.). Its like : Can I trust this server ? Is this the same server whom I am trying to talk to ? No middle man attacks ? Once, the client verifies that it is talking to server which it trusts, then SSL communication can happen over a shared secret key.

注意:我在这里讨论的不是服务器端的客户端身份验证。如果服务器也想进行客户机身份验证,那么服务器还维护一个trustStore来验证客户机。然后它就变成了相互TLS。

其他回答

以下是使用Keytool在本地机器上创建信任库的步骤。 在本地机器上为URL创建信任存储库的步骤。

1)使用chrome浏览器点击url

2)在chrome浏览器中检查url左侧的“i”图标并单击它

3)检查证书选项,点击,弹出对话框

4)检查“证书路径”选项卡中可用于创建信任库的证书数量

5)进入“详细信息”选项卡->点击“复制到文件”->给出你想要创建的证书的路径和名称。

6)检查是否有父证书,按“5”。

7)所有证书创建完成后,打开命令提示符并导航到创建证书的路径。

8)提供以下Keytool命令来添加证书并创建信任库。

Sample: 
   keytool -import -alias abcdefg -file abcdefg.cer -keystore cacerts
        where "abcdefg" is the alias name and "abcdefg.cer" is the actual certificate name and "cacerts" is the truststore name

9)为所有证书提供keytool命令,并将它们添加到信任存储区。

    keytool -list -v -keystore cacerts

密钥存储库仅存储私钥,而信任存储库存储公钥。您需要为SSL通信生成一个java证书。你可以在windows中使用keygen命令,这可能是最简单的解决方案。

服务器使用Keystore存储私钥,第三方客户端使用Truststore存储服务器提供的供访问的公钥。我已经在我的生产应用程序中这样做了。以下是为SSL通信生成java证书的步骤:

windows下使用keygen命令生成证书:

keytool -genkey -keystore server.keystore -alias mycert -keyalg RSA -keysize 2048 -有效期 3950

自我认证证书:

keytool -selfcert -aka mycert -keystore server.keystore -valid 3950

导出证书到文件夹:

Keytool -export -alias mycert -keystore服务器。Keystore -rfc -file mycert.cer

将证书导入客户端信任库:

keytool -importcert -alias mycert -file mycert.cer -keystore truststore

解释:用一般的用法/目的或外行的方式解释:

TrustStore:用于存储证书 信任实体。进程可以维护所有受信任方的证书存储 它信任这一点。 keyStore:用于存储服务器密钥(公共密钥和私有密钥) 连同已签名的证书。

在SSL握手期间,

A client tries to access https:// And thus, Server responds by providing a SSL certificate (which is stored in its keyStore) Now, the client receives the SSL certificate and verifies it via trustStore (i.e the client's trustStore already has pre-defined set of certificates which it trusts.). Its like : Can I trust this server ? Is this the same server whom I am trying to talk to ? No middle man attacks ? Once, the client verifies that it is talking to server which it trusts, then SSL communication can happen over a shared secret key.

注意:我在这里讨论的不是服务器端的客户端身份验证。如果服务器也想进行客户机身份验证,那么服务器还维护一个trustStore来验证客户机。然后它就变成了相互TLS。

密钥存储库文件和信任存储库文件之间没有区别。这两个文件都是专有的JKS文件格式。区别在于使用:据我所知,在创建SSL连接时,Java只使用由-Djavax.net.ssl.trustStore系统属性引用的存储来查找要信任的证书。密钥和-Djavax.net.ssl.keyStore也一样。但是从理论上讲,使用同一个文件进行信任和密钥存储是可以的。