一、前言

  建立客户端与服务器的Https的连接需要证书进行双向验证后,才可访问。

 

二、证书类型

不同数字证书部署在服务器上后,用户浏览器访问网站时,展示如下:

1、无证书时

显示不安全标识。

2、域名型(DV)SSL

可以显示安全连接标识,证书无法显示组织信息。

 

3、企业型(OV)SSL

可以显示安全连接标识,证书详细内显示组织信息。

4、增强型(EV)SSL

地址栏绿色,可以显示安全连接标识,地址栏直接显示组织信息。

三、生成SSL证书

  证书的创建与作用

  生成环境:

      Linux: CentOS_7(及以上)

      Tomcat: Apache Tomcat_8.5.42(及以上)

      OpenSSL: OpenSSL 1.1.0c 下载路径:https://www.openssl.org/source/openssl-1.1.0c.tar.gz

  • 制作服务器根证书

  1.解压安装

    

#解压tar包
tar -xzvf openssl-1.1.0c.tar.gz #进入加压后的文件夹内
cd openssl-1.1.0c #安装openssl到 /usr/local/openssl 目录,安装之后,编译;这个时候执行需要有耐心,可以查看命令行一直在滚屏,等到滚屏结束,安装编译完成
./config --prefix=/usr/local/openssl && make && make install #重命名
mv /usr/bin/openssl /usr/bin/openssl.ori
mv /usr/include/openssl /usr/include/openssl.ori #将安装好的openssl命令软连到对应位置
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl #在/etc/ld.so.conf文件中写入openssl库文件的搜索路径
echo /usr/local/openssl/lib >> /etc/ld.so.conf ldconfig -v openssl version -a

 

  2.生成证书

    2.1 创建根证书密钥文件(自己做CA) root.key

#生成命令
openssl genrsa -des3 -out root.key 2048 #输出日志
Generating RSA private key, 2048 bit long modulus
.....................................................................................................................+++
..........................+++
e is 65537 (0x010001)
Enter pass phrase for root.key: ← #在这输入一个新密码
Verifying – Enter pass phrase for root.key: ← 在这重新输入一遍密码

    

    2.2 创建根证书的申请文件 root.csr

#生成命令
openssl req -new -key root.key -out root.csr #输出日志
Enter pass phrase for root.key: ← 在这输入前面创建的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address []:admin@mycompany.com ← 电子邮箱,可随意填 Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入

 

    2.3 创建一个自当前日期起为期十年的根证书 root.crt

#生成命令
openssl x509 -req -days 3650 -sha256 -extfile /usr/local/openssl/ssl/openssl.cnf -extensions v3_ca -signkey root.key -in root.csr -out root.crt #输出日志
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./emailAddress=admin@mycompany.com
Getting Private key
Enter pass phrase for root.key: ← 在这输入前面创建的密码

      

    2.4 根据CA证书生成truststore JKS文件 root.truststore

      这一步只针对双向认证,单向不需要

#生成命令
keytool -keystore root.truststore -keypass 123456 -storepass 123456 -alias ca -import -trustcacerts -file /tmp/ca/root.crt

 #键入回车后,提示是否信任此证书,输入yes, 则生成truststore成功

  • 制作service服务器端证书

1.创建服务器证书密钥 server.key

#生成命令
openssl genrsa -des3 -out server.key 2048 #输出内容为:
Generating RSA private key, 2048 bit long modulus
...........................+++
...............+++
e is 65537 (0x010001)
Enter pass phrase for server.key: ←在这输入前面创建的密码
Verifying - Enter pass phrase for server.key: ← 在这重新输入一遍密码 #运行时会提示输入密码,此密码用于加密key文件(参数des3便是指加密算法,当然也可以选用其他你认为安全的算法.),以后每当需读取此文件(通过openssl提供的命令或API)都需输入口令(密码).如果觉得不方便,也可以去除这个口令,但一定要采取其他的保护措施! #去除口令的命令
openssl rsa -in server.key -out server.key

2.创建服务器证书的申请文件 server.csr

#生成命令
openssl req -new -key server.key -out server.csr #输出内容为:
Enter pass phrase for server.key: ← 输入前面创建的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [AU]:CN ← 国家名称,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省名,拼音
Locality Name (eg, city) []:BeiJing ← 市名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []:www.xxx.com ← 服务器主机名(或者IP),若填写不正确,浏览器会报告证书无效,但并不影响使用
Email Address []:admin@mycompany.com ← 电子邮箱,可随便填 Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入

 

3.创建自当前日期起有效期为期十年的服务器证书 server.crt

