Skip to Content
avatar image
Former Member

Server certificate rejected by ChainVerifier


I have written a java program for connecting to an HTTPS URL and get the response from the site.

The HTTPS URL works well when I typed the URL in browser. But the same URL is failing while connecting using my program. I am getting the following exception while connecting to my HTTPS page " Server certificate rejected by ChainVerifier"

I am attaching the code below for your reference.

        String s = new String();
        s = "MyRequest=" + s;

        KeyStore keystore = Utils.getJavaDefaultKeystore();

        /* Giving "SUN version 1.5" as a provider */
        System.out.println("keystore provider:"+keystore.getProvider());

		 FileInputStream fis = new FileInputStream("mycertificatefile");
		 BufferedInputStream bis = new BufferedInputStream(fis);

		 CertificateFactory cf = CertificateFactory.getInstance("X.509");
		 Certificate cert = null;
		 while (bis.available() > 0) {
			cert = cf.generateCertificate(bis);


        SecureConnectionFactory secureconnectionfactory = new SecureConnectionFactory(keystore);
        HttpURLConnection httpurlconnection = secureconnectionfactory.createURLConnection(url);
        BufferedWriter bufferedwriter = new BufferedWriter(new OutputStreamWriter(httpurlconnection.getOutputStream()));
        bufferedwriter.write(s, 0, s.length());
        Utils.setBasicAuthenticationHeader(httpurlconnection, user, password);
        catch(ConnectException connectexception)
            error("Connection timeout");
        catch(Exception exception)
            error("Connection exception");
        int i = httpurlconnection.getResponseCode();
        System.out.println("http Response Code = " + i);

If I pass the setIgnoreServerCertificate(true), then I am getting the following exception Fatal SSL handshake error: java.lang.RuntimeException: Unable to create cipher AES/CBC/NoPadding: Illegal key size

Thanks & Regards,


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    May 03, 2006 at 09:54 AM


    Seems that you have an issue with strong cryptography support in Java. Actually, strong cryptography is subject of US export regulations, so if you downloaded "international" version of Java, then you have only weak cryptography -- small key size.

    Try to obtain JVM that is shiped for US users.


    Add comment
    10|10000 characters needed characters exceeded

    • Former Member


      I am not sure, how far this will solve my problem. Let me try this. BTW, I have solved the issue on my own.

      I generated keystore and truststore from the generated certificates and supplied the certificate as input to my program.

      Here is the program for your reference.

      		 HttpClient client = new HttpClient();
      		 Credentials defaultcreds = new UsernamePasswordCredentials(USER, PASSWORD);
      		 client.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), defaultcreds);
               Protocol authhttps = new Protocol("HTTPS", 
                      (ProtocolSocketFactory) new AuthSSLProtocolSocketFactory(
                              urlkeystore, PASSWORD, 
                              urltruststore, PASSWORD), TARGET_HTTPS_PORT);
               Protocol.registerProtocol("https", authhttps);
      	     PostMethod filePost = new PostMethod(FINAL_URL);
               STATUS = client.executeMethod(filePost);
      	     String responseString = filePost.getResponseBodyAsString();
      	     if (responseString != null && responseString.length() > 0) 
      	    	 System.out.println("Response String : " + responseString);

      Thanks & Regards,


  • avatar image
    Former Member
    Jan 14, 2008 at 07:33 AM


    Have you solved your problem in accessing own ketstore-view, please let me know the solution if you have solved.

    KeyStore keyStore = manager.getKeystore("MYSTORE");

    Caused by: java.rmi.RemoteException: Remote call errored

    Caused by: Application is not authorized to execute keystore operation [

    Caused by: access denied

    Please advice.



    Add comment
    10|10000 characters needed characters exceeded