Apache SSL配置之 SSLCertificateChainFile
今天青岛镜像的vip访问SSO-CAS的443端口终于通了,但是发现别的应用连的时候报
错误
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
根据以往的经验,这个错误很明显是不信任服务器端的数字证书引起的,所以我就疑惑了,因为证书使用的是买的证书,且在现在的正式环境上好好的用着。
这个时候我就开始写起测试代码了。
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class SSLTest {
public static void main(String[] args) throws Exception {
URL myURL = new URL("https://xxx.xxx.com");
HttpsURLConnection httpsConn = (HttpsURLConnection) myURL.openConnection();
InputStreamReader insr = new InputStreamReader(httpsConn.getInputStream());
int respInt = insr.read();
while (respInt != -1) {
System.out.print((char) respInt);
respInt = insr.read();
}
}
}
发现连正式环境完全ok,但是当我绑定hosts到青岛的环境的时候就是报错。
这个时候想到两者的差异,正是环境上时直接tomcat的,所以证书什么的直接放在keystore中,然后在tomcat中配置的,但是青岛这边是在apache上配置的ssl,所以差异就在这里。
对对对,keystore中好像还放置了中继的证书,因为我们购买的证书是三级证书。
所以肯定是因为缺少这个中间的证书导致无法认证的。
所以就上网查到了SSLCertificateChainFile这个配置,将中继证书配上去之后,启动,一切OK。
<VirtualHost *:443>
ServerName xxx.xxx.com
JkMountCopy On
SSLProxyEngine on
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /home/admin/web-deploy/conf/ssl/server.crt
SSLCertificateKeyFile /home/admin/web-deploy/conf/ssl/server.key
SSLCertificateChainFile /home/admin/web-deploy/conf/ssl/intermediate.crt
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
</VirtualHost>