#生成命令
openssl x509 -req -days 3650 -sha256 -extfile /usr/local/openssl/ssl/openssl.cnf -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in server.csr -out server.crt #输出内容为:
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./CN=www.mycompany.com/emailAddress=admin@mycompany.com
Getting CA Private Key
Enter pass phrase for root.key: ← 输入前面创建的密码

4.导出.p12文件 server.p12

#生成命令
openssl pkcs12 -export -in /tmp/ca/server.crt -inkey /tmp/ca/server.key -out /tmp/ca/server.p12 -name "server" 根据命令提示,输入server.key密码,创建p12密码。

5.将.p12 文件导入到keystore JKS文件 server.keystore

#生成命令
keytool -importkeystore -v -srckeystore /tmp/ca/server.p12 -srcstoretype pkcs12 -srcstorepass 123456 -destkeystore /tmp/ca/server.keystore -deststoretype jks -deststorepass 123456 这里srcstorepass后面的123456为server.p12的密码deststorepass后的123456为keyStore的密码
  • 制作Client客户端证书

1.创建客户端证书密钥文件 client.key

#生成命令
openssl genrsa -des3 -out client.key 2048 #输出内容为:
Generating RSA private key, 2048 bit long modulus
...............................+++
.........................+++
e is 65537 (0x010001)
Enter pass phrase for client.key: ← 输入新密码
Verifying – Enter pass phrase for client.key: ← 重新输入一遍密码

2.创建客户端证书的申请文件 client.csr

#生成命令
openssl req -new -key client.key -out client.csr #输出内容为:
Enter pass phrase for client.key: ← 输入上一步中创建的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [AU]:CN ← 国家名称,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省名称,拼音
Locality Name (eg, city) []:BeiJing ← 市名称,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不填
Common Name (eg, YOUR name) []:Lenin ← 自己的英文名,可以随便填
Email Address []:admin@mycompany.com ← 电子邮箱,可以随便填 Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不填
An optional company name []: ← 可以不填

3.创建一个自当前日期起有效期为十年的客户端证书 client.crt

#生成命令
openssl x509 -req -days 3650 -sha256 -extfile /usr/local/openssl/ssl/openssl.cnf -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in client.csr -out client.crt #输出内容为:
Signature ok
subject=/C=CN/ST=BeiJing/L=BeiJing/O=MyCompany Corp./CN=www.mycompany.com/emailAddress=admin@mycompany.com
Getting CA Private Key
Enter pass phrase for root.key: ← 输入上面创建的密码

4.导出.p12文件 client.p12

#生成命令
openssl pkcs12 -export -in /tmp/ca/client.crt -inkey /tmp/ca/client.key -out /tmp/ca/client.p12 -name "client" 根据命令提示,输入client.key密码,创建p12密码。

四、配置Tomcat

1.关闭tomcat

tomcat的bin目录下执行

shutdown.sh

2.将证书放入web服务器

 #将keystore文件(server.keystore) 放在web服务器上

cp /tmp/ca/server.keystore /你的tomcat根目录/conf

  #将truststore文件(root.truststore) 放在web服务器上

cp /tmp/ca/root.truststore /你的tomcat根目录/conf

3.修改server.xml配置文件

cd /你的tomcat根目录/conf

vi server.xml

找到下面被注释的代码,删除注释符并修改内容(vi命令操作)

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="/你的路径/apache-tomcat-8.5.42/conf/server.keystore"
keystorePass="******"
truststoreFile="/你的路径/apache-tomcat-8.5.42/conf/root.truststore"
truststorePass="******"
clientAuth="false" sslEnabledProtocols="TLSv1.2"
/> <!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8011" protocol="AJP/1.3" redirectPort="8443" />

4.启动tomcat

tomcat的bin目录下执行

startup.sh

5.访问https服务

测试访问连接

https://localhost:8443/

https://192.168.1.1:8443/  你的IP

