Https Https network self-signed certificate with Tomcat implement detailed graphic network Https

Intranet project enabled Https Configuration Guide

Software Requirements:

  1. OpenSSL https://www.openssl.org/
  2. The environment is already installed Java Jdk

 

Pre-production needs:

  1. Environment variables have been configured Jdk
  2. After installing OpenSSL configuration environment variable

 

 

 

Began making the CA root certificate

In any letter (I choose here G disk) to create a new folder here I am building a ca file folder to store the generated CA certificate

 

Create a private key

Generating a private key commands: OpenSSL genrsa--out CA / CA-1024 the key.pem

 

 

Create a certificate request

命令:openssl req -new -out ca/ca-req.csr -key ca/ca-key.pem

 

 

 

 

Generate a self-signed certificate CA

Command: OpenSSL X509 -req -IN CA / CA-req.csr -out CA / CA-cert.pem -signkey CA / CA-key.pem -days 3650 ( 10 year period)

 

 

 

Production server certificate

Generate a key with a built-in java keytool tool (123456)

命令:keytool -genkey -alias example -validity 365 -keyalg RSA -keysize 1024 -keypass 123456 -storepass 123456 -keystore example.jks

 

 

 

 

Generate a certificate request with the keytool tool (certificate name is related to the example)

命令:keytool -certreq -alias example -sigalg MD5withRSA -file example.csr -keypass 123456 -keystore example.jks -storepass 123456

 

 

 

根据证书请求,用CA签证,生成服务器证书

命令:openssl x509 -req -in example.csr -out example.pem -CA ca/ca-cert.pem -CAkey ca/ca-key.pem -days 365 -set_serial 1

 

 

 

 

向 本地keystore 密钥库中导入证书

命令:keytool -import -v -trustcacerts -keypass 123456 -storepass 123456 -alias root -file ca/ca-cert.pem -keystore example.jks

 

 

 

导入服务器证书

命令:keytool -import -v -trustcacerts -storepass 123456 -alias example -file example.pem -keystore example.jks

 

 

单独导出 CA 作为信任证书

命令:keytool -import -alias example-ca -trustcacerts -file ca/ca-cert.pem -keystore exampletrust.jks

 

这里输入的密码是:123456 证书的密码

 

查看生成的文件

 

 

客户端安装证书:

命令:openssl pkcs12 -export -clcerts -in ca/ca-cert.pem -inkey ca/ca-key.pem -out ca/ca.p12

 

 

 

 

这里输入的密码是 123456(证书密码)

查看生成证书:ca文件夹下面

 

ca.p12文件就是生成的证书

双击打开导入——》当前用户——》下一步——》输入密码(123456)——》

打开ie浏览器,在 internet 选项``内容中清除ssl状态,重启浏览器再重新访问,就不会再有不信任的提示。

 

 

 

 

点击下一步完成即可!

Tomcat 服务器导入证书

首先复制刚才生成的那两个文件:

 

复制到tomcate 目录下面:例如放到conf文件夹下

 

 

打开server.xml文件 复制下面内容到指定位置:

复制内容:

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"

      maxThreads="250" scheme="https" secure="true"

      clientAuth="false" sslProtocol="TLS" keystoreFile="conf/example.jks"

      keystorePass = "123456" truststoreFile="conf/exampletrust.jks"

      truststorePass="123456"/>

 

 

 

放置位置:(注意放置位置一定要对!!!!!)

 

说明:123456表示的是证书密码  443是https默认端口

 

修改默认的http端口和https端口

默认Tomcat HTTP端口8080 HTTPS默认端口8443

 

修改下列位置8080——》80      8443——》443

 

 

=-------------------------------------------

 

强制使用Https

打开conf文件夹下面的web.xml(文件尾部!!!!)  添加以下代码到指定位置

 

 

 

<security-constraint>

        <web-resource-collection>

            <web-resource-name>SSL</web-resource-name>

            <url-pattern>/*</url-pattern>

        </web-resource-collection>

        <user-data-constraint>

            <transport-guarantee>CONFIDENTIAL</transport-guarantee>

        </user-data-constraint>

    </security-constraint>

 

 

最终效果

 

 

 

谷歌:

 

 

IE

 

 

参考博客:https://blog.csdn.net/byg184244735/article/details/85071877

 

Guess you like

Origin www.cnblogs.com/ChromeT/p/11122480.html