简体   繁体   English

将 PEM 文件转换为 .JKS Key Store 和 Trust Store 文件

[英]Converting a PEM file to a .JKS Key Store and Trust Store files

PEM file from the server side which is in the following format when opened:服务器端的PEM文件,打开后格式如下:

-----BEGIN CERTIFICATE-----
somestuff1234
-----END CERTIFICATE-----

I'm trying to convert this to get two JKS files (A trust store and key store) which I can call the server with using my java application through SSL.我正在尝试将其转换为获取两个 JKS 文件(一个信任库和密钥库),我可以使用我的 java 应用程序通过 SSL 调用服务器。

Can anyone help in a easy break down on how to do this using openssl and then the java keystore?任何人都可以帮助轻松分解如何使用 openssl 然后使用 java 密钥库来执行此操作吗? I tried following the instructions in: https://docs.oracle.com/cd/E35976_01/server.740/es_admin/src/tadm_ssl_convert_pem_to_jks.html我尝试按照以下说明进行操作: https://docs.oracle.com/cd/E35976_01/server.740/es_admin/src/tadm_ssl_convert_pem_to_jks.html

But I couldn't import the keystore successfully as for some reason it was empty.但由于某种原因,我无法成功导入密钥库,因为它是空的。 PS when following these instructions I created the PKSC12 from der without a private key inputted since I wasn't provided one. PS 在按照这些说明进行操作时,我从 der 创建了 PKSC12,但没有输入私钥,因为没有提供私钥。

Do I need to use my own private key which I need to create as well but not sure if it is needed since I was only given the certificate?我是否需要使用我自己也需要创建的私钥,但不确定是否需要它,因为我只获得了证书? I've been told intermediate certs are sent in the TLS handshake.我被告知中间证书是在 TLS 握手中发送的。

Thanks for any help on this.感谢您对此的任何帮助。

Try to run your java code with debug mode and specific truststore regarding the SSL server like described here: How to configure trustStore for javax.net.ssl.trustStore on windows?尝试使用调试模式和有关 SSL 服务器的特定信任库运行 java 代码,如下所述: How to configure trustStore for javax.net.ssl.trustStore on windows?

If the only thing in that PEM file is what you've posted:如果该 PEM 文件中唯一的内容就是您发布的内容:

-----BEGIN CERTIFICATE-----
somestuff1234
-----END CERTIFICATE-----

you will not be able to create a full keystore suitable for use as a TLS server that accepts connections.您将无法创建适合用作接受连接的 TLS 服务器的完整密钥库。

You need the private key corresponding to the certificate for that.为此,您需要与证书相对应的私钥。

Do I need to use my own private key which I need to create as well but not sure if it is needed since I was only given the certificate?我是否需要使用我自己也需要创建的私钥,但不确定是否需要它,因为我只获得了证书?

No - along with its identifying data, your certificate has a public key in it.否 - 连同其识别数据,您的证书中有一个公钥。 The entire certificate was cryptographically signed by your CA - which is how the "trust" is transferred to your certificate.整个证书由您的 CA 以加密方式签名 - 这就是“信任”转移到您的证书的方式。 The public key in your certificate was derived from a specific private key.您证书中的公钥源自特定的私钥。

Why won't it work?为什么它不起作用? Because data that's encrypted using the public key in your certificate can only be decrypted using the private key that public key was derived from.因为使用证书中的公钥加密的数据只能使用派生公钥的私钥解密。

Your certificate will only work if it's paired with the correct private key.您的证书只有在与正确的私钥配对时才有效。

But:但:

I created the PKSC12 from der without a private key inputted since I wasn't provided one.我从 der 创建了 PKSC12,但没有输入私钥,因为没有提供私钥。

You must have a private key along with your certificate to be able to run a TLS server.*您必须拥有私钥和证书才能运行 TLS 服务器。*

EDIT:编辑:

And you must have the proper private key paired with your certificate to use it as a client certificate when connecting to a TLS server for the same reason.出于同样的原因,您必须将正确的私钥与您的证书配对,才能在连接到 TLS 服务器时将其用作客户端证书。

Also, a TLS certificate is public - if it were all you needed to prove your identity, publicizing that would make it useless.此外,TLS 证书是公开的——如果您只需要它来证明您的身份,那么将其公之于众会使它毫无用处。 Your possession of the appropriate private key is what proves that the certificate is your certificate and not mine or anyone else's.您拥有适当的私钥就可以证明该证书是您的证书,而不是我的或其他任何人的。

Your TLS server or your client connection to a TLS server isn't going to work until you locate the proper private key for the certificate you have.在您为您拥有的证书找到正确的私钥之前,您的 TLS 服务器或与 TLS 服务器的客户端连接将无法工作。 If you or your organization have lost that private key, you have to create a new private key and go through the process of creating a new certificate from that new private key.如果您或您的组织丢失了该私钥,则必须通过从该新私钥创建证书的过程创建一个新的私钥和 go。

Because without the correct private key, the certificate you have now is utterly useless.因为没有正确的私钥,你现在拥有的证书就毫无用处。

* - Technically not true. * - 技术上不正确。 The TLS standard does support "anonymous" cipher suites that do not require any certificate or private key. TLS 标准确实支持不需要任何证书或私钥的“匿名”密码套件 But almost no application supports anonymous cipher suites.但几乎没有应用程序支持匿名密码套件。 OpenSSL only supports anonymous cipher suites if you compile it from source yourself, for example.例如,OpenSSL 如果您自己从源代码编译它,则仅支持匿名密码套件。

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

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