{"id":298,"date":"2011-09-08T01:14:56","date_gmt":"2011-09-08T01:14:56","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=298"},"modified":"2013-01-18T01:04:02","modified_gmt":"2013-01-18T01:04:02","slug":"making-jre-trust-certificates","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2011\/09\/08\/making-jre-trust-certificates\/","title":{"rendered":"Making JRE trust certificates"},"content":{"rendered":"<p>Let&#8217;s say your Java Web Service client wants to make a call (SOAP over SSL\/https) to a service running on some server and is using a legitimate certificate or say a self-signed certificate.<\/p>\n<p>Now, your client can either bypass this certificate business by using <a href=\"http:\/\/devcentral.f5.com\/weblogs\/joe\/archive\/2005\/07\/06\/1345.aspx\">XTrustProvider.install()<\/a> or do it the right way by importing the certificate in your JRE_HOME\/lib\/security\/ folder.<\/p>\n<p>Either read the documentation on <a href=\"http:\/\/download.oracle.com\/javase\/1.3\/docs\/tooldocs\/win32\/keytool.html\">keytool<\/a> or read further.<br \/>\n(My snippets below use JDK 1.6.0_26 and are done Windows. You can do equivalent stuff on Linux as well)<\/p>\n<p>To View the list of certificates in the JDK,  goto <strong>JRE_HOME\\lib\\security<\/strong> and run the following:<\/p>\n<blockquote><p>\nC:\\Java\\jdk1.6.0_26\\jre\\lib\\security><strong>..\\..\\bin\\keytool keytool -list -keystore cacerts<\/strong><br \/>\nEnter keystore password:<em>default password is <strong>changeit<\/strong><\/em>\n<\/p><\/blockquote>\n<p>To Import the certificate into JDK, goto <strong>JRE_HOME\\lib\\security<\/strong> and run the following:<\/p>\n<blockquote><p>\nC:\\Java\\jdk1.6.0_26\\jre\\lib\\security><strong>..\\..\\bin\\keytool -import -alias myTestCert -keystore cacerts -file c:\\Temp\\Certificates\\DER_Cert.cer<\/strong><br \/>\nEnter keystore password:<em>default password is <strong>changeit<\/strong><\/em>\n<\/p><\/blockquote>\n<p>Now, your Java Web Service Client should now be able to make the calls over SSL without connection issues.<\/p>\n<p>In case you want to Delete the Certificate:<\/p>\n<blockquote><p>\nC:\\Java\\jdk1.6.0_26\\jre\\lib\\security><strong>..\\..\\bin\\keytool -delete -alias myTestCert -keystore cacerts<\/strong><br \/>\nEnter keystore password: <em>default password is <strong>changeit<\/strong><\/em>\n<\/p><\/blockquote>\n<p>More information can be found here: <a href=\"http:\/\/sites.google.com\/site\/ankurrathi\/trustingacertificate\">http:\/\/sites.google.com\/site\/ankurrathi\/trustingacertificate<\/a> and also explains how to download certificates if you don&#8217;t already have it.<\/p>\n<p>If you&#8217;re using Soap UI for testing and you might want to <a href=\"http:\/\/geekswithblogs.net\/gvdmaaden\/archive\/2011\/02\/24\/how-to-configure-soapui-with-client-certificate-authentication.aspx\">configure SoapUI with client certificate authentication. <\/a><\/p>\n<p>Finally your Web Service client might might also need to verify the hostnames as shown below where I trust all hosts.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nstatic  {\r\n\t\tHttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {\r\n\t\t\tpublic boolean verify(String hostname, SSLSession session) {\r\n\t\t\t\t\/\/ Make sure that hostname is valid\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say your Java Web Service client wants to make a call (SOAP over SSL\/https) to a service running on some server and is using a legitimate certificate or say a self-signed certificate. Now, your client can either bypass this certificate business by using XTrustProvider.install() or do it the right way by importing the certificate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/298"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=298"}],"version-history":[{"count":12,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/298\/revisions"}],"predecessor-version":[{"id":301,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/298\/revisions\/301"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}