简体   繁体   English

密钥库/信任库中必须包含哪些内容才能进行相互身份验证?

[英]What must be contained in the keystores/truststores for mutual authentication?

I am trying to perform mutual authentication in Java. 我正在尝试在Java中执行相互身份验证。 The structure of what I am trying to achieve is: server with self-signed certificate acts as a CA, signing the client certificate. 我想要实现的结构是:具有自签名证书的服务器充当CA,签署客户端证书。 Therefore, this is what I keep in each keystore/truststore: 因此,这是我在每个密钥库/信任库中保留的内容:

Client: 客户:

Keystore: 密钥库:

  • Client's SSL keypair. 客户的SSL密钥对。
  • Signed certificate by server (related to the keypair). 服务器签名证书(与密钥对相关)。

Truststore: 信任:

  • Server's selfsigned certificate. 服务器的自签名证书。

Server 服务器

Keystore: 密钥库:

  • Server's SSL keypair. 服务器的SSL密钥对。
  • Self-signed certificate (related to the keypair). 自签名证书(与密钥对相关)。

Truststore: 信任:

  • Server's selfsigned certificate. 服务器的自签名证书。

I am able to perform server's authentication, but when I enable setNeedClientAuth(true) on the server, I get the following errors at the log: http://pastebin.com/raw.php?i=P52Qq89z So the server seems to authenticate but the client cannot provide the CA chain, may it be an issue with the contents of its keystore? 我能够执行服务器的身份验证,但是当我在服务器上启用setNeedClientAuth(true)时,我在日志中收到以下错误: http ://pastebin.com/raw.php?i = P52Qq89z因此服务器似乎验证了但客户端无法提供CA链,可能是其密钥库内容的问题?

I used openSSL to generate the keys and the certificates, KeyStore Explorer to create the keystores (after a couple of days of unsuccessful use of keytool) and JDK 1.7.0_51 我使用openSSL生成密钥和证书,KeyStore Explorer创建密钥库(在使用keytool几天后)和JDK 1.7.0_51

UPDATE: the problem was solved following these instructions: https://stackoverflow.com/a/12150604/2891462 It was a problem with how the CA self-signed certificate had been created (only an issue in JDK 1.7, apparently). 更新:问题已按照以下说明解决: https//stackoverflow.com/a/12150604/2891462这是如何创建CA自签名证书的问题(显然只是JDK 1.7中的一个问题)。

There a couple of things that are wrong in your configuration. 您的配置中有一些错误。

Looking at your debugging logs, your certificate doesn't have the basic constraints to say CA=true. 查看调试日志,证书没有CA = true的基本约束。

[
  Version: V1
  Subject: CN=Ficticious bank, OU=SoE, O=University, L=London, ST=England, C=UK
  Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5
  Key:  Sun RSA public key, 2048 bits
  Validity: [From: Wed May 07 19:21:23 BST 2014,
               To: Thu May 07 19:21:23 BST 2015]
  Issuer: CN=Ficticious bank, OU=SoE, O=University, L=London, ST=England, C=UK
  SerialNumber: [    9a7143cf f5ecfbf8]

]
  Algorithm: [SHA1withRSA]
  ...
]

It's not going to work as a CA if it's not a CA certificate. 如果它不是CA证书,它将无法作为CA工作。 See RFC 3280 (and 5280): 请参阅RFC 3280 (和5280):

  This extension MUST appear as a critical extension in all CA certificates that contain public keys used to validate digital signatures on certificates. 

Secondly, this certificate, which you also want to use as an End-Entity Certificate (EEC) for your server doesn't have a valid name for that server: no Subject Alternative Name and a CN that visibly doesn't match any host name. 其次,此证书(您还希望用作服务器的最终实体证书(EEC))没有该服务器的有效名称:没有主题备用名称和可见与任何主机名称不匹配的CN 。 While the default SSLSocket doesn't do any hostname verification by default (you can configure it), it's useful to have a valid host name for a server certificate, since clients should really verify it in principle. 虽然默认SSLSocket默认情况下不进行任何主机名验证(您可以对其进行配置),但拥有服务器证书的有效主机名很有用,因为客户端原则上应该真正验证它。

Overall, there doesn't seem to be many benefits in using the very same certificate for the CA and the server certificate. 总的来说,对CA和服务器证书使用相同的证书似乎没有多少好处。 Self-signed certificates are mainly useful when used on their own. 自签名证书在单独使用时非常有用。 If you're planning to use it as a CA certificate too, you might as well separate the CA certificate and the server certificate. 如果您计划将其用作CA证书,则可以将CA证书和服务器证书分开。 It will certainly be useful in the long run, in particular when you have to change the server cert, on "Thu May 07 19:21:23 BST 2015" in your example, or if perhaps you need to re-issue the server cert for any other reason. 从长远来看,它肯定是有用的,特别是当你必须在你的例子中“在2015年5月7日19:21:23 BST 2015”更改服务器证书时,或者你可能需要重新颁发服务器证书由于任何其他原因。

Beside this, you have the right idea for your keystore and truststore: 除此之外,您对密钥库和信任库有正确的想法:

  • Client: 客户:

    • Keystore: 密钥库:

      • Client private key and certificate chain in the same entry (but the CA certificate itself can be omitted). 客户端私钥和证书链在同一条目中(但可以省略CA证书本身)。
    • Truststore: 信任:

      • CA certificate(s) that can validate the server cert. 可以验证服务器证书的CA证书。
  • Server 服务器

    • Keystore: 密钥库:

      • Server private key and certificate chain in the same entry (but the CA certificate itself can be omitted). 服务器私钥和证书链在同一条目中(但可以省略CA证书本身)。
    • Truststore: 信任:

      • CA certificate(s) that can validate the client certs. 可以验证客户端证书的CA证书。

for mutual authentication(2 way SSL) only 2 things needs to be done 对于相互认证(双向SSL),只需要做两件事

server's certificate exported from server's keystore(not trust store - in case you are using different trust and key store) 从服务器的密钥库导出的服务器证书(不是信任存储 - 如果您使用的是不同的信任和密钥存储区)

and second is 第二是

client's certificate should be present in server's truststore(not key store - in case you are using different trust and key store) 客户端的证书应该存在于服务器的信任库中(而不是密钥库 - 如果您使用的是不同的信任和密钥存储区)

additionally there is a good blog here to read about the same 另外有一个很好的博客点击这里阅读有关同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM