Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to pass ssl certificate in java adf

User_BS3NIAug 26 2015 — edited Aug 26 2015

Hi,

I am passing URL through UI and trying to Login to URL with username and password and by passed the SSL using given code but still its not working out Can you please help me out. I am stuck in it from 2 days. Its wokring for simple Core Java but failing in Weblogic when I am passing URL through Form. I am using Jdeveloper 11g Release 1

package assoc.files.view.backing;

import java.io.IOException;

import java.io.OutputStream;

import java.io.PrintStream;

import java.net.Authenticator;

import java.net.InetAddress;

import java.net.MalformedURLException;

import java.net.PasswordAuthentication;

import java.net.URL;

import java.security.KeyManagementException;

import java.security.NoSuchAlgorithmException;

import javax.net.ssl.HttpsURLConnection;

import javax.net.ssl.SSLContext;

import javax.net.ssl.TrustManager;

import javax.net.ssl.X509TrustManager;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.PreparedStatement;

import java.security.cert.X509Certificate;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Calendar;

import java.util.Date;

import java.util.Iterator;

import java.util.logging.Logger;

import javax.net.ssl.HostnameVerifier;

import javax.net.ssl.SSLSession;

import javax.net.ssl.TrustManager;

public  class CustomAuthenticator extends Authenticator {

  

      static {

             disableSSLVerification();

         }

      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) {

              }

          } };

          public void authentication() {

            

            try {

            SSLContext sc = SSLContext.getInstance("SSL");

            sc.init(null, trustAllCerts, new java.security.SecureRandom());

            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); // Sets the authenticator that will be used by the networking code

            // when a proxy or an HTTP server asks for authentication.

              

            Authenticator.setDefault(new  CustomAuthenticator());

            }

           catch (Exception e) {

                        System.out.println(" Error: " + e.getMessage());

                    }

          

          }

        // Called when password authorization is needed

        protected PasswordAuthentication getPasswordAuthentication() {

           System.out.println("checkkkk");

            // Get information about the request

            String prompt = getRequestingPrompt();

            String hostname = getRequestingHost();

            InetAddress ipaddr = getRequestingSite();

            int port = getRequestingPort();

            String username = "export_report";

            String password = "Expo";

            // Return the information (a data holder that is used by Authenticator)

            return new PasswordAuthentication(username,

                                              password.toCharArray());

        }

  //Method used for bypassing SSL verification

      public static void disableSSLVerification() {

          TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

              public java.security.cert.X509Certificate[] getAcceptedIssuers() {

                  return null;

              }

              public void checkClientTrusted(X509Certificate[] certs, String authType) {

              }

              public void checkServerTrusted(X509Certificate[] certs, String authType) {

              }

          } };

          SSLContext sc = null;

          try {

              sc = SSLContext.getInstance("SSL");

              sc.init(null, trustAllCerts, new java.security.SecureRandom());

          } catch (KeyManagementException e) {

              e.printStackTrace();

          } catch (NoSuchAlgorithmException e) {

              e.printStackTrace();

          }

         HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

   HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier() {

   public boolean verify(String urlHostName, SSLSession session) {

   return true;

   }

   } );

          HostnameVerifier allHostsValid = new HostnameVerifier() {

              public boolean verify(String hostname, SSLSession session) {

                  return true;

              }

          };    

          HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);         

      }

}

I am getting following error

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=thawte Primary Root CA - G3,OU=(c) 2008 thawte\, Inc. - For authorized use only,OU=Certification Services Division,O=thawte\, Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=T-TeleSec GlobalRoot Class 3,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=T-TeleSec GlobalRoot Class 2,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=GlobalSign,O=GlobalSign,OU=GlobalSign Root CA - R3". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "OU=Security Communication RootCA2,O=SECOM Trust Systems CO.\,LTD.,C=JP". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=VeriSign Universal Root Certification Authority,OU=(c) 2008 VeriSign\, Inc. - For authorized use only,OU=VeriSign Trust Network,O=VeriSign\, Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=KEYNECTIS ROOT CA,OU=ROOT,O=KEYNECTIS,C=FR". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

<Aug 26, 2015 12:43:20 PM IST> <Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=GeoTrust Primary Certification Authority - G3,OU=(c) 2008 GeoTrust Inc. - For authorized use only,O=GeoTrust Inc.,C=US". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>

I/O Error: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable certificate was received

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2015
Added on Aug 26 2015
6 comments
1,071 views