Google

Monday, April 2, 2007

Dummny certificate authentication implementation

Certificates is one of the way of Authorization/Authentication while implementing SSL based authentication. When browser accesses any web based application which has certificates implemented to authenticate user, browser is asked to validate certificate if it has, or accept certificate for a session or temporary. Browser knows this behavior and knows how to respond or deal with it.

When we access web based system through program program looks at a fixed set of locations (depends on language that you are using) for certificates; and if it does not find it throws an exception. This all happens while creating a socket connection with web application.

In case of Java, It uses javax.net.ssl.SSLSocketFactory to create socket connection. That class asks to javax.net.ssl.X509TrustManager instance for certificate validation.
X509TrustManager searches for certificate into JAVA_HOME/jre/lib/security/certs file which is collection of certificates. If it does not find it then it throws an exception.

One option to deal with this is, Find out which all web applications will your program use and using keytool add certificates for those web applications into JAVA_HOME/jre/lib/security/certs file. But that is hard coding in some sense. If you want your application to use some other web application which also has certificate authentication, then administrator will have to do that for you. You can also write a java code for that but which again is lots of coding that programmer has to do.

There is one more approach which will make programmers work easy. It is DummyCertificate approach. In this case we will create dummy certificate validate which will validate all certificates. To implement it in Java programmer will have to write two classesDummySSLSocketFactory and DummyTrustManager.

DummySSLSocketFactory will be used for creating sockets and DummyTrustManager
will be used for certificate validation which will return true for any
certificate it is asked to validate.

We will need to ask java to use DummySSLSocketFactory to create sockets which will ask DummyTrustManager to validate certificate. There are two ways one can do so. One is to edit JAVA_HOME\jre\lib\security\java.security.Security file. Find ssl.ServerSocketFactory.provider in that file and specify there fully classified class name of DummySSLSocketFactory. One can also do this programmatically. java.security.Security class has a static method setProperty. using that you can ask java to use DummySSLSocketFactory to create sockets.
Ex: Security.setProperty("ssl.SocketFactory.provider", com.persistent.DummySSLSocketFactory);

DummySSLSocketFactory implementation asks DummyTrustManager to validate certificates which will validate all certificates and will return true for all certificates.

So this is how one can deal with certificate validation issue through programs.

Code for DummySSLSocketFactory and DummyTrustManager. These code are tested against JavaMail 1.4 and JDK 1.5.

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.Security;
import javax.net.SocketFactory;
import javax.net.ssl.*;

public class DummySSLSocketFactory extends SSLSocketFactory {
private SSLSocketFactory factory;

public DummySSLSocketFactory() {
try {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null,
new TrustManager[] { new DummyTrustManager()},
null);
factory = (SSLSocketFactory)sslcontext.getSocketFactory();
} catch(Exception ex) {
// ignore
}
}

public static SocketFactory getDefault() {
return new DummySSLSocketFactory();
}

public Socket createSocket(Socket socket, String s, int i, boolean flag)
throws IOException {
return factory.createSocket(socket, s, i, flag);
}

public Socket createSocket(InetAddress inaddr, int i,
InetAddress inaddr1, int j) throws IOException {
return factory.createSocket(inaddr, i, inaddr1, j);
}

public Socket createSocket(InetAddress inaddr, int i)
throws IOException {
return factory.createSocket(inaddr, i);
}

public Socket createSocket(String s, int i, InetAddress inaddr, int j)
throws IOException {
return factory.createSocket(s, i, inaddr, j);
}

public Socket createSocket(String s, int i) throws IOException {
return factory.createSocket(s, i);
}

public String[] getDefaultCipherSuites() {
return factory.getDefaultCipherSuites();
}
public Socket createSocket() throws IOException {
System.out.println( "createSocket 0");
return factory.createSocket();
}
public String[] getSupportedCipherSuites() {
return factory.getSupportedCipherSuites();
}
}

import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;

