如何制作SSL证书即https服务支持
如何制作SSL证书即https服务支持
目的
最近需要做个网站,支持https的访问,但是,是内部使用的,不需要对外网开放。
基础知识
在制作之前先了解一下OpenSSL、HTTPS的关系。见https://www.qikegu.com/docs/2632,对SSL工作原理部分讲得比较清楚了。
再补充一点SSL证书的知识
https://zhuanlan.zhihu.com/p/371891073
通过以上的学习,基本可以了解了,要完成这个功能,必须制作出如下证书:
- CA根证书
- CA中间证书
- 网站证书
制作过程
国内的制作说明很多,但是,基本都是制作出CA后,直接自签名网站的。并且相关的OPENSSL的配置也很少说明,感觉文档都写得不够完整,因此,起初制作的证书,基本都嗝屁了。也可能是我个人的问题。
看到一篇老外的教程:
https://jamielinux.com/docs/openssl-certificate-authority/create-the-root-pair.html
按照他的介绍制作出了所需要的全部证书。但是,在实际应用时,还是报了一些问题,比如出现网站的证书出现无法认证等问题。以下稍微介绍说明下,这个老外的制作过程及注意情况。制作全程root权限。
CA证书制作
# mkdir /root/ca
# cd /root/ca
# mkdir certs crl newcerts private
# chmod 700 private
# touch index.txt
# echo 1000 > serial
准备CA的配置文件 /root/ca/openssl.cnf
# OpenSSL root CA configuration file.
# Copy to `/root/ca/openssl.cnf`.[ ca ]
# `man ca`
default_ca = CA_default[ CA_default ]
# Directory and file locations.
dir = /root/ca
certs = $dir/certs
crl_dir = $dir/crl
new_certs_dir = $dir/newcerts
database = $dir/index.txt
serial = $dir/serial
RANDFILE = $dir/private/.rand# The root key and root certificate.
private_key = $dir/private/ca.key.pem
certificate = $dir/certs/ca.cert.pem# For certificate revocation lists.
crlnumber = $dir/crlnumber
crl = $dir/crl/ca.crl.pem
crl_extensions = crl_ext
default_crl_days = 30# SHA-1 is deprecated, so use SHA-2 instead.
default_md = sha256name_opt = ca_default
cert_opt = ca_default
default_days = 375
preserve = no
policy = policy_strict[ policy_strict ]
# The root CA should only sign intermediate certificates that match.
# See the POLICY FORMAT section of `man ca`.
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional[ policy_loose ]
# Allow the intermediate CA to sign a more diverse range of certificates.
# See the POLICY FORMAT section of the `ca` man page.
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional[ req ]
# Options for the `req` tool (`man req`).
default_bits = 2048
distinguished_name = req_distinguished_name
string_mask = utf8only# SHA-1 is deprecated, so use SHA-2 instead.
default_md = sha256# Extension to add when the -x509 option is used.
x509_extensions = v3_ca[ req_distinguished_name ]
# See <https://en.wikipedia.org/wiki/Certificate_signing_request>.
countryName = Country Name (2 letter code)
stateOrProvinceName = State or Province Name
localityName = Locality Name
0.organizationName = Organization Name
organizationalUnitName = Organizational Unit Name
commonName = Common Name
emailAddress = Email Address# Optionally, specify some defaults.
countryName_default = GB
stateOrProvinceName_default = England
localityName_default =
0.organizationName_default = Alice Ltd
organizationalUnitName_default =
emailAddress_default =[ v3_ca ]
# Extensions for a typical CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign[ v3_intermediate_ca ]
# Extensions for a typical intermediate CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, digitalSignature, cRLSign, keyCertSign[ usr_cert ]
# Extensions for client certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = client, email
nsComment = "OpenSSL Generated Client Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth, emailProtection[ server_cert ]
# Extensions for server certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth[ crl_ext ]
# Extension for CRLs (`man x509v3_config`).
authorityKeyIdentifier=keyid:always[ ocsp ]
# Extension for OCSP signing certificates (`man ocsp`).
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, digitalSignature
extendedKeyUsage = critical, OCSPSigning
生成密钥
# cd /root/ca
# openssl genrsa -aes256 -out private/ca.key.pem 4096Enter pass phrase for ca.key.pem: secretpassword
Verifying - Enter pass phrase for ca.key.pem: secretpassword# chmod 400 private/ca.key.pem
生成CA证书
# cd /root/ca
# openssl req -config openssl.cnf \-key private/ca.key.pem \-new -x509 -days 7300 -sha256 -extensions v3_ca \-out certs/ca.cert.pemEnter pass phrase for ca.key.pem: secretpassword
You are about to be asked to enter information that will be incorporated
into your certificate request.
-----
Country Name (2 letter code) [XX]:GB
State or Province Name []:England
Locality Name []:
Organization Name []:Alice Ltd
Organizational Unit Name []:Alice Ltd Certificate Authority
Common Name []:Alice Ltd Root CA
Email Address []:# chmod 444 certs/ca.cert.pem
这里要特别注意起名字,不要乱起 Organization Name 还有Country Name 等。
验证CA证书
# openssl x509 -noout -text -in certs/ca.cert.pem
中间证书
制作中间证书基本与制作CA证书是一样的。不过,openssl的配置是不同的。
中间证书配置,放到 /root/ca/intermediate/openssl.cnf
# OpenSSL intermediate CA configuration file.
# Copy to `/root/ca/intermediate/openssl.cnf`.[ ca ]
# `man ca`
default_ca = CA_default[ CA_default ]
# Directory and file locations.
dir = /root/ca/intermediate
certs = $dir/certs
crl_dir = $dir/crl
new_certs_dir = $dir/newcerts
database = $dir/index.txt
serial = $dir/serial
RANDFILE = $dir/private/.rand# The root key and root certificate.
private_key = $dir/private/intermediate.key.pem
certificate = $dir/certs/intermediate.cert.pem# For certificate revocation lists.
crlnumber = $dir/crlnumber
crl = $dir/crl/intermediate.crl.pem
crl_extensions = crl_ext
default_crl_days = 30# SHA-1 is deprecated, so use SHA-2 instead.
default_md = sha256name_opt = ca_default
cert_opt = ca_default
default_days = 375
preserve = no
policy = policy_loose[ policy_strict ]
# The root CA should only sign intermediate certificates that match.
# See the POLICY FORMAT section of `man ca`.
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional[ policy_loose ]
# Allow the intermediate CA to sign a more diverse range of certificates.
# See the POLICY FORMAT section of the `ca` man page.
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional[ req ]
# Options for the `req` tool (`man req`).
default_bits = 2048
distinguished_name = req_distinguished_name
string_mask = utf8only# SHA-1 is deprecated, so use SHA-2 instead.
default_md = sha256# Extension to add when the -x509 option is used.
x509_extensions = v3_ca[ req_distinguished_name ]
# See <https://en.wikipedia.org/wiki/Certificate_signing_request>.
countryName = Country Name (2 letter code)
stateOrProvinceName = State or Province Name
localityName = Locality Name
0.organizationName = Organization Name
organizationalUnitName = Organizational Unit Name
commonName = Common Name
emailAddress = Email Address# Optionally, specify some defaults.
countryName_default = GB
stateOrProvinceName_default = England
localityName_default =
0.organizationName_default = Alice Ltd
organizationalUnitName_default =
emailAddress_default =[ v3_ca ]
# Extensions for a typical CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign[ v3_intermediate_ca ]
# Extensions for a typical intermediate CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, digitalSignature, cRLSign, keyCertSign[ usr_cert ]
# Extensions for client certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = client, email
nsComment = "OpenSSL Generated Client Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth, emailProtection[ server_cert ]
# Extensions for server certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth[ crl_ext ]
# Extension for CRLs (`man x509v3_config`).
authorityKeyIdentifier=keyid:always[ ocsp ]
# Extension for OCSP signing certificates (`man ocsp`).
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, digitalSignature
extendedKeyUsage = critical, OCSPSigning
# mkdir /root/ca/intermediate
# cd /root/ca/intermediate
# mkdir certs crl csr newcerts private
# chmod 700 private
# touch index.txt
# echo 1000 > serial
# echo 1000 > /root/ca/intermediate/crlnumber
创建密钥
# cd /root/ca
# openssl genrsa -aes256 \-out intermediate/private/intermediate.key.pem 4096Enter pass phrase for intermediate.key.pem: secretpassword
Verifying - Enter pass phrase for intermediate.key.pem: secretpassword# chmod 400 intermediate/private/intermediate.key.pem
自签名中间证书申请文件, 要注意Organization Name 要与CA的相同
# cd /root/ca
# openssl req -config intermediate/openssl.cnf -new -sha256 \-key intermediate/private/intermediate.key.pem \-out intermediate/csr/intermediate.csr.pemEnter pass phrase for intermediate.key.pem: secretpassword
You are about to be asked to enter information that will be incorporated
into your certificate request.
-----
Country Name (2 letter code) [XX]:GB
State or Province Name []:England
Locality Name []:
Organization Name []:Alice Ltd
Organizational Unit Name []:Alice Ltd Certificate Authority
Common Name []:Alice Ltd Intermediate CA
Email Address []:
用CA去签名中间证书的申请文件 csr
# cd /root/ca
# openssl ca -config openssl.cnf -extensions v3_intermediate_ca \-days 3650 -notext -md sha256 \-in intermediate/csr/intermediate.csr.pem \-out intermediate/certs/intermediate.cert.pemEnter pass phrase for ca.key.pem: secretpassword
Sign the certificate? [y/n]: y# chmod 444 intermediate/certs/intermediate.cert.pem
验证一下生成的证书,如果不放心的话
# openssl x509 -noout -text \-in intermediate/certs/intermediate.cert.pem
# openssl verify -CAfile certs/ca.cert.pem \intermediate/certs/intermediate.cert.pemintermediate.cert.pem: OK
如果有必要的话,生成证书链。没必要就算了。
# cat intermediate/certs/intermediate.cert.pem \certs/ca.cert.pem > intermediate/certs/ca-chain.cert.pem
# chmod 444 intermediate/certs/ca-chain.cert.pem
制作网站证书
这个是重点,出问题最多的就是这里。
生成密钥, 不要带 -aes256
参数.
# cd /root/ca
# openssl genrsa \-out intermediate/private/www.example.com.key.pem 2048
# chmod 400 intermediate/private/www.example.com.key.pem
制作网站的SSL申请文件csr, 注意,一定要加上subjectAltName!!!
# cd /root/ca
# openssl req -config intermediate/openssl.cnf \-key intermediate/private/www.example.com.key.pem \-new -sha256 -out intermediate/csr/www.example.com.csr.pem \-addext "subjectAltName = IP:127.0.0.1,DNS:*.cct.com"Enter pass phrase for www.example.com.key.pem: secretpassword
You are about to be asked to enter information that will be incorporated
into your certificate request.
-----
Country Name (2 letter code) [XX]:US
State or Province Name []:California
Locality Name []:Mountain View
Organization Name []:Alice Ltd
Organizational Unit Name []:Alice Ltd Web Services
Common Name []:www.example.com
Email Address []:
可以用如下命令看是否有生成subjectAltName的申请
# openssl req -noout -text -in intermediate/csr/www.example.com.csr.pem
一定要看到这个
Requested Extensions:X509v3 Subject Alternative Name:IP Address:127.0.0.1, DNS:*.cct.com
接下来是认证,需要修改中间证书的 openssl.conf
[ server_cert ]
# Extensions for server certificates (`man x509v3_config`).
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = IP:127.0.0.1,DNS:*.cct.com
其中 subjectAltName 是新增的。
再用中间证书签名网站申请文件生成网站证书
# cd /root/ca
# openssl ca -config intermediate/openssl.cnf \-extensions server_cert -days 375 -notext -md sha256 \-in intermediate/csr/www.example.com.csr.pem \-out intermediate/certs/www.example.com.cert.pem
# chmod 444 intermediate/certs/www.example.com.cert.pem
验证证书信息
# openssl x509 -noout -text -in intermediate/certs/www.example.com.cert.pem
一定要看到
X509v3 Subject Alternative Name:IP Address:127.0.0.1, DNS:*.cct.com
就说明添加 subjectAltName 成功了。
最终成果
最终,得到了如下有用的证书及网站私钥文件
# cd /root/ca
# find
./certs/ca.cert.pem # 根证书
./intermediate/private/www.example.com.key.pem # 网站密钥
./intermediate/certs/intermediate.cert.pem # 中间证书
./intermediate/certs/www.example.com.cert.pem # 网站证书
./intermediate/certs/ca-chain.cert.pem # 证书链
证书验证
安装 nginx 进行验证
nginx在/etc/nginx/sites-enabled
下新建 127.0.0.1 文件,文件内容
server {listen 443 ssl;server_name 127.0.0.1;root /var/www/html;index index.html index.htm;ssl_certificate /home/chenct/myssl/127.0.0.1.cert.pem;ssl_certificate_key /home/chenct/myssl/127.0.0.1.key.pem;ssl_session_timeout 5m;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers on;
}
特别声明
感谢开源大佬的奉献,本说明仅作一点点实战补充。
如何制作SSL证书即https服务支持相关推荐
- 配置 腾讯云 SSL 证书 SSL证书实现https,环境:phpStudy下Apache环境
微信小程序开发交流qq群 581478349 承接微信小程序开发.扫码加微信. 正文: SSL证书实现https,环境:phpStudy下Apache环境 前提条件: 1.申请并下载好腾讯云 ...
- Mac 上制作 SSL 证书
前言 我们在开发 https 服务时,需要引入相应的 SSL 证书. 今天,我就自己在 Mac 上制作 SSL 证书的过程做个记录. 环境 MacOS 10.15.7 工具 openssl 步骤 第一 ...
- 赛门铁克Symantec SSL证书产品及服务
赛门铁克Symantec SSL证书产品及服务 在SSL证书市场,Symantec证书在全球具有绝对领先地位: 世界500强企业中93%的公司选择了赛门铁克Symantec的SSL证书服务: 世界10 ...
- SSL证书与Https应用部署小结(转发)
为了提高网站的安全性,一般会在比较敏感的部分页面采用https传输,比如注册.登录.控制台等.像Gmail.网银等全部采用https传输. https/ssl 主要起到两个作用:网站认证.内容加密传输 ...
- php iis6 安装ssl证书,在IIS下部署SSL证书实现HTTPS
HTTPS是以安全为目标的HTTP通道,简单讲是HTTP的安全版.谷歌已经制定了一项长远的计划,它的最终目标是将所有通过HTTP协议呈现的网页标为"不安全",对于站长来说,部署SS ...
- IIS配置SSL证书实现https
.net项目,http升级为https,分为两种情况:1.有域名 2.无域名,网站通过ip访问 有域名 大多数网站是这种情况,通过域名访问系统,有域名就可以去腾讯云或者其他云平台申请经过CA认证的SS ...
- Linux系统下安装minio并设置SSL证书进行HTTPS远程连接访问
下载minio并且设置权限 创建一个文件夹用于保存下载的minio mkdir /usr/local/minio 在创建的文件夹中用wget下载Linux版本的minio服务端 wget https: ...
- 最新阿里云服务器免费SSL证书配置HTTPS的两种方法(图文教程二)
在大家学习如何利用免费SSL证书配置网站HTTPS之前,我们先要搞清楚为什么要开启HTTPS,这个绿色的小锁真的有用吗?所谓的HTTPS其实是(安全套接字层超文本传输协议)是以安全为目标的HTTP通道 ...
- windows配置NGINX、NGINX配置SSL证书通过HTTPS访问、使用HTTPS通过NGINX代理访问服务器端项目
1.windows配置nginx 1)在nginx官网下载稳定版nginx,nginx官网:http://nginx.org/en/download.html 2)解压文件,注:存放目录最好不要带有中 ...
最新文章
- node中的流的介绍(Stream)
- 游戏开发者需要注意的4个内存使用问题
- iotop--补齐系统监视工具缺失的一环
- 2阶节IIR算法C语言源码
- oracle关于时区,关于oracle时区
- Linux 常用开关机以及7个启动级别
- java比对文本文件_Java编程实现比对两个文本文件并标记相同与不同之处的方法...
- python枚举类型_Python 的枚举类型
- openstack ha 部署
- 我的世界java版海岛种子_我的世界海岛生存种子,是出生在海岛不是找的那种。...
- GIS招聘 | 辽宁省省直事业单位(含测绘、地信等专业岗位)
- 加糖加冰加牛奶——装饰模式
- 学生个人网页设计作品 HTML+CSS+JavaScript仿小米商城(8页) 学生个人网页模板 简单个人主页成品 个人网页制作 HTML学生个人网站作业设计代做
- 腾讯云服务器配置jre、jdk、tomcat
- 前端校验还是后端校验
- html图片定位坐标原点,利用CSS定位背景图片的常用方法总结
- Python机器学习基础
- 关于圆周卷积和fft求卷积的一些看法
- 基尔霍夫电流定律KCL和基尔霍夫电压定律KVL
- unity3d:ugui 长按按钮
热门文章
- 最新阿里、腾讯、华为、字节跳动等大厂的薪资和职级对比
- kaggle竞赛 使用TPU对104种花朵进行分类 第二十一次尝试 99.9%准确率 中文注释【深度学习TPU+Keras+Tensorflow+EfficientNetB7】
- ArchLinux开发环境第2辑——高效平铺式桌面i3个性化配置与美化
- 水电站经济运行模型建立
- 如何快速将pdf转换excel转换
- 晴天科技冲刺上市:实控人丁一波系本科肄业,粤民投为其股东
- LeetCode #378 JavaScript
- 我现在是CodeGear公司的员工了
- x3850X5如何添加CPU和QPI Wrap Card及两节点配置说明
- 《MATLAB智能算法30个案例》:第27章 无导师学习神经网络的分类——矿井突水水源判别