【问题标题】:Java SOAP service over SSL with client certificates带有客户端证书的基于 SSL 的 Java SOAP 服务
【发布时间】:2012-01-10 02:59:56
【问题描述】:

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

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

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,因此它接受所有传入连接。

我做错了什么?谢谢!

【问题讨论】:

    标签: java php soap ssl jax-ws


    【解决方案1】:

    了解 PHP,但您在 Web 服务中的 TrustManager 没有进行任何身份验证。
    因此,不应由于客户端身份验证问题而拒绝连接。

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

    我建议你拿个wireshark看看通讯。
    我怀疑您不会看到来自您的服务器的拒绝。

    故障应该在您的客户端本地

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 2021-08-05
      • 2013-10-18
      相关资源
      最近更新 更多