Tuesday, May 29, 2012

How to register SSL certificates in your JVM?

You wrote a Java program which needs to access to a external ressource through SSL (such as LDAPS or HTTPS)?

Okay, this post is for you.

The first thing you have to know is that the first time you established a secured connection to something, you (normally) have to accept the certificate used to encrypt the dialog. In apps with interaction with end users (such as a web browser), the user often see a popup which asks him to trust the certificate. But, if the secured connection is establised behind the scene  (without any possibility to show a popup to somebody, such in batch process apps), the certificate must be trusted before establishing the connection.

In Java, there's a wallet which contains trusted certificate. It is located in [JAVA_HOME]/jre/lib/security/cacerts

I explain here how to extract the public key of a SSL certificate and how to register is in the cacerts file.

Step 1 : let's extract the public key from a secured connection


We will use OpenSSL for that. Just run from a shell :
openssl s_client -connect [URL_TO_REACH]:443 > cert.pem

This will generate a file "cert.pem". Edit this file and remove the text before and after the certificate (You will understand while you will see it)

Step 2 : register the cert.pem in the cacerts wallet


There are four prerequisites to know :
  • the certificate has to be associated with a n alias in the wallet (and you will see that you will be able to remove it from the wallet by this alias later)
  • for unix users, you have to be root to register a certificate
  • the default password of the cacerts wallet is "changeit"
  • don't forget to restart your program after having registered the certificate
 To register your cert.pem, just do :
