Ask Users Before Rejecting X509 Certificate

This tip implements a X509TrustManager that asks clients before it rejects a certificate chain. The keystore used is just an example? you can adapt it for any other keystore:

import*;import*;import*;import*;import*;import*;import java.awt.*;import java.awt.event.*;class X509TrustManagerDialog implements ActionListener{Button accept=new Button("ACCEPT");Button reject=new Button("REJECT");Label label1=new Label("A X.509 certificate was rejected to the standard verification...");Label label2=new Label("Accept / Reject this certificate ?");Dialog t=null;public X509TrustManagerDialog()  {  t=new Dialog(new Frame());       t.setSize(400,100);  t.setLocation(50,50);  t.setModal(true);  t.setResizable(false);  t.setLayout(new FlowLayout());  t.add(label1);t.add(label2);t.add(accept);t.add(reject);      accept.addActionListener(this);  reject.addActionListener(this);      t.setVisible(true);         }  public void actionPerformed(ActionEvent e)    {    if((e.getActionCommand()).equals("ACCEPT"))           {           t.setVisible(false);           return;           }               if((e.getActionCommand()).equals("REJECT"))           System.exit(1);    }}class QueryX509TrustManager implements X509TrustManager{X509TrustManager X509TM=null;          //default X.509 TrustManagerTrustManagerFactory ClientTMF=null;    //SunX509 factory from SunJSSE providerKeyStore ClientKS=null;                //keystore SSLCert - just an example TrustManager[] ClientTMs=null;         //all the TrustManagers from SunX509 factorychar[] ClientKeystorePassword="Varonmykey".toCharArray();//SSLCert access password    //QueryX509TrustManager constructor    public QueryX509TrustManager(){            //get an KeyStore object of type JKS (default type)    try{       ClientKS=KeyStore.getInstance("JKS");       }catch( e)        {System.out.println("1: "+e.getMessage());}    //loading SSLCert keystore    try{       ClientKS.load(new FileInputStream("SSLKeystore"),ClientKeystorePassword);       }catch( e)          {System.out.println("2: "+e.getMessage());       }catch( e)          {System.out.println("3: "+e.getMessage());       }catch( e)          {System.out.println("4: "+e.getMessage());}              //TrustManagerFactory of SunJSSE    try{       ClientTMF=TrustManagerFactory.getInstance("SunX509","SunJSSE");       }catch( e)          {System.out.println("5: "+e.getMessage());       }catch( e)          {System.out.println("6: "+e.getMessage());}    //call init method for ClientTMF    try{       ClientTMF.init(ClientKS);       }catch( e)          {System.out.println("7: "+e.getMessage());}    //get all the TrustManagers    ClientTMs=ClientTMF.getTrustManagers();        //looking for a X509TrustManager instance    for(int i=0;i
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

Top 5 B2B SaaS Marketing Agencies for 2023

In recent years, the software-as-a-service (SaaS) sector has experienced exponential growth as more and more companies choose cloud-based solutions. Any SaaS company hoping to stay ahead of the curve in this quickly changing industry needs to invest in effective marketing. So selecting the best marketing agency can mean the difference

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.