OpenSSL自签发CA证书chrome浏览器安全访问

前言


接到这样一个需求:内网通过IP地址访问某系统,需要使用 https,而且不能有不安全的提示,如下图:

1653383297338

不允许这样的情况存在,这就需要使用 openssl 进行自签解决。


OpenSSL 自签证书


安装 openssl

yum install openssl openssl-devel -y
mkdir -pv /etc/ssl/private

使用openssl 生成 SSL key 和 CSR

cd /etc/ssl/private/
openssl req -new -newkey rsa:2048 -sha256 -nodes -out 192.168.199.104.csr -keyout 192.168.199.104.key -subj "/C=CN/ST=Beijing/L=Beijing/O=Super Inc./OU=Web Security/CN=192.168.199.104"

openssl x509 -req -days 365 -in 192.168.199.104.csr -signkey 192.168.199.104.key -out 192.168.199.104.crt

1653384872415


配置nginx支持 ssl

1653384768725

nginx -t
nginx -s reload

chrome 添加信任证书

将上面生成的 192.168.199.104.crt 拷贝到 windows 并导入 chrome

chrome -> 设置 -> 隐私设置和安全性 -> 管理证书 -> 导入

1653385007556


chrome 浏览器导入证书访问:

1653385060532


火狐 浏览器导入证书访问:

1653385228295

因此,这里对 chrome 浏览器需要做特殊的操作:

首先删除之前导入的证书

1653385300834


添加附加用途

解决Chrome不能识别证书通用名称NET::ERR_CERT_COMMON_NAME_INVALID错误

[root@nginx(192.168.199.104) ~]#cd /etc/ssl/private/
[root@nginx(192.168.199.104) /etc/ssl/private]#ls
192.168.199.104.crt  192.168.199.104.csr  192.168.199.104.key
[root@nginx(192.168.199.104) /etc/ssl/private]#rm -rf *

//添加如下文件
[root@nginx(192.168.199.104) /etc/ssl/private]#vim http.ext
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName=@SubjectAlternativeName

[ SubjectAlternativeName ]
IP.1=127.0.0.1
IP.2=192.168.199.104	# 内网访问的IP地址


[root@nginx(192.168.199.104) /etc/ssl/private]#openssl req -new -newkey rsa:2048 -sha256 -nodes -out 192.168.199.104.csr -keyout 192.168.199.104.key -subj "/C=CN/ST=Beijing/L=Beijing/O=Super Inc./OU=Web Security/CN=192.168.199.104"

[root@nginx(192.168.199.104) /etc/ssl/private]#openssl x509 -req -days 365 -in 192.168.199.104.csr -signkey 192.168.199.104.key -out 192.168.199.104.crt -extfile http.ext

然后再次将 192.168.199.104.crt 下载到 window 导入 chrome 。

注意:这里需要重新载入下 nginx,清空下 chrome 的缓存,再次启动。

1653386013219

这样就解决了,chrome 自签ssl证书不安全链接的问题。



总结


(1)chrome 需要添加附属文件

IP地址访问:

[root@nginx(192.168.199.104) /etc/ssl/private]#cat http.ext
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName=@SubjectAlternativeName

[ SubjectAlternativeName ]
IP.1=127.0.0.1
IP.2=192.168.199.104

域名访问:

[root@nginx(192.168.199.104) /etc/ssl/private]#cat http.ext
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName=@SubjectAlternativeName

[ SubjectAlternativeName ]
DNS.1=super.com
DNS.2=www.super.com

(2)两条命令生成证书

openssl req -new -newkey rsa:2048 -sha256 -nodes -out 192.168.199.104.csr -keyout 192.168.199.104.key -subj "/C=CN/ST=Beijing/L=Beijing/O=Super Inc./OU=Web Security/CN=192.168.199.104"

openssl x509 -req -days 365 -in 192.168.199.104.csr -signkey 192.168.199.104.key -out 192.168.199.104.crt -extfile http.ext

(3)将 192.168.199.104.crt 导入到 chrome 受信任的根证书颁发机构

1653386253723

(4)重载 nginx 并清除 chrome 缓存访问。

1653386297761

posted @ 2022-05-24 18:02  hukey  阅读(5595)  评论(0编辑  收藏  举报