简体   繁体   English

无法为Java应用程序安装SSL证书

[英]Unable to install SSL certificate for Java app

Am bit similar situation as explained in this question. 有点类似于这个问题中解释的情况。 I also have a WSDL at a particular link. 我在特定链接上也有一个WSDL。 When I open that link I get the There is a problem with this website's security certificate... error in IE. 当我打开该链接时,我得到了There is a problem with this website's security certificate... IE中的错误。 When I click continue it opens up WSDL file. 当我单击继续时,它会打开WSDL文件。

Now I am writing a client for this webservice in Java. 现在我正在用Java编写这个Web服务的客户端。 And it throws following exception: 它抛出以下异常:

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)

So I guess it is related to resolving certificates and since the guy on the said thread got similar exception, I am trying out the solution suggested there - downloading and adding the certificate to the private using keytool.exe , though I really dont think I have completely understood this certificate stuff and also keytool . 所以我猜这与解析证书有关,因为上述线程中的人有类似的异常,我正在尝试解决方案建议 - 下载并使用keytool.exe将证书添加到私有,虽然我真的不认为我有完全理解这个证书的东西,还有keytool

So I 所以我

  • Downloaded the certificate by visiting the link in browser and then copy pasted it in app directory in eclipse. 通过访问浏览器中的链接下载证书,然后将其粘贴到eclipse中的app目录中。
  • Also I copy pasted $JAVA_HOME/lib/security/cacerts to my app directory. 我还将粘贴的$JAVA_HOME/lib/security/cacerts复制到我的app目录。 So by now my app hierarchy looks something like this in eclipse: 所以现在我的app层次结构在eclipse中看起来像这样: 在此输入图像描述
  • Then opened command prompt and navigated to the app directory. 然后打开命令提示符并导航到app目录。
  • Finally executed the command (as suggested in that thread). 最后执行了命令(如该线程中所示)。 It gave me following output. 它给了我以下输出。 It gave me following output 它给了我以下输出 在此输入图像描述

However it is giving me exactly the same exception. 然而它给了我完全相同的例外。 What should I do? 我该怎么办?

Edit 编辑

Well this is my effort to write java client for Exchange Web Services. 这是我为Exchange Web服务编写Java客户端的努力。 Their is ExchangeAuthenticator which manages web services authentication requests to the Exchange and ExchangeDevelopmentTest which contains main method to test functionality of above class. 它们是ExchangeAuthenticator,它管理对Exchange和ExchangeDevelopmentTest的Web服务身份验证请求,其中包含测试上述类功能的主要方法。 a Here is the code: 这是代码:

ExchangeAuthenticator 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 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());
        }
    }
}

The problem is that your certificate is not issued for 172.17.245.196 IP address, so the client used to parse WSDL does not trust it. 问题是您的证书不是为172.17.245.196 IP地址颁发的,因此用于解析WSDL的客户端不信任它。 That IP address shall be in subject field of the certificate. 该IP地址应在证书的主题字段中。

Is your certificate trusted by official certification authority or is it self signed? 您的证书是否受到官方认证机构的信任,或者是否经过自签名? Probably you will need Java to trust it. 可能你需要Java来信任它。 Add it to keystore and then set system properties: 将其添加到密钥库,然后设置系统属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM