我遵循以下教程来设置我的tomcat ssl:http://www.mkyong.com/tomcat/how-to-configure-tomcat-to-support-ssl-or-https/
我将密钥库文件命名为mystore2.jks,而不是mkyongkeystore。然后,我向密钥库添加了另一个类似这样的证书。
keytool -genkey -alias testhim -keyalg RSA -keystore mystore2.jks然后按如下方式导出:
keytool -export -alias testhim -file forcurl.crt -keystore mystore2.jks 现在我想使用'forcurl.crt‘测试我的tomcat https。
curl https://localhost:8443 --cert forcurl.crt
curl: (58) unable to use client certificate (no key found or wrong pass phrase?)如何传递密码?导出的证书应该是crt文件吗?方法是否正确,从tomcat指向的keystore导出证书,然后使用该证书和curl访问tomcat url?
forcurl.crt看起来像这样,这个编码叫什么?肯定不是PEM:
3082 036d 3082 0255 a003 0201 0202 0433
c4ed 0830 0d06 092a 8648 86f7 0d01 010b
0500 3067 310b 3009 0603 5504 0613 0264
6b31 1030 0e06 0355 0408 1307 7465 7374
6869 6d31 1030 0e06 0355 0407 1307 7465
7374 6869 6d31 1030 0e06 0355 040a 1307
7465 7374 6869 6d31 1030 0e06 0355 040b
1307 7465 7374 6869 6d31 1030 0e06 0355
0403 1307 7465 7374 6869 6d30 1e17 0d31
...我可以使用以下命令访问url并获得响应: curl https://localhost:8443 --insecure
我不想让任何人访问该URL,因为它将是REST API。要访问url,需要出示他的证书。
我将tomcat>server.xml https连接器更改为true clientAuth="true“。
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="true" sslProtocol="TLS" keystoreFile="/home/nowshad/dump/mystore2.jks"
keystorePass="123456"/>然后使用:
curl https://localhost:8443 --insecure -v这是输出:
user@user-System:~$ curl https://localhost:8443 --insecure -v
* Rebuilt URL to: https://localhost:8443/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Request CERT (13):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* Unknown SSL protocol error in connection to localhost:8443
* Closing connection 0
curl: (35) Unknown SSL protocol error in connection to localhost:8443 发布于 2016-06-01 02:45:38
如果是自签名证书,curl https://localhost:8443 --insecure应该足以进行测试。如果它是由CA签名的,那么您只需正常调用它,即curl https://localhost:8443。
客户端不需要证书,尤其是不需要密钥,就可以进行通信。当客户端连接时,服务器将提供证书。
客户机所需要的就是签署证书的CA证书,这样它就可以验证证书是否有效。
Add -v将详细输出添加到cURL。
https://stackoverflow.com/questions/37553209
复制相似问题