Https:创建部署SSL证书进行双向认证的更多相关文章

  1. SSL使用windows证书库中证书实现双向认证

    前一段时间对OpenSSL库中的SSL通讯稍微琢磨了一下,在百度文库中找了个示例程序,然后在机器上跑,哇塞,运行成功!那时那个惊喜啊,SSL蛮简单的嘛.前几天,老板要我整一个SSL通讯,要使用wind ...

  2. 在IIS下部署SSL证书实现HTTPS

    在IIS下部署SSL证书实现HTTPS   HTTPS是以安全为目标的HTTP通道,简单讲是HTTP的安全版.谷歌已经制定了一项长远的计划,它的最终目标是将所有通过HTTP协议呈现的网页标为“不安全” ...

  3. 基于SSL协议的双向认证 - 双向认证 [3]

    1      SSL双向认证的实现 这里是基于SSL和Tomcat配置实现的,配置方法如下: 1.1    生成CA数字证书 首先需要配置OPENSSL环境变量. 我的OPENSSL配置文件路径是“D ...

  4. Centos 7 环境下,如何使用 Apache 实现 SSL 虚拟主机 双向认证 的详细教程:

    1. testing ! ... 1 1 原文参考链接: http://showerlee.blog.51cto.com/2047005/1266712 很久没有更新LAMP的相关文档了,刚好最近单位 ...

  5. 让网站永久拥有HTTPS - 申请免费SSL证书并自动续期 Let’s Encrypt

    让网站永久拥有HTTPS - 申请免费SSL证书并自动续期 Let’s Encrypt 为什么要用HTTPS  网站没有使用HTTPS的时候,浏览器一般会报不安全,而且在别人访问这个网站的时候,很有可 ...

  6. Requests对HTTPS请求验证SSL证书

    SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socket layer(SSL)安全协议是由Netscape Communication公司设计开发.该安全协议主 ...

  7. Resin 4.0 部署SSL证书

    前言 Resin目前最新的版本还是4.0 (4.0.49),使用Java EE6,在Resin上部署证书,一般有两种方式,首先我们推荐采用Openssl方式,不仅因为Openssl模式下的速度更快,而 ...

  8. Tomcat部署SSL证书过程中遇到的问题

    在CentOS7中Tomcat部署SSL证书时遇到的问题 1.配置servlet.xml 配置tomcat/conf/server.xml 加入以下代码 <Connector port=&quo ...

  9. CentOS系统Tomcat 8.5或9部署SSL证书

    本文档介绍了CentOS系统下Tomcat 8.5或9部署SSL证书的操作说明. 环境准备 操作系统:CentOS 7.6 64位 Web服务器:Tomcat 8.5或9 前提条件 已从阿里云SSL证 ...

随机推荐

  1. SpringBoot 上传文件如何获取项目工程路径

    上传文件时,需要将上传的文件存放于工程路径中,以便前端能够获取文件资源,那如何获取工程路径呢? //获取 SpringBoot 工程中 static 的绝对路径 String serverpath= ...

  2. origin2018去掉demo水印

    消除demo字样 有的origin破解完成后,使用没问题,但导出的图有demo水印.其实不需要重装,只需要下载一个补丁即可解决. 1. 把下载到的origin.exe复制到安装文件夹 2. 双击执行一 ...

  3. 压力测试工具JMeter简单使用

    场景:项目上线前自测服务器抗压能力or提供数据给品牌方展示 注意:测试单台机器不要使用很大的线程.每台机器的配置不同,"聚合报告"中的Error也不同. 如:20000线程请求,1 ...

  4. 使用vue-cli 来创建vue项目

    前置条件 需要安装node环境 安装vue\cli工具 vue\cli官网 传送门 vue-cli 安装node.js nodejs中文网 点击之后会发现这个界面 可以点击下载或者选择其他版本的包,尽 ...

  5. 菜鸟刷题路:剑指 Offer 09. 用两个栈实现队列

    剑指 Offer 09. 用两个栈实现队列 用两个栈实现一个队列.队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的 ...

  6. 1、java语言概述

    Java基础知识图解 软件开发 软件开发 软件,即一系列按照特定顺序组织的计算机数据和指令的集合.有系统软件和应用软件之分. 人机交互方式 图形化界面(Graphical User Interface ...

  7. 基于Docker安装常用软件

    基于Docker安装常用软件 本实验介绍如何基于Docker安装常用的软件,具体包括: Ubuntu Cetnos Nginx Node.js PHP MySQL Tomcat Redis Mongo ...

  8. 【VBA】模块更新方法

    删除模块,重新导入 1 Sub 更新模块() 2 With ThisWorkbook.VBProject 3 .VBComponents.Remove .VBComponents("模块1& ...

  9. 【题解】逐个击破 luogu2700

    题目 题目描述: 现在有N个城市,其中K个被敌方军团占领了,N个城市间有N-1条公路相连,破坏其中某条公路的代价是已知的. 现在,告诉你K个敌方军团所在的城市,以及所有公路破坏的代价,请你算出花费最少 ...

  10. 教你用python搭建一个「生活常识解答」机器人

    今天教大家如何用Python爬虫去搭建一个「生活常识解答」机器人. 思路:这个机器人主要是依托于"阿里达摩院发布的语言模型PLUG",通过爬虫的方式,发送post请求(提问),然后 ...