© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

Authentication of user using SSL Certificate Using Java

Description:

While SSL provides authentication, privacy, and data integrity, it does not provide non-repudiation services.This program is to authenticate the user using SSL cerficate. The user has to give the SSL certificate as input for authentication.Using the FileByte class, it reads the file and the validity period of a certificate is checked using checkValidity(). If it is a valid certificate, its details are stored as public keys for further communication of the user.

Authentication of user using SSL Certificate Using Java :

/*FileByte.java*/ import java.io.*; /** * * @author student */ public class FileByte implements Serializable { private byte by[]; /** Creates a new instance of FileByte */ public FileByte() { } public void setByte(byte a[]) { by=a; } public byte[] getByte(){ return by; } } /* Main_Server*/ import java.io.*; import java.net.*; import java.util.*; import java.security.cert.*; import java.security.*; import java.sql.*; public class Main_Server { public static void main(String a[]){ String response = null; PublicKey publicKey=null; String host=""; String sender_host="localhost"; String fd = "cert"; if(fd.equals("cert")) { System.out.println("Server inside Certificate Processing.."); try{ FileInputStream fi = new FileInputStream("D:/adhoc.cer"); byte[] bytes=new byte[fi.available()]; fi.read(bytes); FileByte fby=new FileByte(); fby.setByte(bytes); String fname = "adhoc.cer"; byte byt[]=fby.getByte(); try { FileOutputStream fos= new FileOutputStream("F:/key/publickeys/"+fname); fos.write(byt); fos.flush(); fos.close(); System.out.println("Certificate File stored in Publickey Folder"); System.out.println("Stored Certificate Name :"+fname); InputStream inStream = new FileInputStream("F:/key/publickeys/"+fname); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream); inStream.close(); Properties publickeys = new Properties(); try { System.out.println("Certificate validation start..."); cert.checkValidity(); System.out.println("Certificate validation stop..."); //System.out.println("Key :"+host); System.out.println("Value :"+fname+".cer"); FileOutputStream fo = new FileOutputStream("F:/key/publickeys/pkeys.properties"); publickeys.setProperty(sender_host,fname); publickeys.store(fo,"public certs"); fo.close(); System.out.println(); response = "valid cerfificate"; // System.out.println("One Certificate File Recieved"); }catch(CertificateExpiredException e){ response = "expired certificate"; //System.out.println("One Certificate File Recieved"); FileOutputStream fo = new FileOutputStream("F:/key/publickeys/pkeys.properties"); publickeys.setProperty(sender_host,fname); publickeys.store(fo,"public certs"); fo.close(); } catch(CertificateNotYetValidException e){ response = "not yet valid certificate"; } catch( Exception e){ e.printStackTrace(); } System.out.println(response); }catch(Exception e){ e.printStackTrace(); } }catch(Exception e){ e.printStackTrace(); } } }//end of main }

Sample ScreenShot:

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom