Home > Java > body text

How to set up an SSL certificate for Tomcat in Ubuntu

PHPz
Release: 2024-02-22 13:52:09
forward
1214 people have browsed it

php editor Yuzai brings you this issue of Java Q&A. Today’s topic is how to set up an SSL certificate for Tomcat in Ubuntu. SSL certificates are an important part of ensuring website security, and are especially important for websites running on Tomcat servers. Configuring an SSL certificate in an Ubuntu system may be a little complicated, but as long as you follow the correct steps, you can successfully set up an SSL certificate and protect your website data. Next, let us learn how to set up an SSL certificate for Tomcat in Ubuntu!

Question content

I use https://zerossl.com as the certificate and they provided me with these files:

  • ca_bundle.crt
  • Certificate.crt
  • Private Key

Then I run these commands

Generate p12 file

openssl pkcs12 -export -in certificate.crt -inkey private.key -out keystore.p12 -name tomcat -cafile ca_bundle.crt -caname root -chain
Copy after login

Generate jks file

keytool -importkeystore -srckeystore certifcate.p12 -srcstoretype pkcs12 -destkeystore mykeystore.jks -deststoretype pkcs12
Copy after login

Then I edit my /opt/tomcat/conf/server.xml

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
   maxThreads="150" scheme="https" secure="true"
   keystoreFile="/path/to/your/keystore.jks" keystorePass="your_keystore_password"
   keyAlias="tomcat" keyPass="your_key_password"
   clientAuth="false" sslProtocol="TLS" />
Copy after login

I'm not sure why the ssl certificate isn't working. If anyone could tell me if I'm missing something I'd be very grateful.

Solution

So you are doing too much. You don't need to convert the key to jks keystore. jks is java's original keystore format and is a proprietary format. Since then, pkcs12 came out and java finally supported it, so I recommend just using p12 files and configuring tomcat to read pkcs12 instead of trying to use jks.

However, for a quick answer, your conversion routine from pkcs12 -> jks does not save the jks file. -deststoretype pkcs12 should be -deststoretype jks However, we will do this for pkcs12 since that is the "future". Technically, tomcat has supported pkcs12 since 5.0, but that's in the future.

Anyway, here is how you can use p12 certificates in tomcat's setup.

<Connector port="8443" 
           protocol="org.apache.coyote.http11.Http11NioProtocol" 
           SSLEnabled="true"
           maxThreads="150"
           scheme="https"
           secure="true"
           clientAuth="false" 
           sslProtocol="TLS" 
           keystoreFile="/your/path/certificate.p12"
           keystorePass="xxxxsomething_secretxxxxx"
           keystoreType="PKCS12" />
Copy after login

The above is the detailed content of How to set up an SSL certificate for Tomcat in Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!