public class DummyTrustManager implements X509TrustManager {

public void checkClientTrusted(X509Certificate[] cert, String authType) {
}

public void checkServerTrusted(X509Certificate[] cert, String authType) {
}

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
If you find any issues please feel free to ping on thakkar.kiran@gmail.com

Labels: , ,

74 Comments:

At November 9, 2009 at 5:24 AM , Anonymous Anonymous said...

viagra reviews viagra for sale without a prescription buy cheap viagra online cialis viagra viagra attorneys viagra and cocaine viagra 6 free samples viagra generic cheap viagra walmart can viagra causes legs to ache viagra pills viagra for sale without a prescription viagra suppliers cheapest uk supplier viagra

 
At December 10, 2009 at 1:46 PM , Anonymous Anonymous said...

Curious question

 
At December 30, 2009 at 11:25 PM , Anonymous Anonymous said...

The remarkable answer :)

 
At February 2, 2010 at 5:38 AM , Anonymous Anonymous said...

Good post and this fill someone in on helped me alot in my college assignement. Gratefulness you for your information.

 
At February 7, 2010 at 10:00 PM , Anonymous Anonymous said...

Opulently I agree but I think the list inform should acquire more info then it has.

 
At December 6, 2010 at 3:41 AM , Anonymous EV SSL Certificates said...

Very informative blog, that is good from the website point of view. I am greatfull to read it.

 
At November 17, 2012 at 10:19 AM , Anonymous Anonymous said...

xanax no prescription xanax recreational use alcohol - how much xanax and alcohol to die

 
At January 8, 2013 at 3:15 PM , Anonymous Anonymous said...

burberry outlet jhxmwz rzqr burberry outlet yadeyc cfas burberry sale online uhaoul sqtw uggs uk pyuowg wmfw ugg sale ohpmhd lzdz http://www.2lv6.com phvxyw jhmm ugg factory outlet vavyah kbph ugg boots cheap wjckpa nhja http://www.jg20.com aqucri suyd michael kors online outlet ymaksk wbjk michael kors 2013 vcqhus natv longchamp outlet tekswm zrga longchamp bags on sale fbdjud wxwt longchamp bag ialtog nsrr burberry diaper bag hpaxez pscy

 
At January 10, 2013 at 10:09 AM , Anonymous Anonymous said...

www.bulberryfashion2013.com cldjtk tidd burberry sale bhqzka lgrh www.livebulberryfashion.com rueivm puqy uggs outlet fsrais qctm ugg outlet store ngmaxs rrow ugg outlet online vwiaif iuly ugg boots cheap xqmefm dlzm ugg sale uuqlfp zhne michael kors handbags outlet fvjsod uhrn http://www.02s8.com awenvf tcwk http://www.1qpf.com fgiark irvp longchamp outlet xlsgmr msmq longchamp sale ocqhvk tnct longchamp handbags sale rdikbr snbx http://www.e4ni.com zgpwsk jxce

 
At January 10, 2013 at 2:25 PM , Anonymous Anonymous said...

burberry outlet krkctn mkwy www.fashionbulberryoutlet.com yeapkc ssyn www.livebulberryfashion.com gepvfq ozbo uggs sale cxqgru gygz ugg outlet online dakfuo gbil ugg on sale asneii zmrj ugg boots outlet bdajvi xwug ugg sale djnzxn qjyu michael kors outlet nukjpb ewka michael kors online outlet tgxntj faxh michael kors outlet daqwot eumw longchamp outlet online zvkvcz qvrz longchamp bags on sale tyuocg bhbv longchamp diaper bag dskqjg cmgh burberry outlet gzlryx qiym

 
At January 10, 2013 at 4:47 PM , Anonymous Anonymous said...

burberry handbags ofnkve xupn www.fashionbulberryoutlet.com yqmzuq hrni burberry outlet ixtxkk ajwz ugg uk jkjoke xlkj ugg outlet online sale kbopmr qhrh ugg boots sale waootv qzcw ugg boots cheap vngmma kahs ugg boots outlet aqksvp yffl michael kors outlet ymacbm pkjv http://www.02s8.com vvupov icjc michael kors 2013 ikjbcp fgkg longchamp outlet cnjgdm mamy longchamp tote lkmtpj bnjn longchamp handbags libjcf spaw burberry outlet online xfrvxl fqhb

 
At January 10, 2013 at 10:04 PM , Anonymous Anonymous said...

www.bulberryfashion2013.com qdwyuk lnry burberry fnibxs kiur burberry outlet ergndq uwid www.specjerseys.com rhogkc duna www.numbjerseys.com rzopmp ysyd http://www.2lv6.com alaqye wlmv ugg boots outlet oamizx khlx http://www.7jcu.com zpsuha rxfd michael kors outlet qejgjr gggb michael kors online outlet dkpbbo wgyu michael kors 2012 rmjxlf wbjv longchamp outlet store acbfvu dlkx http://www.9dcu.com dsibpz fmvc longchamp handbags sale ljymxq bipv burberry diaper bag wcwvit zgae

 
At January 11, 2013 at 12:07 AM , Anonymous Anonymous said...

burberry handbags jqfkst sfnl www.fashionbulberryoutlet.com gyyfin juup burberry outlet online aucbwr igwz uggs uk wmsluk xncf ugg outlet store twemky tpbp http://www.2lv6.com ohkqch ntxs ugg boots outlet xtraza rvte ugg on sale psucay fwgx michael kors online outlet nxpesm rdfj michael kors online outlet aikiup zvzq michael kors outlet gtmcka wgdr longchamp on sale mfzknw xwrh longchamp outlet biegji zwqw http://www.dtr6.com vumnvw mnhk burberry outlet guwlnq ajwd

 
At January 11, 2013 at 2:10 AM , Anonymous Anonymous said...

burberry lkwnae mcdy burberry sale ujeebq dold www.livebulberryfashion.com uyzhrz fram ugg boots qidtrf vqlo www.numbjerseys.com ebvtzy eeee ugg boots sale uvovkt etnh ugg discount bgvmst jiin ugg on sale ovxkfc nzkv http://www.jg20.com ykrkgx uogg michael kors 2013 uqzhjz vkne michael kors factory outlet fibgkc zdoq longchamp handbags sale ptdjgs gyvb longchamp sale wgutra dgkw longchamp handbags sale osnwwm cusw http://www.e4ni.com fqxerz jnwd

 
At January 11, 2013 at 6:48 AM , Anonymous Anonymous said...

burberry ujjfau rdfu burberry uk iitwwu cxvs www.livebulberryfashion.com utjccr sjjc uggs sale refqjk kiuq ugg boots bhvqbg vgzr ugg boots sale aixkoq dvht ugg boots cheap oaujtm wwkj ugg boots cheap mcjfdm qflm michael kors online outlet ksahal onbn michael kors tote ikubtw vnlk michael kors diaper bag eadolt uffy longchamp on sale yceqxg mwzl longchamp tote gvblgb jwqs longchamp bag lwxtjc btcg burberry outlet tdsasr szec

 
At January 12, 2013 at 10:06 AM , Anonymous Anonymous said...

viagra online viagra xanax combination - viagra online manchester

 
At January 14, 2013 at 2:57 AM , Anonymous Anonymous said...

www.bulberryfashion2013.com qdpyaj xsjp burberry outlet cithay rjrb www.livebulberryfashion.com fqebav exxs www.specjerseys.com uacvgv mtrp ugg outlet store wixlgi thnf ugg boots sale iabstj nchg ugg outlet kvixco dlxy ugg on sale kgcncw ztcx michael kors outlet jsvlxz mjij michael kors handbags rtycet yzra michael kors flats bkwgnx qchk longchamp outlet vzwhfv iaab longchamp sale znecol byee longchamp bag gvchbb zejt http://www.e4ni.com xxuqip ozxf

 
At January 14, 2013 at 9:33 AM , Anonymous Anonymous said...

burberry bags bqdwtk stww burberry uk yganrq qryl burberry outlet store yleogy hosv www.specjerseys.com rqiqyo ykfz ugg boots outlet jqbxir lyrp ugg boots sale icgjro upfn ugg discount guleul zxer ugg usa cyhfop rzef michael kors outlet store nyueby hhac michael kors handbags favhit ftcb michael kors outlet jquuhg xiti longchamp outlet tzhycz fpks longchamp bags on sale gefhaw dllx longchamp handbags sale ovcydm pisv burberry outlet vraurf kzlr

 
At January 26, 2013 at 11:52 AM , Anonymous Anonymous said...

cheap generic viagra buy viagra online from us - is it legal to order viagra online in australia

 
At February 1, 2013 at 1:16 AM , Anonymous Anonymous said...

tramadol online tramadol yeast infection - tramadol 100mg overnight

 
At February 1, 2013 at 10:21 PM , Blogger johnywalker said...

Hi!

Great post like this must be highly recommended. It is so nice to read such wonderful blog. Thanks

Certificate Authentication

 
At February 5, 2013 at 4:36 PM , Anonymous Anonymous said...

buy soma online soma san diego side stage - soma bloomington

 
At February 6, 2013 at 1:35 PM , Anonymous Anonymous said...

buy soma buy aura soma australia - cheap somatropin sale

 
At February 8, 2013 at 5:17 AM , Anonymous Anonymous said...

soma drug buy soma florida - buy somatropin pill form

 
At February 8, 2013 at 6:14 PM , Anonymous Anonymous said...

soma pills soma watson brand 350 mg 90 tabs - soma pills cost

 
At February 9, 2013 at 9:16 AM , Anonymous Anonymous said...

soma online soma order status - buy soma online usa

 
At February 10, 2013 at 1:00 PM , Anonymous Anonymous said...

buy tramadol cod overnight buy tramadol cod fedex - where to buy tramadol online safely

 
At February 12, 2013 at 12:10 AM , Anonymous Anonymous said...

F-tag 329 Unnecessary Medications cipro 500mg - buy cipro no prescription http://www.cheapcipromed.net/#buy-cipro-no-prescription , [url=http://www.cheapcipromed.net/#cipro-for-sale-online ]cipro for sale online [/url]

 
At February 12, 2013 at 1:23 AM , Anonymous Anonymous said...

Feline Medications Anxiety generic propecia no prescription - cheap propecia no prescription http://www.propeciahowtosave.net/#cheap-propecia-no-prescription , [url=http://www.propeciahowtosave.net/#where-to-buy-finasteride-online ]where to buy finasteride online [/url]

 
At February 12, 2013 at 1:57 PM , Anonymous Anonymous said...

buy tramadol online tramadol buy online no prescription mastercard - tramadol urinary retention

 
At February 12, 2013 at 3:40 PM , Anonymous Anonymous said...

Blogger: Kiran Thakkar's Blog - Post a Comment order celebrex - celecoxib no prescription http://www.celebrexgenericsale.net/#celecoxib-no-prescription , [url=http://www.celebrexgenericsale.net/#cheap-celebrex-online ]cheap celebrex online [/url]

 
At February 12, 2013 at 6:49 PM , Anonymous Anonymous said...

buy tramadol tramadol ultram eq 50mg - what does tramadol 50 mg look like

 
At February 13, 2013 at 8:14 PM , Anonymous Anonymous said...

buy cialis online cheap order generic cialis in usa - cialis daily vs cialis 36 hour

 
At February 14, 2013 at 4:57 AM , Anonymous Anonymous said...

tramadol online pharmacy 100mg tramadol vs percocet - tramadol 100mg capsules

 
At February 17, 2013 at 9:15 AM , Anonymous Anonymous said...

tmd generic plavix for sale - buy cheap plavix online http://www.plavixbuynow.net/#plavix-drug, [url=http://www.plavixbuynow.net/#plavix-drug]clopidogrel for sale online [/url]

 
At February 18, 2013 at 2:18 AM , Anonymous Anonymous said...

sob gabapentin online - buy neurontin no prescription http://www.neurontinonlinesales.net/#buy-neurontin-no-prescription , [url=http://www.neurontinonlinesales.net/#buy-gabapentin-online-no-prescription ]buy gabapentin online no prescription [/url]

 
At February 21, 2013 at 2:50 PM , Anonymous Anonymous said...

xanax 1mg xanax joint pain - 3mg xanax online

 
At February 21, 2013 at 7:51 PM , Anonymous Anonymous said...

buy tramadol tramadol 50 mg vs percocet - cheap tramadol no prescription

 
At February 22, 2013 at 9:48 AM , Anonymous Anonymous said...

cheap alprazolam best place buy alprazolam - xanax 1 mg at a time

 
At February 22, 2013 at 11:23 AM , Anonymous Anonymous said...

generic xanax xanax overdose in children - xanax weight loss

 
At February 22, 2013 at 11:41 AM , Anonymous Anonymous said...

Hello, generic atorvastatin - purchase lipitor http://www.lipitoronlinesale.com/#purchase-lipitor , buy generic lipitor online

 
At February 22, 2013 at 2:48 PM , Anonymous Anonymous said...

xanax online pills that look like xanax - xanax online consultation

 
At February 26, 2013 at 7:58 PM , Anonymous Anonymous said...


3 discount cymbalta - cymbalta no prescription needed http://www.cymbaltaonlinerx.net/#discount-cymbalta, [url=http://www.cymbaltaonlinerx.net/#discount-cymbalta]discount cymbalta[/url]

 
At February 26, 2013 at 11:01 PM , Anonymous Anonymous said...

buy tramadol online cod overnight tramadol 50 mg kaps - tramadol hydrochloride 50mg side effects

 
At March 1, 2013 at 9:47 AM , Anonymous Anonymous said...

cialis online buy cialis online usa no prescription - reviews on cialis 10mg

 
At March 5, 2013 at 2:56 PM , Anonymous Anonymous said...

20000 :) celebrex without prescription - celebrex online no prescription http://www.celebrexpharmsite.net/, [url=http://www.celebrexpharmsite.net/]generic for celebrex [/url]

 
At March 5, 2013 at 8:51 PM , Anonymous Anonymous said...

http://landvoicelearning.com/#74967 buy tramadol visa - tramadol 50 mg good

 
At March 6, 2013 at 11:47 AM , Anonymous Anonymous said...

http://landvoicelearning.com/#57594 tramadol withdrawal dogs - tramadol 50mg information

 
At March 6, 2013 at 9:38 PM , Anonymous Anonymous said...

http://buytramadolonlinecool.com/#30694 side effects for tramadol 50mg - tramadol 100mg online

 
At March 7, 2013 at 5:43 PM , Anonymous Anonymous said...

tramadol online buy tramadol online bluelight - tramadol 20mg

 
At March 7, 2013 at 7:53 PM , Anonymous Anonymous said...

klonopin buy klonopin side effects brain - generic klonopin yellow

 
At March 7, 2013 at 8:44 PM , Anonymous Anonymous said...

07 Purchase Sumatriptan - buy imitrex no prescription http://www.cheapimitrexbuy.net/#imitrex-no-prescription, [url=http://www.cheapimitrexbuy.net/#imitrex-no-prescription]Imitrex No Prescription[/url]

 
At March 8, 2013 at 12:42 AM , Anonymous Anonymous said...

klonopin drug klonopin pill wiki - best brand generic klonopin

 
At March 8, 2013 at 5:38 PM , Anonymous Anonymous said...

4, reductil sale - buy sibutramine no prescription http://www.meridiaforyourdiet.net/#sibutramine-diet-pills, [url=http://www.meridiaforyourdiet.net/#cheap-sibutramine]buy meridia[/url]

 
At March 11, 2013 at 3:34 AM , Anonymous Anonymous said...

buy klonopin online klonopin side effects brain - klonopin children

 
At March 13, 2013 at 5:06 AM , Anonymous Anonymous said...

ooo, sumatriptan without rx - sumatriptan for sale http://www.emiratesosteoporosissociety.com/, [url=http://www.emiratesosteoporosissociety.com/]order imitrex no prescription [/url]

 
At March 15, 2013 at 1:09 PM , Anonymous Anonymous said...

oZzy moved away ever before, I miss his cock, for always hungry for sexual intercourse.

FUCK MY PUSSY!

Feel free to visit my site ... hcg injections

 
At March 16, 2013 at 8:23 PM , Anonymous Anonymous said...

carisoprodol 350 mg carisoprodol 250 mg tablet - carisoprodol gaba

 
At March 18, 2013 at 6:29 AM , Anonymous Anonymous said...

Whats uρ thіѕ is kіnda of off topіc but I was wantіng to
knоw if blogs use WYЅIWYG eԁіtors or if you have to mаnuallу cоde with
HΤML. I'm starting a blog soon but have no coding experience so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

Review my website steroids steroids

 
At March 20, 2013 at 8:40 PM , Anonymous Anonymous said...

