none
[E2010] [EWS Java API 1.1][JAVA] - How to use Certificate for HTTPS connection. RRS feed

  • Question

  • Hi All,

    I am trying to connect to Exchange Server 2010 using EWS Java API. For testing the application, I used the certificate code described in the "Getting Started" document.

    // The trust all certs.
    private static TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager()
    {
    public java.security.cert.X509Certificate[] getAcceptedIssuers()
      	{
    		return null;
      	}
    
    public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String    authType) 
    {
    }
    
    public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) 
    {
    }
    };
    
    // Java Secure Socket Connection 
    private static HostnameVerifier hv = new HostnameVerifier() 
    {
    @Override
    	public boolean verify(String urlHostName, SSLSession session) 
    {
    		return true;
    	}
    };
    
    //Sets the ssl config.
    private static void setSSLConfig() throws Exception 
    {
       SSLContext context = SSLContext.getInstance("SSL");
       context.init(null, trustAllCerts, new java.security.SecureRandom());
       HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
       HttpsURLConnection.setDefaultHostnameVerifier(hv);
    }
    

    Now I am trying to use use a certificate. I did the following steps for that.

    I imported the certificate into the keystore.

    Set 2 system properties in the application, the path to the keystore and the password.

    -Djavax.net.ssl.trustStore=C:\\Java\\jdk1.5.0_15\\jre\\lib\\security\\cacerts -Djavax.net.ssl.trustStorePassword=changeit

     

    Even after setting this arguments, I am getting an exception.

    Exception in thread "main" microsoft.exchange.webservices.data.EWSHttpException : Unable to get response codejavax.net.ssl.SSLHandshakeException : java.security.cert.CertificateException : No subject alternative names matching IP address 10.192.17.124 found

          at microsoft.exchange.webservices.data.HttpNativeWebRequest.getResponseCode(Unknown Source)

          at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)

          at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)

          at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)

          at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)

          at microsoft.exchange.webservices.data.ExchangeService.bindToFolder(Unknown Source)

          at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)

          at microsoft.exchange.webservices.data.Folder.bind(Unknown Source)

          at test.TestFolder.main( TestFolder.java:82 )

    Please help me with this exception.

    Thanks,

    Paul

    Monday, January 10, 2011 7:12 AM

Answers

  • It was a problem with the Exchange Server certificate, I was using.

    For more details on the error, check "http://www.jroller.com/hasant/entry/no_subject_alternative_names_matching".

    Instead of using the IP in the URL, I used the Domain Name and it started working fine.

    Thanks,

    Paul

    Monday, January 10, 2011 1:06 PM

All replies