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
Solved

problem with jsse?????

Posted on 2002-03-25
4
297 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
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
msterjev earned 125 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

856 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