{"id":29,"date":"2019-11-02T16:51:01","date_gmt":"2019-11-02T16:51:01","guid":{"rendered":"https:\/\/www.grizzly-hills.com\/?p=29"},"modified":"2019-11-02T16:51:01","modified_gmt":"2019-11-02T16:51:01","slug":"tomcat-enabling-ssl","status":"publish","type":"post","link":"https:\/\/www.grizzly-hills.com\/index.php\/2019\/11\/02\/tomcat-enabling-ssl\/","title":{"rendered":"Tomcat: Enabling SSL"},"content":{"rendered":"\n<p>Usually, when you get your SSL certificates, they are .crt, .key, and .ca-bundle files. These work fine for Apache&#8217;s HTTP server, but Apache&#8217;s Tomcat server needs these converted into a .jks (Java Key Store), and the Tomcat configuration set up to use that key store. To simplify the conversion, here is a shell script to perform the steps, under the assumption that the .crt, .key, and .ca-bundle files all have the same prefix.<\/p>\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/sh\nif [ \"$1\" = \"\" ]; then\n&nbsp; echo \"\"\n&nbsp; echo \"&nbsp; usage: $0 &lt;file-prefix&gt; &lt;password&gt;\"\n&nbsp; echo \"\"\n&nbsp; echo \"&nbsp; This tool requires that all files have the same prefix, and the .crt, .key, and .ca-bundle files exist.\"\n&nbsp; echo \"\"\n&nbsp; echo \"&nbsp; For example, if your files are named example.com.crt, example.com.key, example.com.ca-bundle, you would do:\"\n&nbsp; echo \"\"\n&nbsp; echo \"&nbsp; &nbsp; $0 example.com mySekretPasswd\"\n&nbsp; echo \"\"\n&nbsp; exit 1\nfi\necho \"\"\necho \"&nbsp; Generating JKS file for $1...\"\necho \"\"\necho \"----------------------------------------------------------\"\nopenssl pkcs12 -export -in $1.crt -inkey $1.key -name $1 -out $1.p12 -passout pass:$2\nkeytool -importkeystore -deststorepass $2 -destkeystore $1.jks -srckeystore $1.p12 -srcstoretype PKCS12 -srcstorepass $2\nkeytool -import -alias bundle -trustcacerts -file $1.ca-bundle -keystore $1.jks -storepass $2\nprefix_alias=`keytool -list -v -keystore $1.jks -storepass $2 | grep -i alias | grep $1`\nif [ \"$prefix_alias\" = \"\" ]; then\n&nbsp; echo \"\"\n&nbsp; echo \"&nbsp; ** something seems to have gone wrong, $1 not found in aliases\"\n&nbsp; echo \"\"\n&nbsp; exit 1\nfi\necho \"----------------------------------------------------------\"\necho \"\"\necho \"&nbsp; JKS file created.\"\necho \"\"\necho \"&nbsp; Copy $1.jks to Tomcat's ssl directory, typically something like \/etc\/tomcat8\/ssl\/$1.jks\"\necho \"\"\necho \"&nbsp; Add or Update the &lt;Connector&gt; entries in Tomcat's server.xml to be something like:\"\necho \"\"\necho \"&nbsp; &nbsp; &lt;Connector port=\\\"8443\\\" protocol=\\\"org.apache.coyote.http11.Http11NioProtocol\\\" maxThreads=\\\"150\\\" SSLEnabled=\\\"true\\\" scheme=\\\"https\\\" secure=\\\"true\\\" clientAuth=\\\"false\\\" sslProtocol=\\\"TLS\\\" keystoreFile=\\\"\/etc\/tomcat8\/ssl\/$1.jks\\\" keystoreType=\\\"JKS\\\" keystorePass=\\\"$2\\\" keyAlias=\\\"$1\\\" \/&gt;\"\necho \"&nbsp; &nbsp; &lt;Connector port=\\\"8009\\\" protocol=\\\"AJP\/1.3\\\" redirectPort=\\\"8443\\\" \/&gt;\"\necho \"\" <\/pre>\n\n\n<p>An example of using the tool, if your certificate files all start with <code><strong>example.com<\/strong><\/code>:<\/p>\n\n\n<pre class=\"wp-block-preformatted\"><strong>.\/convert-for-tomcat.sh example.com mySekretPasswd<\/strong> <\/pre>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Usually, when you get your SSL certificates, they are .crt, .key, and .ca-bundle files. These work fine for Apache&#8217;s HTTP server, but Apache&#8217;s Tomcat server needs these converted into a .jks (Java Key Store), and the Tomcat configuration set up to use that key store. To simplify the conversion, here is a shell script to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.grizzly-hills.com\/index.php\/2019\/11\/02\/tomcat-enabling-ssl\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Tomcat: Enabling SSL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[16,19],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-linux-systems-administration","tag-linux","tag-tomcat"],"_links":{"self":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":0,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}