现在问题是客户端连接服务器得时候报 No trusted certificate found 问题
客户端添加证书的代码(这段代码是cxf 官方提供的demo里面的) :
String contextPath = "./certs"; System.out.println("contextPath=" + contextPath); HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port)
.getConduit(); TLSClientParameters tlsCP = new TLSClientParameters(); // 服务器证书库
String keyPassword = "password";
KeyStore keyStore = KeyStore.getInstance("JKS");
String keyStoreLoc = contextPath + "/wibble.jks";
keyStore.load(new FileInputStream(keyStoreLoc),
keyPassword.toCharArray());
KeyManager[] myKeyManagers = getKeyManagers(keyStore, keyPassword);
tlsCP.setKeyManagers(myKeyManagers); // 证书信任库
KeyStore trustStore = KeyStore.getInstance("JKS");
String trustStoreLoc = contextPath + "/truststore.jks";
trustStore.load(new FileInputStream(trustStoreLoc),
keyPassword.toCharArray());
TrustManager[] myTrustStoreKeyManagers = getTrustManagers(trustStore);
tlsCP.setTrustManagers(myTrustStoreKeyManagers); // The following is not recommended and would not be done in a
// prodcution environment,
// this is just for illustrative purpose
tlsCP.setDisableCNCheck(true); httpConduit.setTlsClientParameters(tlsCP);
里面的证书也是官方例子里面提供的脚本生成的,现在报 No trusted certificate found
查看了两个证书多是有的,不知道问题在哪里
客户端添加证书的代码(这段代码是cxf 官方提供的demo里面的) :
String contextPath = "./certs"; System.out.println("contextPath=" + contextPath); HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port)
.getConduit(); TLSClientParameters tlsCP = new TLSClientParameters(); // 服务器证书库
String keyPassword = "password";
KeyStore keyStore = KeyStore.getInstance("JKS");
String keyStoreLoc = contextPath + "/wibble.jks";
keyStore.load(new FileInputStream(keyStoreLoc),
keyPassword.toCharArray());
KeyManager[] myKeyManagers = getKeyManagers(keyStore, keyPassword);
tlsCP.setKeyManagers(myKeyManagers); // 证书信任库
KeyStore trustStore = KeyStore.getInstance("JKS");
String trustStoreLoc = contextPath + "/truststore.jks";
trustStore.load(new FileInputStream(trustStoreLoc),
keyPassword.toCharArray());
TrustManager[] myTrustStoreKeyManagers = getTrustManagers(trustStore);
tlsCP.setTrustManagers(myTrustStoreKeyManagers); // The following is not recommended and would not be done in a
// prodcution environment,
// this is just for illustrative purpose
tlsCP.setDisableCNCheck(true); httpConduit.setTlsClientParameters(tlsCP);
里面的证书也是官方例子里面提供的脚本生成的,现在报 No trusted certificate found
查看了两个证书多是有的,不知道问题在哪里
路径已经检查过了没有问题,格式是通过cxf自带的脚本
生成的
1,key 有没有问题
2,key的domain和service domain 是否一样。
这个问题多半是你客户端的trustStore没有包含web service端的keystore的证书导致。
你可以用以下步骤试一下:
1,找到web service端的keystore文件。
keytool -export -alias ${web service端的keystore的别名} -file server.crt -keystore ${web service端的keystore}
2,把上面导出来的正如导入到你的
keytool -import -file server.crt -keystore truststore.jks -trustcacerts -alias clientAlias
其中这里的【clientAlias】可以随便起,只要不和truststore.jks已有的别名重复便可如何还是不行,可能就需要用相同的步骤把你客户端的keyStore的正如导入到web service端trustStore里面
2.客户端要有信任证书(B, 其中:A是B签发的,或A=B)
浏览器客户端: 直接在浏览器安装证书加入到信任区域;
java客户端 在javahome\bin\lib\sercuit\cacerts中安装信任证书;
另外A的DN要与A的SDN一样; 注意以上几点,就没什么问题
keytool -import -v -noprompt -alias client_keystore -file $jksPath/client.chain -keystore $jksPath/client_keystore.jks -storepass $password
这样仓库里面的就是认证过的证书和ca证书,不然直接导入认证好的证书是要报错的。