【问题标题】:Unable to install SSL certificate for Java app无法为 Java 应用安装 SSL 证书
【发布时间】:2013-10-10 06:16:18
【问题描述】:

this 问题中解释的情况有点相似。我在特定链接上也有一个 WSDL。当我打开该链接时,我在 IE 中收到 There is a problem with this website's security certificate... 错误。当我点击继续时,它会打开 WSDL 文件。

现在我正在用 Java 为这个 web 服务编写一个客户端。它会引发以下异常:

Exception in thread "main" com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.

java.io.IOException: Got java.security.cert.CertificateException: No subject alternative names matching IP address 172.17.245.196 found while opening stream from https://172.17.245.196/ews/Services.wsdl
java.io.IOException: Got java.security.cert.CertificateException: No subject alternative names matching IP address 172.17.245.196 found while opening stream from https://172.17.245.196/ews/Services.wsdl?wsdl
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)    
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
    at javax.xml.ws.Service.<init>(Unknown Source)
    at com.microsoft.schemas.exchange.services._2006.messages.ExchangeWebService.<init>(ExchangeWebService.java:58)
    at com.xyz.cms.EWSJavaAPI.ExchangeAuthenticator.getExchangeServicePort(ExchangeAuthenticator.java:32)
    at com.xyz.cms.test.ExchangeDevelopmentTest.main(ExchangeDevelopmentTest.java:31)

所以我想这与解决证书有关,并且由于上述线程上的人遇到了类似的异常,我正在尝试那里建议的解决方案 - 使用 keytool.exe 下载证书并将其添加到私有,尽管我真的不我想我已经完全理解了这个证书的东西,还有keytool

所以我

  • 通过访问浏览器中的链接下载证书,然后将其复制粘贴到eclipse中的app目录中。
  • 我还将粘贴的$JAVA_HOME/lib/security/cacerts 复制到我的应用程序目录中。所以现在我的应用程序层次结构在 Eclipse 中看起来像这样:
  • 然后打开命令提示符并导航到应用程序目录。
  • 最终执行了命令(如该线程中所建议的那样)。它给了我以下输出。它给了我以下输出

但是它给了我完全相同的例外。我该怎么办?

编辑

这是我为 Exchange Web 服务编写 java 客户端的努力。它们是 ExchangeAuthenticator,它管理对 Exchange 和 ExchangeDevelopmentTest 的 Web 服务身份验证请求,其中包含测试上述类功能的主要方法。 a 这里是代码:

ExchangeAuthenticator

public class ExchangeAuthenticator {    
/**
 * Obtains an authenticated ExchangeServicePortType with given credentials.
 *     
 */
    public ExchangeServicePortType getExchangeServicePort(String username, String password, String domain, URL wsdlURL) throws MalformedURLException {
        // Concatinate our domain and username for the UID needed in authentication.
        String uid = "domain" + "\\" + "uname";

        // Create an ExchangeWebService object that uses the supplied WSDL file, wsdlURL.
        ExchangeWebService exchangeWebService = new ExchangeWebService(wsdlURL, new QName("<a href=\"http://schemas.microsoft.com/exchange/services/2006/messages\">http://schemas.microsoft.com/exchange/services/2006/messages</a>", "ExchangeWebService"));
        ExchangeServicePortType port = exchangeWebService.getExchangeWebPort();
        // Supply your username and password when the ExchangeServicePortType is used for binding in the SOAP request.
        ((BindingProvider)port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, uid);
        ((BindingProvider)port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);

        return port;
    }
}

ExchangeDevelopmentTest

public class ExchangeDevelopmentTest {    
    public static void main (String[] args) {
        ExchangeAuthenticator exchangeAuthenticator = new ExchangeAuthenticator();

        // Print statement so we can easily see where our statements start in the Java console.
        System.out.println("Let's get started!");

        try {
            // Create a URL object which points at the .wsdl we deployed in the previous step.
            URL wsdlURL = new URL("https://172.17.245.196/ews/Services.wsdl");
            //URL wsdlURL = new URL("<a href=\"https://172.17.245.196/ews/Services.wsdl\">https://172.17.245.196/ews/Services.wsdl</a>");
            // Call to the class we just created to return an ExchangeServicePortType with authentication credentials.
            ExchangeServicePortType port = exchangeAuthenticator.getExchangeServicePort("uname", "password@123", "domain", wsdlURL);

            // Prints out the default toString() for the ExchangeServicePortType.
            System.out.println(port.toString());
        } catch (MalformedURLException ex) {
            // Catch any errors that may occur.
            Logger.getLogger(ExchangeDevelopmentTest.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println(ex.getMessage()+"\n"+ex.getStackTrace());
        }
    }
}

【问题讨论】:

  • 我认为您忘记告诉您的连接信任新的密钥库。发布您用于获取 wsdl 的代码。
  • here完全相同的问题:是服务器证书不正确(或者你应该使用它的名称,而不是它的IP地址)。
  • @tom 更新问题以包含代码

标签: java eclipse ssl certificate keytool


【解决方案1】:

问题是您的证书不是为 172.17.245.196 IP 地址颁发的,因此用于解析 WSDL 的客户端不信任它。该 IP 地址应在证书的主题字段中。

您的证书是受官方证书颁发机构信任还是自签名?可能您需要 Java 来信任它。将其添加到密钥库,然后设置系统属性:

System.setProperty("javax.net.ssl.keyStore", "lfkeystore2");
System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut");

【讨论】:

  • 你的意思是在命令提示符keytool 输出应该有172.17.245.196SubjectAlternativeName
  • 是的,类型为“IP 地址”而不是“DNSName”。仅当您想使用带有 IP 地址的 URL 时。您当然可以将 URL 与现有的 DNS SAN 一起使用(当然,如果它解析为该 IP 地址)。
  • 哦,但是为什么它不在那里,我的意思是为什么它显示 DNSName 而不是 IP 地址 - 应该怎么做才能做到这一点? - 我可能听起来很愚蠢
  • 当我 ping 到该名称时,它会解析为我在代码中指定的 IP 地址。可以吗?
  • 只是服务器没有配置为使用HTTPS URL的IP地址使用。这是很常见的(也是明智的)。改用它的名字。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-01
  • 2016-08-30
  • 2011-12-27
  • 2014-06-26
  • 2015-08-20
  • 2017-03-05
  • 1970-01-01
相关资源
最近更新 更多