Update:
Try the client authentication method in Tomcat.
To get tomcat to take advantage of client authentication, we need three certificates. ie Server certificate for Tomcat, client certificate for browser and CA certificate, which will sign both of the above certificates. Here I will show how to do this on Windows.
There are two ways.
1) You must have a CSR file, i.e. a certificate signing request. You can send it to a Certification Authority such as Verisign or Comodo or many others like them. They will provide you with a certificate. Or
2) You can create your own certification authority and sign certificates. But it is recommended to do this only for personal use.
You must have Java and OpenSSL installed to complete the following steps.
To create a certificate signing request, you must have a key. To generate the key, enter the following command in the CMD.
openssl genrsa -out Serverkey.key 1024
This will create the "Serverkey.key" file. The key size is 1024. You can specify it according to your requirements.
Now create the CSR file with the following command.
openssl req -new -key Serverkey.key -out ServerReq.csr -config / path / to / openssl.cnf
After executing this command, you will be asked to provide some information. After that, you will find the CSR file in your directory. You can send this file to CA. In case you do this for personal use and you want to have your own certification authority, create a key and CSR for your certification authority using the above two commands. Once you have the CSR for CA, you can sign up with the CA key with the following command.
openssl x509 -req -days 365 -in CAReq.csr -signkey CAKey.key -out CA.crt
Once you have a CA certificate, you can use it to sign other certificates.
openssl x509 -req -days 365 -CA CA.crt -CAkey CAKey.key -CAcreateserial -in ServerReq.csr -out Server.crt
You can also use the same command for the client certificate.
The browser that is our client here will accept a certificate of P12 format. The P12 format is the file that contains your certificate, as well as the key.
Use the following command to convert CRT to P12.
openssl pkcs12 -export -in Server.crt -inkey ServerKey.key -chain -CAfile CA.crt -out ServerCert.p12
In tomcat, there is one trust store in which there will be a CA certificate, and the other is a keystore that will have a server key and certificate (p12 file).
Use the following command to import the CA certificate into truststore.
keytool -import -alias CertAuth -keystore caCerts.jks -file CA.crt
You can specify an alias as you wish. Pay attention to the password that you give when asked after executing the above command. We will use this password in the server.xml file. The same applies to the command below.
Use the following command to import a p12 format certificate into the keystore.
keytool -importkeystore -destkeystore tomcat.keystore -srckeystore -ServerCert.p12 -srcstoretype PKCS12 -alias 1
Now modify the tomcat server.xml file as follows.
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" scheme="https" secure="true" truststoreFile="path/to/truststorefile" truststorePass="password" keystoreFile="path/to/keystorefile" keystorePass="password" clientAuth="true" sslProtocol="TLS" />
Now import the client P12 format certificate into the browser. Then start the tomcat server and try to access https: // localhost: 8443 . You can find a blog for a detailed version of this answer. Hope this helps.