{"id":530,"date":"2018-10-09T03:00:15","date_gmt":"2018-10-09T03:00:15","guid":{"rendered":"http:\/\/www.asianux.org.vn\/?p=530"},"modified":"2018-10-09T03:00:15","modified_gmt":"2018-10-09T03:00:15","slug":"step-by-step-instructions-on-self-signed-certificate-and-tomcat-over-ssl","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2018\/10\/09\/step-by-step-instructions-on-self-signed-certificate-and-tomcat-over-ssl\/","title":{"rendered":"Step by step instructions on self-signed certificate and Tomcat over SSL"},"content":{"rendered":"<p>Creating a self-signed certificate to test Tomcat https is easy, and this article gives you the step-by-step instructions on the following parts:<\/p>\n<p>1. Create a self-signed host certificate using openSSL<\/p>\n<p>2. Create a PKCS12 keystore and convert it to java keystore<\/p>\n<p>3. Configure Tomcat 6 to use https, and redirect http to https<\/p>\n<p>4. Create a Java client to talk to the Tomcat over SSL with the self-signed certificates<\/p>\n<h2><strong>Part 1. \u00a0Create a self-signed host certificate using openSSL<\/strong><\/h2>\n<p>There are different ways of creating a self-signed certificate, such as using Java keytool. \u00a0But I prefer openSSL because the keys and certificates generated this way are more standardized and can be used for other purposes. \u00a0The\u00a0<a href=\"http:\/\/www.openssl.org\/docs\/HOWTO\/\" target=\"_blank\" rel=\"noopener\">openSSL HOWTO page<\/a>\u00a0gives you a lot of details and other information.<\/p>\n<h3>1.1 Create a pair of PKI keys<\/h3>\n<p>PKI stands for Public Key Infrastructure, which is also known as Asymmetric key pair, where you have a private key and a public key. \u00a0The private key is a secret you guard with your honor and life, and the public key is something you give out freely. \u00a0Messages encrypted with one can be decrypted with the other. \u00a0While generally speaking, given one key, it should be infeasible to derive the other. \u00a0However, openSSL makes it so that given a private key, you can easily derive the public key (but not vice versa, otherwise the security is broken). \u00a0For this reason, when you generate a key using openSSL, it only gives you a private key.<\/p>\n<p>As a side note, the word\u00a0asymmetric\u00a0is really a poor choice. \u00a0Once, a security expert was giving a presentation to a roomful of students on PKI, and one of his slides was supposed to have the title \u201cAsymmetric key scheme\u201d, but perhaps it was the fonts he used, or perhaps he made a last-minute typo,\u00a0\u00a0it looked like there was a space between the letter \u201cA\u201d and the rest of the letter. \u00a0After that presentation, quite a few naive students began to think that \u00a0PKI is a\u00a0<del><em>symmetric\u00a0<\/em><\/del><em>(WRONG!)<\/em>\u00a0key scheme where it should be exactly the opposite \u2014 this is probably a less forgivable mistake than blowing up the chemistry lab because someone thinks inflammable means not flammable.<\/p>\n<p>1.1.1 Create a host private key using openSSL<\/p>\n<div>\n<div id=\"highlighter_188247\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">openssl genrsa -out HOSTNAME-private.pem 2048<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This private key is 2048 bits long, generated using RSA algorithm, and we choose not to protect it with an additional passphrase because the key will be used with a server certificate. \u00a0The name of the private key is HOSTNAME-private.pem where HOSTNAME should be replaced by the name of the machine you intend to host Tomcat.<\/p>\n<p>1.1.2 Derive the public key using openSSL. \u00a0This step is not necessary, unless \u00a0you want to distribute the public key to others.<\/p>\n<div>\n<div id=\"highlighter_97791\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">openssl rsa -<\/code><code class=\"bash keyword\">in<\/code> <code class=\"bash plain\">HOSTNAME-private.pem -pubout \u00a0&gt; HOSTNAME-public.pem<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>1.2 Create a self-signed X509 certificate<\/h3>\n<div>\n<div id=\"highlighter_461908\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">openssl req -new -x509 -key HOSTNAME-private.pem -out HOSTNAME-certificate.pem -days 365<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Then you will be prompted to enter a few pieces of information, use \u201c.\u201d if you wish to leave the field blank<\/p>\n<div>\n<div id=\"highlighter_616455\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">-----<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash plain\">Country Name (2 letter code) [AU]:US<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"bash plain\">State or Province Name (full name) [Some-State]:Indiana<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"bash plain\">Locality Name (eg, city) []:Bloomington<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"bash plain\">Organization Name (eg, company) [Internet Widgits Pty Ltd]:Cool Org<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"bash plain\">Organizational Unit Name (eg, section) []:Cool IT<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"bash plain\">Common Name (eg, YOUR name) []:Cool Node<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"bash plain\">Email Address []:.<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>You will now see your host certificate file HOSTNAME-certificate.pem<\/p>\n<p><strong>UPDATE<\/strong>: The field Common Name is quite important here. \u00a0It is the\u00a0<strong>hostname<\/strong>\u00a0of the machine you are trying to certify with the certificate, which is the name in the DNS entry corresponding to your machine IP.<\/p>\n<p>If your machine does not have a valid DNS entry (in other words, doing a nslookup on the IP of your machine doesn\u2019t give you anything), the host certificate probably won\u2019t work too well for you. \u00a0If you are only doing some very minimalistic https connection using only the HttpsURLConnection provided by Java, you can probably get by by disabling the certificate validation as outline towards the end of this article; however, if you use other third-party software packages, you will probably get an exception look like the following:<\/p>\n<div>\n<div id=\"highlighter_67362\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">java.io.IOException: HTTPS hostname wrong: \u00a0should be &lt;xxx.yyy.zzz&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This is because many security packages would check for things such as URL Spoofing, and when they do a reverse lookup of the machine IP, \u00a0but do not yield the same hostname as what is in the certificate, they think something is fishy and throws the exception.<\/p>\n<p>Part 2. Create a PKCS12 keystore and convert it to a Java keystore<\/p>\n<p>Java keytool does not allow the direct import of x509 certificates with an existing private key, and here is a\u00a0<a href=\"http:\/\/www.agentbob.info\/agentbob\/79-AB.html\" target=\"_blank\" rel=\"noopener\">Java import key utility<\/a>\u00a0Agent Bob created to get around that. \u00a0However, we can still get it to work even without this utility. \u00a0The trick is to import the certificate into a PKCS12 keystore, which Java keytool also supports, and then convert it to the Java keystore format<\/p>\n<h3>2.1 Create a PKCS12 keystore and import (or export depending on how you look at it) the host certificate we just created<\/h3>\n<div>\n<div id=\"highlighter_362121\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">openssl pkcs12 -<\/code><code class=\"bash functions\">export<\/code> <code class=\"bash plain\">-out keystore.pkcs12 -<\/code><code class=\"bash keyword\">in<\/code> <code class=\"bash plain\">HOSTNAME-certificate.pem -inkey HOSTNAME-private.pem<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>It will ask you for the export password, and it is recommended to provide a password.<\/p>\n<h3>2.2 Convert the PKCS12 keystore to Java keystore using Java keytool.<\/h3>\n<div>\n<div id=\"highlighter_91959\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">keytool -importkeystore -srckeystore keystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Keytool will first ask you for the new password for the JKS keystore twice, and it will also ask you for the password you set for the PKCS12 keystore created earlier.<\/p>\n<div>\n<div id=\"highlighter_139467\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">Enter destination keystore password:<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash plain\">Re-enter new password:<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"bash plain\">Enter <\/code><code class=\"bash functions\">source<\/code> <code class=\"bash plain\">keystore password:<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"bash plain\">Entry <\/code><code class=\"bash keyword\">for<\/code> <code class=\"bash functions\">alias<\/code> <code class=\"bash plain\">1 successfully imported.<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"bash plain\">Import <\/code><code class=\"bash functions\">command<\/code> <code class=\"bash plain\">completed: 1 entries successfully imported, 0 entries failed or cancelled<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>It will output the number of entries successfully imported, failed, and cancelled. \u00a0If nothing went wrong, you should have another keystore file: keystore.jks<\/p>\n<h2>Part 3. Configure Tomcat to use HTTPS<\/h2>\n<p>With the keystore in place, we can now configure Tomcat to communicate via SSL using the certificate.<\/p>\n<h3>3.1 Configure Tomcat HTTPS Connector.<\/h3>\n<p>Edit CATALINA_HOME\/conf\/server.xml, where CATALINA_HOME is the base directory of Tomcat. \u00a0By default, the HTTPS Connector configuration is commented out. \u00a0We can search for \u201c8443\u201d which is the default port number for HTTPS connector, and then either replace the configuration block, or add another block just below. \u00a0We are going to use the Coyote blocking connector:<\/p>\n<div>\n<div id=\"highlighter_626039\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml comments\">&lt;!--<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"xml spaces\">\u00a0<\/code><code class=\"xml comments\">&lt;Connector port=\"8443\" protocol=\"HTTP\/1.1\" SSLEnabled=\"true\"<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"xml spaces\">\u00a0<\/code><code class=\"xml comments\">maxThreads=\"150\" scheme=\"https\" secure=\"true\"<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"xml spaces\">\u00a0<\/code><code class=\"xml comments\">clientAuth=\"false\" sslProtocol=\"TLS\" \/&gt;<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"xml spaces\">\u00a0<\/code><code class=\"xml comments\">--&gt;<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">Connector<\/code> <code class=\"xml color1\">port<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"8443\"<\/code> <code class=\"xml color1\">protocol<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"org.apache.coyote.http11.Http11Protocol\"<\/code> <code class=\"xml color1\">SSLEnabled<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"true\"<\/code> <code class=\"xml color1\">maxThreads<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"150\"<\/code> <code class=\"xml color1\">secure<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"true\"<\/code> <code class=\"xml color1\">scheme<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"https\"<\/code> <code class=\"xml color1\">keystoreFile<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"PATH\/TO\/keystore.jks\"<\/code> <code class=\"xml color1\">keystorePass<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"JKS_KEYSTORE_PASSWORD\"<\/code> <code class=\"xml color1\">clientAuth<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"false\"<\/code> <code class=\"xml color1\">sslProtocol<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"TLS\"<\/code> <code class=\"xml plain\">\/&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>In the snippet above, PATH\/TO\/keystore.jks is the path to the Java Keystore we created earlier, and I recommend using the absolute path to eliminate any confusion. \u00a0Also provide the keystore password \u2013 it is in plain text, so protect server.xml using the correct permission (700).<\/p>\n<p>The\u00a0<a href=\"http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/ssl-howto.html#Edit_the_Tomcat_Configuration_File\" target=\"_blank\" rel=\"noopener\">Tomcat SSL configuration instruction<\/a>\u00a0is a bit misleading and may let us believe both blocking and non-blocking should be configured. \u00a0This is not true because the port number can only be used by one connector type.<\/p>\n<p>This configuration enables Tomcat to communicate HTTPS on port 8443. \u00a0At this point, it is a good idea to fire up Tomcat and make sure the configuration works using a web browser.<\/p>\n<div>\n<div id=\"highlighter_61178\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">cd CATALINA_HOME<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"xml plain\">bin\/startup.sh<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>And point your web browser to\u00a0<a href=\"https:\/\/hostname:8443\/\" rel=\"nofollow\">https:\/\/HOSTNAME:8443<\/a>\u00a0to see if Tomcat\u2019s front page shows up. \u00a0Since we are using a self-signed certificate, your browser may complain about the certificate being not secure. \u00a0Accept the certificate so your browser can display the page.<\/p>\n<h3>3.2 Configure Tomcat to redirect HTTP to HTTPS<\/h3>\n<p>However, so far, Tomcat still supports HTTP (default port is 8443, but it may have been changed in your situation). \u00a0It would be desirable to automatically redirect any requests to the HTTP over to the HTTPS. \u00a0The first thing to do is edit CATALINA_HOME\/conf\/server.xml again, and this time, locate the Connector configuration for HTTP, and modify it so that the \u201credirectPort\u201d attribute points to the HTTPS port (8443 by default).<\/p>\n<div>\n<div id=\"highlighter_485898\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">Connector<\/code> <code class=\"xml color1\">port<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"8080\"<\/code> <code class=\"xml color1\">protocol<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"HTTP\/1.1\"<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"xml spaces\">\u00a0<\/code><code class=\"xml color1\">connectionTimeout<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"20000\"<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"xml spaces\">\u00a0<\/code><code class=\"xml color1\">redirectPort<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"8443\"<\/code> <code class=\"xml plain\">\/&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Now save server.xml, and edit web.xml, and add the following block to the end of the file, just before the &lt;\/web-app&gt; tag (in other words, the security-constraint section must be added AFTER the servlet-mapping sections:<\/p>\n<div>\n<div id=\"highlighter_433433\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">web-app<\/code> <code class=\"xml plain\">...&gt;<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"xml plain\">...<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"xml spaces\">\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">security-constraint<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">web-resource-collection<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">web-resource-name<\/code><code class=\"xml plain\">&gt;All Apps&lt;\/<\/code><code class=\"xml keyword\">web-resource-name<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">url-pattern<\/code><code class=\"xml plain\">&gt;\/*&lt;\/<\/code><code class=\"xml keyword\">url-pattern<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">web-resource-collection<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">user-data-constraint<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">transport-guarantee<\/code><code class=\"xml plain\">&gt;CONFIDENTIAL&lt;\/<\/code><code class=\"xml keyword\">transport-guarantee<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"xml spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">user-data-constraint<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"xml spaces\">\u00a0\u00a0<\/code><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">security-constraint<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">web-app<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Save this file, restart Tomcat again. This time, open a browser and enter the URL to the normal HTTP port, and see if Tomcat redirects to the HTTPS port.<\/p>\n<h2>Part 4. Create a test Java client to talk to Tomcat over SSL<\/h2>\n<p>Since we created our own self-signed certificate, if we just use a Java HttpsURLConnection client trying to connect to the Tomcat over SSL, it will not honor the certificate and throw an exception like the following:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating a self-signed certificate to test Tomcat https is easy, and this article gives you the step-by-step instructions on the following parts: 1. Create a self-signed host certificate using openSSL 2. Create a PKCS12 keystore&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-530","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=530"}],"version-history":[{"count":1,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/530\/revisions"}],"predecessor-version":[{"id":531,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/530\/revisions\/531"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}