Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem with jsse?????

Posted on 2002-03-25
4
Medium Priority
?
301 Views
Last Modified: 2010-03-31
can somebody provide a sample code for establishing a HTTPURLconnection with a server using jsse.i need to capture the sesssion id's and cookies as well.As i am working with jsse for the first time i am not sure how the to initialise the values for trust manager and key manager.I don't want a thrid party  tool.i want the SUN jsse implementation...
0
Comment
Question by:anuj_roy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
msterjev earned 250 total points
ID: 6894853
Establishing HttpsURLConnection is the same as HttpURLConnection (with proper cast).So, the problem isn't the code. You must specify some system properties.First at all you need to specify https protocol handler class. In the Sun's implementation you must start you java interpreter with the System property:

-Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol. As always,the server will present its certificate to the client, which must verify it using its trustore. In this case, we can use the default trustore $JREHOME/lib/security/cacerts.Also, you can set system property javax.net.ssl.trustStore to your own trustore. The same is valid for keystore. The system property is javax.net.ssl.keyStore. In order to establish connection this way, the server's name in the URL must be the same with the server name in it's certificate. If you want to avoid this constraint you must write implementation of interface HostnameVerifier. You can contact me for further examples of HttpsURLConnection and row SSL socket communication.
0
 

Author Comment

by:anuj_roy
ID: 6895641
thanx for the reply ,but i have a problem when i am initialising SSLContext ,i have to pass keystore and Truststore values dynamically .i can't put it in the system properties.SO how to do that from the code.that in the constructor of SSLContext when i am passing this values i am  at present initialising it with null and passing it.is it fine or just tell me how to initialise it properly using sun's JSSE.
0
 
LVL 3

Expert Comment

by:msterjev
ID: 6895702
private boolean initializeSSL()
     {
          String sslProvider;
          String keyStore;
          String sslVer;
          String certType;
          String storeType;
          String storePass;
          char[] storePassChars=null;
          SSLContext sslcxt;
          KeyManagerFactory kmf;
          KeyStore ks;
         
          Properties sslconfig=null;
          try
          {
               sslconfig=new Properties();
               sslconfig.load(new FileInputStream("sslconfig.properties"));
          }
          catch(Exception e)
          {
               showException(e);
               System.exit(1);
          }
          try
          {
               sslProvider=sslconfig.getProperty("sslProvider");
               if(sslProvider==null) sslProvider="SunJSSE";
               keyStore=sslconfig.getProperty("keyStore");
               if(keyStore==null) keyStore="mystore";
               sslVer=sslconfig.getProperty("sslVer");
               if(sslVer==null) sslVer="SSL";
               certType=sslconfig.getProperty("certType");
               if(certType==null) certType="SunX509";
               storeType=sslconfig.getProperty("storeType");
               if(storeType==null) storeType="JKS";
               storePass=sslconfig.getProperty("storePass");
               if(storePass!=null)
               {
                    storePassChars=new char[storePass.length()];
                    storePass.getChars(0,storePass.length(),storePassChars,0);
               }
               sslcxt=SSLContext.getInstance(sslVer,sslProvider);
               kmf=KeyManagerFactory.getInstance(certType,sslProvider);
               ks=KeyStore.getInstance(storeType);
               ks.load(new FileInputStream(keyStore),storePassChars);
               kmf.init(ks,storePassChars);
               sslcxt.init(kmf.getKeyManagers(),null,new SecureRandom());
               sslServerSocketFactory=(SSLServerSocketFactory)sslcxt.getServerSocketFactory();
               System.out.println("SSL Server Socket Factory created.");                            
               return true;          
          }catch(Exception e)
          {
               e.printStackTrace();
               return false;
          }
     }
0
 

Author Comment

by:anuj_roy
ID: 6895845
thanx a lot for the reply i will try this out...i want one more help ,i want to get the session id using the http url connection.can u tell me how to go about it????
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question