简体   繁体   English

使用 TLS 的 Apache HTTPClient

[英]Apache HTTPClient using TLS

Sorry guys, i'm searching in all the internet for this but i need someone to help me.对不起,我正在互联网上搜索这个,但我需要有人帮助我。 I've written a client for a particular server and i'm using apache http client to communicate with it.Now i've put TLS over the communication and i'd like to know how to put my client certificate into the communication in order to use HTTPs.I'm not very confident with the java keystore et similia so i need someone that helps me.我已经为特定服务器编写了一个客户端,我正在使用 apache http 客户端与它进行通信。现在我已经将 TLS 放在了通信上,我想知道如何将我的客户端证书按顺序放入通信中使用 HTTPs。我对 java keystore et similia 不是很自信,所以我需要有人帮助我。

The keytool manual describes how to manipulate keystores. keytool 手册描述了如何操作密钥库。 The method you're interested into is -importcert.您感兴趣的方法是-importcert。

You should first find out where the truststore your client uses is.您应该首先找出您的客户使用的信任库在哪里。 It can be specified by the -Djavax.net.ssl.trustStore javaopt, or it could be your JDK/JRE installation's default, whose location is <java_home>/jssecacerts or <java_home>/cacerts .它可以由-Djavax.net.ssl.trustStore javaopt 指定,也可以是您的 JDK/JRE 安装的默认值,其位置是<java_home>/jssecacerts<java_home>/cacerts

Then you should retrieve the server's certificate.然后您应该检索服务器的证书。 If you can you should ask the server's admin to provide it in a secure fashion.如果可以,您应该要求服务器的管理员以安全的方式提供它。 Otherwise you can contact the server in different ways so it provides its certificate, the easier being accessing its https interface on a browser.否则,您可以通过不同的方式联系服务器,以便它提供其证书,在浏览器上访问其 https 界面会更容易。

At this point you can import the certificate in a truststore.此时,您可以在信任库中导入证书。 If you use an existing truststore like cacerts, the certificate will be added as a new entry, or you can provide a path that corresponds to no file to the -keystore argument, in which case a new truststore with your certificate as its unique entry would be created at this location.如果您使用现有的信任库(如 cacerts),则证书将作为新条目添加,或者您可以提供与-keystore参数对应的无文件的路径,在这种情况下,将您的证书作为其唯一条目的新信任库将在此位置创建。 I would recommend the latter unless your client will later communicate with CA-trusted servers.我会推荐后者,除非您的客户端稍后将与 CA 信任的服务器进行通信。

Your keytool command should look something like that :您的 keytool 命令应该如下所示:
keytool -importcert -alias <a name for the cert> -file <cert's path> -keystore <truststore's path> -storepass <the truststore's password>

If you create a new truststore, the -storepass provided will unlock it for later uses, and must be specified to your client by the -Djavax.net.ssl.trustStorePassword javaopt.如果您创建一个新的信任库,提供的-storepass将解锁它供以后使用,并且必须由-Djavax.net.ssl.trustStorePassword javaopt 指定给您的客户端。 If you use an existing truststore you must provide its password (I believe cacerts' is changeit ).如果您使用现有的信任库,则必须提供其密码(我相信 cacerts' 是changeit )。

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

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