Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Add certificate from web -> keystore

Thread view: 
genkuro@gmail.com - 28 Jun 2007 19:12 GMT
Hi -

I'm working with a large cluster of hundreds of nodes.  The cluster
occasionally chats with itself using web services, SSL, and self-
signed certificates.

The cluster is built through scripts of course.  And the creation
script must be able to establish communication between the nodes,
preferably over http (versus NFS or some other data sharing
mechanism).

What's the easiest most intuitive way to grab an SSL certificate over
http then add it to the keystore?

I appreciate the help.
Roedy Green - 28 Jun 2007 20:03 GMT
>What's the easiest most intuitive way to grab an SSL certificate over
>http then add it to the keystore?

Read up on JCE to see if there is a  method to do this for you.
see http://mindprod.com/jgloss/jce.html

If the public cert itself is exchanged under some circumstances in an
ordinary browser interaction try getting a copy of Ethereal (see
http://mindprod.com/jgloss/sniffer.html)

and watch the packets going back and forth. Then  mimic that with a
raw socket.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
timjowers - 02 Jul 2007 23:11 GMT
On Jun 28, 2:12 pm, genk...@gmail.com wrote:
> Hi -
>
[quoted text clipped - 11 lines]
>
> I appreciate the help.

Just guessing: (let me know if this helps)

import java.net.*;
import java.io.*;

import javax.net.ssl.HttpsURLConnection;
import javax.security.cert.Certificate;

public class SSLGetCertificateFromWebPager {
   public static void main(String[] args) throws Exception {
       URL site = new URL("https://mail.google.com/mail/");
       HttpsURLConnection conn = (HttpsURLConnection)
site.openConnection();
       conn.setDoOutput(true);
       InputStream istream = conn.getInputStream();
       java.security.cert.Certificate[] aCerts =
conn.getServerCertificates();
       System.out.println( "The certificate is " );
       System.out.println( aCerts[0].toString() );
       System.out.println( "The certificate encoding is " +
aCerts[0].getType() );
       byte[] data = aCerts[0].getEncoded();
       File file = new File( "gmail_downloaded.cer" ); // DER
encoding for instance
       DataOutputStream dos = new DataOutputStream( new
FileOutputStream( file ) );
       dos.write( data );
       dos.close();
       BufferedReader br = new BufferedReader(
                               new InputStreamReader(
                               istream ));
       String line;

       while ((line = br.readLine()) != null)
           System.out.println(line);
       br.close();
   }
}

Best,
TimJowers


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.