{"id":1236,"date":"2020-07-28T17:35:28","date_gmt":"2020-07-28T05:35:28","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1236"},"modified":"2020-07-28T18:03:04","modified_gmt":"2020-07-28T06:03:04","slug":"java-6-to-use-tls-1-2-by-using-bouncycastle","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1236","title":{"rendered":"Java 6 to use TLS 1.2 by using BouncyCastle"},"content":{"rendered":"<ol>\n<li>Download the <strong><a href=\"https:\/\/www.oracle.com\/java\/technologies\/jce-6-download.html\" target=\"_blank\" rel=\"noopener noreferrer\">Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 6<\/a>.<\/strong> <em>(i.e. if the link is already dead then download this instead <a href=\"https:\/\/nasnz.ronella.xyz\/wordpress\/wp-content\/uploads\/2020\/07\/jce_policy-6.zip\">jce_policy-6<\/a>.)<\/em><\/li>\n<li>Extract the downloaded archive and follow the installation procedure found in the <strong>README.txt<\/strong>.<\/li>\n<li>Download the following <strong>Bouncy Castle libraries<\/strong>:\n<ul>\n<li><a href=\"https:\/\/www.bouncycastle.org\/download\/bcprov-jdk15to18-166.jar\" target=\"_blank\" rel=\"noopener noreferrer\">bcprov-jdk15to18-166.jar<\/a><\/li>\n<li><a href=\"https:\/\/www.bouncycastle.org\/download\/bctls-jdk15to18-166.jar\" target=\"_blank\" rel=\"noopener noreferrer\">bctls-jdk15to18-166.jar<\/a><br \/>\n<blockquote><p>If the preceding links doesn't work try to find them from the <a href=\"https:\/\/www.bouncycastle.org\/archive\/\" target=\"_blank\" rel=\"noopener noreferrer\">archive<\/a>.<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<\/li>\n<li>Place the downloaded libraries into <strong>${JAVA_HOME}\/jre\/lib\/ext<\/strong> directory.<\/li>\n<li>Update the <strong>java.security<\/strong> <em>(i.e. found in ${JAVA_HOME}\/jre\/lib\/security directory.)<\/em> file to have the following as the priority:\n<pre style=\"white-space: pre;\">security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider\r\nsecurity.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider\r\n<\/pre>\n<blockquote><p>Adjust the other <strong>security.provider<\/strong> to start from <strong>3<\/strong> like the following:<\/p>\n<pre style=\"white-space: pre;\">security.provider.3=sun.security.provider.Sun\r\nsecurity.provider.4=sun.security.rsa.SunRsaSign\r\nsecurity.provider.5=com.sun.net.ssl.internal.ssl.Provider\r\nsecurity.provider.6=com.sun.crypto.provider.SunJCE\r\nsecurity.provider.7=sun.security.jgss.SunProvider\r\nsecurity.provider.8=com.sun.security.sasl.Provider\r\nsecurity.provider.9=org.jcp.xml.dsig.internal.dom.XMLDSigRI\r\nsecurity.provider.10=sun.security.smartcardio.SunPCSC\r\nsecurity.provider.11=sun.security.mscapi.SunMSCAPI\r\n<\/pre>\n<\/blockquote>\n<\/li>\n<li>Try the following <strong>Java code<\/strong>:\n<pre style=\"white-space: pre;\">import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.net.HttpURLConnection;\r\nimport java.net.ProtocolException;\r\nimport java.net.URL;\r\n\r\npublic class Main {\r\n\r\n    public static void main(String[] args) {\r\n        try {\r\n            URL url = new URL(\"https:\/\/www.nist.gov\/\");\r\n            System.out.println(url);\r\n            HttpURLConnection connection = (HttpURLConnection) url.openConnection();\r\n            connection.setRequestMethod(\"GET\");\r\n            connection.setDoOutput(true);\r\n            System.out.println(connection.getResponseCode());\r\n            StringBuilder response = new StringBuilder();\r\n            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));\r\n\r\n            try {\r\n                String line = reader.readLine();\r\n                while (line != null) {\r\n                    response.append(line);\r\n                    line = reader.readLine();\r\n                }\r\n            } finally {\r\n                reader.close();\r\n            }\r\n\r\n            System.out.println(response.toString());\r\n        }\r\n        catch(ProtocolException exception) {\r\n            exception.printStackTrace();\r\n        }\r\n        catch(IOException exception) {\r\n            exception.printStackTrace();\r\n        }\r\n    }\r\n}<\/pre>\n<blockquote><p>You should be able to access it without any SSL handshake error.<\/p><\/blockquote>\n<blockquote><p>Alternatively, you can opt to use the official <a href=\"https:\/\/www.oracle.com\/java\/technologies\/javase\/6-relnotes.html#R160_121\" target=\"_blank\" rel=\"noopener noreferrer\">JDK 6u121<\/a> via the <a href=\"https:\/\/www.oracle.com\/java\/technologies\/javase\/6-relnotes.html\" target=\"_blank\" rel=\"noopener noreferrer\">Java SE 6 Advanced and Java SE 6 Support<\/a> if you have availed of it.<\/p><\/blockquote>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Download the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 6. (i.e. if the link is already dead then download this instead jce_policy-6.) Extract the downloaded archive and follow the installation procedure found in the README.txt. Download the following Bouncy Castle libraries: bcprov-jdk15to18-166.jar bctls-jdk15to18-166.jar If the preceding links doesn&#8217;t work try to find them [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,23],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1236"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1236"}],"version-history":[{"count":8,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1236\/revisions"}],"predecessor-version":[{"id":1245,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1236\/revisions\/1245"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}