su -c "[JAVA_HOME]/jre/bin/keytool -import -alias [MY_CERT_ALIAS] -keypass changeit -keystore [JAVA_HOME]/jre/lib/security/cacerts -file cert.pem"
(Don't forget to replace [JAVA_HOME] and [MY_CERT_ALIAS] with your own values.

If you need to remove this certificate, just do :
su -c "[JAVA_HOME]/jre/bin/keytool -delete -alias [MY_CERT_ALIAS] -keypass changeit -keystore [JAVA_HOME]/jre/lib/security/cacerts"

That's all.

UPDATE (October 2016) : 


If you have an handshake failure, try this :

openssl s_client -tls1 -connect [URL_TO_REACH]:443 > cert.pem

71 comments:

Engineering Ebooks Download said...

Dollardoc is a premier place for publishing of Books, Documents and Presentations. It is right now the World’s fastest growing online publishing platform for the widest range of Books, documents and other kinds of social publications.

Eric said...

Thank you! This made what seemed like a daunting task much easier! I was able to successfully make the connection now.

rebeka christy said...

Thanks for sharing this informative blog. Those who want to become a certified unix professional reach FITA, Which offers best Unix Course in Chennai with years of experienced professionals.

dhanamlakshmi palu said...

Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post.
very nice !!!
CCNA training in chennai | CCNA training chennai | CCNA course in chennai | CCNA course chennai

general manager said...

Thanks for sharing this effective article,
"domain"

Staff Ngeditblog said...

tempat nyari SSL murah ya di IDwebhost.com Cuman disini kamu bisa menemukan paket terbaik untuk hosting webkamu.

Savitha said...

Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
Oracle Training In Chennai

Diya Patel said...

Best SAS Training Institute In Chennai It’s too informative blog and I am getting conglomerations of info’s about Oracle interview questions and answer .Thanks for sharing, I would like to see your updates regularly so keep blogging.

big data trunk1 said...


Thank you for sharing such great information !
big data classroom training
hadoop ónlinÉ training
free big data bootcamp

hadoop big data videos

Big data QA Tester training
Big data Analyst training

simashree said...

Thanks for the great information in your blog Selenium Training in Chennai

mythily mythu said...

Thanks for the great information in your blog.
android training in chennai

mythily mythu said...

Thank you for sharing such great information !
datamodeling training in chennai

Anonymous said...

Great man, Thank you for the blog sharing informative contents about SSL Certificate in Chennai.

sri krishna kumar said...

Your post is nice to read and thank to share this post
Mainframe Training In Chennai | Informatica Training In Chennai | Hadoop Training In Chennai

gkr ragini said...

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.digital marketing training in chennai

The SSL Street said...
This comment has been removed by the author.
The SSL Street said...

Thanks for sharing this information. SSL Certificates protect your customer's personal data including passwords, credit cards and identity information. Getting an SSL certificate is the easiest way to increase your customer's confidence in your online business.

Vikky cmd said...

Hello there! This is my first comment here, so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles. Can you recommend any other blogs/websites/forums that deal with the same subjects? Thanks.

Hadoop Training in Chennai

Jai Prakash said...

Nice post.
Digital Marketing Course In Chennai
Digital marketing Courses

sofianan said...

Amazing post.Thanks for your details and explanations..I want more information from your side.Thank you
hr and payroll software in chennai

Rohini .R said...

Thanks for your information
Oracle training in rajajinagar

malini v said...

Oracle training in chennai
Thanks for detail explanation

john jersy said...

Write more; that’s all I have to say. It seems as though you relied on the video to make your point. You know what you’re talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?
Click here:
angularjs training in annanagar
Click here:
angularjs training in bangalore
Click here:
angularjs training in chennai
Click here:
angularjs training in velarchery
Click here:
angularjs training in sholinganallur

sai said...

Were a gaggle of volunteers as well as starting off a brand new gumption within a community. Your blog furnished us precious details to be effective on. You've got completed any amazing work!
Click here:
Microsoft azure training in marathahalli
Click here:
Microsoft azure training in bangalore
Click here:
Microsoft azure training in pune

gowsalya said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Devops Training in Chennai

Devops Training in Bangalore

Devops Training in pune

Mouni yoga said...

It is better to engaged ourselves in activities we like. I liked the post. Thanks for sharing.
Python training in btm
Python training in usa
Python training in marathahalli
AWS Training in chennai
AWS Training in bangalore

john jersy said...

Really nice experience you have. Thank you for sharing. It will surely be an experience to someone.
AWS Training in chennai
AWS Training in bangalore

johnsy sai said...

Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging

DevOps online Training|DevOps Training in USA
Devops Training in Chennai

Devops Training in Bangalore

isai 14 said...

Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 
Blueprism training in tambaram

Blueprism training in annanagar

Blueprism training in velachery

Naga Manickam said...

Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straightforward and to the point.
Data Science training in rajaji nagar | Data Science with Python training in chenni
Data Science training in electronic city | Data Science training in USA
Data science training in pune | Data science training in kalyan nagar



lenin christ said...

Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!
Data science course in tambaram | Data Science course in anna nagar
Data Science course in chennai | Data science course in Bangalore
Data Science course in marathahalli | Data Science course in btm

Afiah B said...

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
java training in omr | oracle training in chennai

java training in annanagar | java training in chennai

Chitra devi said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

best rpa training in chennai |
rpa training in chennai |
rpa training in bangalore
rpa training in pune | rpa online training

cynthia williams said...

Learned a lot from your blog. Good creation and hats off to the creativity of your mind. Share more like this.
RPA courses in Chennai
Robotic Process Automation Training
Blue Prism Training in Chennai
UiPath Training in Chennai
R Training in Chennai
Machine Learning Training in Chennai

Naga Manickam said...

Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 
Data Science course in Chennai | Data science course in bangalore
Data science course in pune | Data science online course
Data Science Interview questions and answers | Python course in Kalyan nagar

sudha P said...

This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
java training in tambaram | java training in velachery

java training in omr | oracle training in chennai

Anonymous said...

I have been meaning to write something like this on my website and you have given me an idea. Cheers.

angularjs Training in btm

angularjs Training in electronic-city

angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

Priya Rajesh said...

Wonderful post. Thanks for taking time to share this information with us.
DevOps certification Chennai
DevOps Training in Chennai
DevOps Training near me
Angularjs Training in Chennai
AWS course in Chennai

Meera Kumar said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us. Do check R Programming Course Fees & Get trained by an expert who will enrich you with the latest trends.

Ananya Krishnan said...

Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

Good to learn about DevOps at this time.

devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai

Anonymous said...

Your story is truly inspirational and I have learned a lot from your blog. Much appreciated.

angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

angularjs Training in bangalore

angularjs Training in bangalore

angularjs online Training

Meera Kumar said...

I think things like this are really interesting. I absolutely love to find unique places like this. It really looks super creepy though!! R Programming institutes in Chennai | R Programming Training in Chennai

gowthunan said...

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
fire and safety course in chennai

kavinilavu G said...

Great blog.This was really informative and helpful.Thank you for shared.keep update..check it also big data training in Velachery
Hadoop Training in Chennai

Surendra SriyaEdu said...

Thank for sharing very valuable information.nice article.keep on blogging.For more information visit
aws online training
aws training in hyderabad
aws online training in hyderabad

Divya M said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
selenium training in chennai
selenium training in bangalore
selenium training in Pune
selenium training in pune
Selenium Online Training

kavinilavu G said...

Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us big data training in Velachery | Hadoop Training in Chennai | big data Hadoop training and certification in Chennai | Big data course fees

Shadeep shree said...

Great information!!! Thanks for your blog
Computer Education Franchise in India
Franchise in Education Sector
Franchise India
Franchise Business in India
Top 10 Franchise Business in India

LindaJasmine said...

Interesting Post. I liked your style of writing. It is very unique. Thanks for Posting.

Node JS Training in Chennai
Node JS Course in Chennai
Node JS Advanced Training
Node JS Training Institute in chennai
Node JS Training Institutes in chennai
Node JS Course

Shiva Shakthi said...

The blog you had post is verymuch useful for us to know about the Web designing. thanks for your information sharing with us.
Web Designing Institute in Coimbatore
Web Designing Course
Web Design Classes
Website Design Course
Learning Web Design

Vicky Ram said...

Excellent post! keep sharing such a post

Guest posting sites
Technology

Sumaya Manzoor said...

Thanks for sharing a valuable information to us. your article inspired me more. I Would like to get more updates in future.
selenium Training in Chennai
Selenium Training Chennai
ios training institute in chennai
Digital Marketing Course in Chennai
.Net coaching centre in chennai
android classes in chennai
app development course in chennai

Afiah B said...

A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

Java training in Bangalore | Java training in Marathahalli | Java training in Bangalore | Java training in Btm layout

Java training in Bangalore | Java training in Marathahalli | Java training in Bangalore | Java training in Btm layout

Anbarasan14 said...

This was helpful to me thanks for sharing this useful information. Kindly continue the work.

Spoken English Institutes in Bangalore
Spoken English Coacjing Classes near me
English Speaking Classes in Bangalore
Spoken English Chennai
English Classes in Chennai
Spoken English Course in Chennai
Best Spoken English Classes in Chennai

LindaJasmine said...

Interesting Post. Looking for this information for a while. Thanks for Posting.

Node JS Training in Chennai
Node JS Course in Chennai
Node JS Advanced Training
Tableau Training in Chennai
Tableau Course in Chennai
Primavera Training in Chennai
Primavera Course in Chennai
Pega training in chennai
Pega course in chennai

Naga Manickam said...

I really like your blog. You make it interesting to read and entertaining at the same time. I cant wait to read more from you.

Data Science training in rajaji nagar | Data Science Training in Bangalore | Data Science with Python training in chennai

Data Science training in electronic city | Data Science training in USA

Data science training in pune | Data science training in kalyan nagar

Mouni yoga said...

Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
python training institute in marathahalli
python training institute in btm
Python training course in Chennai

sharmi chithra said...

It is very excellent blog and useful article thank you for sharing with us, keep posting.

PrimaveraTraining in Velachery
Primavera Courses in Velachery
Primavera Training in Tambaram
Primavera Training in Adyar
Primavera Courses in Adyar

saran latha said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
Devops Training courses
Devops Training in Bangalore
Best Devops Training in pune

Xplore IT Corp said...


Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
networking training
ccna Training

sharmi chithra said...

Nice post. I learned some new information. Thanks for sharing.

Xamarin Training in Chennai
Xamarin Course in Chennai
Xamarin Training
Xamarin Course
Xamarin Training Course
Xamarin Classes
Best Xamarin Course

Vicky Ram said...

Nice Post. Looking for more updates from you. Thanks for sharing.

Guest posting sites
Technology

LindaJasmine said...

Thanks for sharing such an amazing post. Your style of writing is very unique. It made me mesmerized in your words. Keep on writing.

Informatica Training in Chennai
Informatica Training Center Chennai
Best Informatica Training in Chennai
Informatica course in Chennai
Informatica Training center in Chennai
Informatica Training
Learn Informatica
Informatica course

mercyroy said...

Innovative thinking of you in this blog makes me very useful to learn.
i need more info to learn so kindly update it.
Core Java Training in Bangalore
Java Courses in Chennai Perambur
Java Courses in Saidapet
Java Training in Kelambakkam

Aman CSE said...

Thanks For sharing such a wonderful Blog on RPA. This blog contains so much of data about RPA that anyone who is searching for RPA, its really helpful for them to grab this data from your blog on RPA. Again thank you so much for your blog on RPA.
Thanks and Regards,
blue prism training in chennai
Best blue prism training in chennai
blue prism training cost in chennai

Harish said...

You have done a great job by posting this. I found very useful information.

Spark Training in Chennai
Spark Course in Chennai
Spark Training
Spark Training in Velachery
Spark Training in Adyar
Spark Training in Tambaram

Rithi Rawat said...

Excellent and very cool idea and great content of different kinds of valuable information's. machine learning with python course in Chennai | machine learning training center in chennai

kavinilavu G said...

Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.Trending Software Technologies in 2018 | Hadoop Training in Chennai | big data Hadoop training and certification in Chennai | Roles and reponsibilities of hadoop developer

mercyroy said...

feeling so good to read your information's in the blog.
thanks for sharing your ideas with us and add more info.
devops course in bangalore
devops certification in bangalore
devops Course in Anna Nagar
Best devops Training Institute in Anna nagar

Anonymous said...

Such a great think. Your post is very knowledgeable. Please keep updating......
Best Digital Marketing Course in Bangalore
Digital Marketing Course Bangalore
Best Digital Marketing Classes in Bangalore
Digital Marketing Training in Nungambakkam
Digital Marketing Training in Saidapet
Digital Marketing Training in Kelambakkam
Digital Marketing Training in Karappakkam

Learn Digital said...

Your post is really awesome. Your blog is really helpful for me to develop my skills in a right way. Thanks for sharing this unique information with us.
- Learn Digital Academy

How to secure your REST API with Java Spring Security

Here is the best article I read on how to secure REST API and even make a full stateless architecture by using JWT token to store all user d...