我正在尝试设置在 Tomcat 7 中运行的 Java Web 服务以使用相互(2 路)身份验证。似乎无论我做什么,都无法连接到安全端口上的服务。
这是我为创建证书和密钥库等所做的:
//create the key and certificate for the tomcat server.
keytool -genkey -v -alias tomcat -keyalg RSA -validity 3650 -keystore tomcat.keystore
//create the key and certificate for the client machine.
keytool -genkey -v -alias clientkey -keyalg RSA -storetype PKCS12 -keystore client.p12
//export the client key
keytool -export -alias clientkey -keystore client.p12 -storetype PKCS12 -rfc -file client.cer
//import the client key into the server keystore
keytool -import -v -file client.cer -keystore tomcat.keystore
这是 server.xml 文件中的连接器:
<Connector port="8443"
maxThreads="150"
scheme="https"
secure="true"
sslProtocol="TLS"
clientAuth="true"
keystoreFile="tomcat.keystore"
keystorePass="tomcat"
truststoreFile="tomcat.keystore"
truststorePass="tomcat"/>
tomcat-users.xml 文件如下所示:
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="admin"/>
<!-- note that the actual values for CN, OU, O, L, ST are different, but they match the values created in the client certificate -->
<user username="CN=name, OU=unit, O=org, L=locality, ST=state, C=US" password="null" roles="admin" />
</tomcat-users>
以下是在启动时设置的:
-Djavax.net.ssl.keyStoreType=jks
-Djavax.net.ssl.keyStore=tomcat.keystore
-Djavax.net.ssl.keyStorePassword=tomcat
-Djavax.net.ssl.trustStore=tomcat.keystore
-Djavax.net.ssl.trustStorePassword=tomcat
-Djavax.net.debug=SSL
最后,我将 client.p12 文件复制到我的客户端计算机,并将其导入到 Firefox 的客户端证书中。
第一个问题:当我从 Firefox 访问我的服务的端点(例如 - https://my.server.com:8443/test)时,我得到响应“安全连接失败”。SSL 收到超过最大允许长度的记录。(错误代码:ssl_error_rx_record_too_long)
第二个问题:我真的不想在端口 8443 上运行此连接器。我想在端口 7800(这是我们公司的 HTTPS 标准)上运行它。当我将连接器上的端口更改为 7800 并尝试访问端点(例如 - https://my.server.com:7800/test)时,它永远不会解析页面。
所以,在某个地方我显然错过了一个关键的部分。谁能看到我的错误?
更新:在@Dave G 的反馈之后
运行命令:
openssl s_client -connect localhost:8443 -showcerts
产生以下输出:
CONNECTED(00000003)
140642290976584:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:766:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 263 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---
我还在启动时添加了 -Djavax.net.debug=SSL 。这会在 catalina.out 文件的开头生成以下内容:
trustStore is: tomcat.keystore
trustStore type is : jks
trustStore provider is :
init truststore
adding as trusted cert:
Subject: CN=localhost, OU=unit, O=org, L=Springfield, ST=MO, C=US
Issuer: CN=localhost, OU=unit, O=org, L=Springfield, ST=MO, C=US
Algorithm: RSA; Serial number: 0x5485b5a5
Valid from Mon Dec 08 14:28:53 UTC 2014 until Thu Dec 05 14:28:53 UTC 2024
adding as trusted cert:
Subject: CN=William Jackson, OU=unit, O=org, L=Springfield, ST=MO, C=US
Issuer: CN=William Jackson, OU=unit, O=org, L=Springfield, ST=MO, C=US
Algorithm: RSA; Serial number: 0x5485b6af
Valid from Mon Dec 08 14:33:19 UTC 2014 until Sun Mar 08 14:33:19 UTC 2015
trigger seeding of SecureRandom
done seeding SecureRandom
然后很多:
Ignoring unavailable cipher suite: <suite name>
Ignoring unsupported cipher suite: <suite name>