【发布时间】:2016-09-29 21:49:34
【问题描述】:
我按照本教程设置我的 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 指向的密钥库中导出证书,然后使用带有 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
【问题讨论】:
标签: tomcat ssl curl https certificate