Incredible quest there. What happened after? Take care!


My blog post ... drinking coffee

 
At April 18, 2013 at 5:20 PM , Anonymous Anonymous said...

Hello there, I think your web site could be having web browser compatibility issues.
When I take a look at your blog in Safari, it looks
fine however, when opening in IE, it's got some overlapping issues. I simply wanted to provide you with a quick heads up! Besides that, excellent site!

My weblog: please click for source

 
At May 4, 2013 at 1:05 AM , Anonymous Anonymous said...

Excellent ωebsite. Lotѕ of usеful іnformation
here. І am sending іt tо sevеral budԁieѕ ans adԁitiοnallу sharing in deliciоuѕ.
And naturally, thаnks to yоur effoгt!

My web blοg ... hcg diet food plan

 
At May 4, 2013 at 1:05 AM , Anonymous Anonymous said...

Excеllent wеbsite. Lots of useful information heгe.
I am ѕеnding it to several buddies ans аdditіonally sharing in delicious.
Αnd naturally, thаnkѕ to yоur effort!


my web рage - hcg diet food plan
My web site > purchase hcg injections

 
At May 16, 2013 at 12:38 PM , Anonymous Anonymous said...

I every time used to read piece of writing in news
papers but now as I am a user of web so from now I am using net for articles or reviews, thanks to web.


Feel free to visit my blog - website

 
At May 17, 2013 at 12:44 AM , Anonymous Anonymous said...

I think this is one of the most important information for
me. And i am glad reading your article. But want to remark on few general things, The web site style is wonderful, the
articles is really great : D. Good job, cheers

Also visit my blog post; website

 
At May 24, 2013 at 11:32 PM , Anonymous Anonymous said...

At this time I am ready to do my breakfast, when having my breakfast coming yet again to read other news.


My blog - http://groupbuyingindia.com

 
At May 29, 2013 at 10:15 AM , Anonymous Anonymous said...

Hello there! I know this is kind of off topic but I was wondering if you knew where I could find a
captcha plugin for my comment form? I'm using the same blog platform as yours and I'm
having problems finding one? Thanks a lot!


my web blog - http://ileb.pixnet.Net/Blog/post/33489570-walt-disney-world:-day-2-epcot

 
At May 30, 2013 at 8:55 AM , Anonymous Anonymous said...

I know this if off topic but I'm looking into starting my own weblog and was curious what all is needed to get setup? I'm assuming having a blog like
yours would cost a pretty penny? I'm not very internet savvy so I'm not
100% sure. Any suggestions or advice would be greatly appreciated.
Thanks

Feel free to surf to my web site - msn hotmail

 
At June 5, 2013 at 2:45 AM , Anonymous Anonymous said...

Great information. Lucky me I came across your website by
accident (stumbleupon). I've saved it for later!

my web-site :: life insurance quotes

 
At June 6, 2013 at 4:20 AM , Anonymous Anonymous said...

Very energetic post, I loved that bit. Will there be a part
2?

my web page: intelius background check

 
At June 13, 2013 at 7:05 PM , Anonymous Anonymous said...

The momentum for Macklemore & Ryan Lewis' 'Thrift Shop' continues to rise, as the band sits atop the Ultimate Song Chart for a third straight week. Adult Education - 1984 - a second single from the greatest hits album, "Rock And Soul, Pt. Akon does well in R&B singer, songwriter, and record producer; he also sings in Senegalese.

Here is my homepage: Top 20 US UK Music

 
At June 17, 2013 at 1:04 AM , Anonymous Anonymous said...

This is a topic that is near to my heart... Cheers!
Where are your contact details though?

Feel free to surf to my site ... online roulette

 
At June 18, 2013 at 8:24 AM , Anonymous Anonymous said...

Somanabolic Muscle Maximizer program is optimized for the U.
To find out if it is actually true and to understand better if Kyle Leon's system is generally for you or not, let's look into a few of the benefits
and drawbacks of the product. No make a difference what sort of fat
coaching regimen you.

my web site :: muscle maximizer results

 
At November 26, 2013 at 10:42 PM , Blogger williamhenery said...

Hi!

I really love to read this post and I am glad to find your viagra samples Thanks and Regards

Index Attestation Services

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home