2011-11-30 209 views
1

因此,我一直试图使用JAX-WS和SSL来设置Java SOAP servlet。我得到了通过SSL运行的实际服务,但我需要它基于客户端证书进行身份验证,现在它正在接受针对它的所有连接。基于SSL和客户端证书的Java SOAP服务

这里是我到目前为止的代码:

TrustManager tm = new X509TrustManager() { 
public void checkClientTrusted(X509Certificate[] chain, 
       String authType) 
       throws CertificateException { 
    System.out.println("yay1"); 
} 



public void checkServerTrusted(X509Certificate[] chain, 
       String authType) 
       throws CertificateException { 
    System.out.println("yay2"); 
} 

public X509Certificate[] getAcceptedIssuers() { 
    throw new UnsupportedOperationException("Not supported yet."); 
} 
}; 


String uri = "http://127.0.0.1:8083/SoapContext/SoapPort"; 
Object implementor = new Main(); 

Endpoint endpoint = Endpoint.create(implementor); 

SSLContext ssl = SSLContext.getInstance("TLS"); 

KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 
KeyStore store = KeyStore.getInstance("JKS"); 

store.load(new FileInputStream("serverkeystore"),"123456".toCharArray()); 

keyFactory.init(store, "123456".toCharArray()); 


TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 

trustFactory.init(store); 


ssl.init(keyFactory.getKeyManagers(), 
new TrustManager[] { tm }, null); 

HttpsConfigurator configurator = new HttpsConfigurator(ssl); 

HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(8083), 8083); 

httpsServer.setHttpsConfigurator(configurator); 

HttpContext httpContext = httpsServer.createContext("/SoapContext/SoapPort"); 

httpsServer.start(); 

endpoint.publish(httpContext); 

而且我有这个PHP代码测试它:

$soapClient = new SoapClient("https://localhost:8083/SoapContext/SoapPort?wsdl", array('local_cert' => "newcert.pem")); 
$soapClient->add(array('i' => '1', 'j' => '2')); 

不幸的是,它的错误了这个时候我包括的local_cert:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://localhost:8083/SoapContext/SoapPort?wsdl' : failed to load external entity "https://localhost:8083/SoapContext/SoapPort?wsdl" 

如果不包含local_cert,它会成功连接,但它永远不会调用我的自定义TrustManager,所以它接受所有传入的连接。

我在做什么错?谢谢!

回答

0

我做不是知道PHP但你的TrustManager在web服务中没有做任何验证。
因此,由于客户端身份验证问题,不应拒绝连接。

您在客户端引用的new_cert.pem是否包含私钥?
如果不是,那么这可能是问题。

我建议你采取wireshark并看到沟通。
我怀疑你不会看到来自服务器的拒绝。

失败应该在您的客户端本地

+0

谢谢,我会尽力的! – user1070690