方案一) 生成X.509 v3 certificate with SAN(Subject Alternative Names )

注释:Starting with Chrome v58 they no longer accept certificates without SAN information.

除了上面的提示以外, 我们要的不仅仅是生成SSL certificate,而是不得不构建一个带有根证书的SSL certificate chain,

在连接一个 HTTPS 网站的时候,服务器会发送证书链,但光有证书链,客户端/浏览器是不能完成证书校验的,(客户端/浏览器)必须有一张根证书才能迭代完成签名认证,

也就是说客户端必须信任根证书才能构建信任基础。(注意中间证书则是可省的,我们构建的SSL证书链就没有)

1) 创建根证书及密钥

#create a private key
#This creates a key, 2048 bits long, The -des3 parameter specifies to use the #Tripple DES algorithm to encrypt the key
openssl genrsa -des3 -out rootCA.key 2048 
#Now to generate the root certificate:
#new: create a new request
#nodes: don’t encrypt the output key
#x509: specifies the kind of certificate to make
#key: the file with the private key to use
#sha256: this is the hashing algorithm. When you omit this it will default to the #SHA1 algorithm which will result in the browser generating a warning
#days: the number of days the certificate should be valid for. Use as high a number #as you feel comfortable with for your development environment
#out: the name of the file to write the certificate to.openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024  -out rootCA.pem

创建的过程中,会要求你题写基本信息到你的根证书里面。

我的如下:

Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:CMCM
Organizational Unit Name (eg, section) []:CM
Common Name (e.g. server FQDN or YOUR name) []:HL ROOT CA
Email Address []:499389897@qq.com

有了根证书,现在创建服务器用到的ssl证书。

2)创建服务器用的ssl证书及密钥

因为只有X.509 v3证书承载SAN信息,所以与创建X.509 v1证书时相比,它需要做更多的工作。

在同一目录下,先创建一个v3.ext文件,把下面信息放进去,alt_names下面换成你自己的域名

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = acme-site.dev
DNS.2 = www.acme-site.dev

The first step is to create a private key for the SSL certificate and a certificate signing request.

openssl req -new -nodes -out server.csr -newkey rsa:2048 -keyout server.key

同样创建服务器ssl证书也会要你填写一些基本信息,我填写如下:

Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:CMCM
Organizational Unit Name (eg, section) []:CM
Common Name (e.g. server FQDN or YOUR name) []:HL ROOT CA
Email Address []:499389897@qq.comPlease enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

3)关键步骤,根证书颁发信任给服务器ssl证书

openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

方案二)

参考资料:

https://support.citrix.com/article/CTX135602_

新建文件req.conf,内容如下:

[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = VA
L = SomeCity
O = MyCompany
OU = MyDivision
CN = www.myser.com
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = www.myser.net
DNS.2 = myser.com
DNS.3 = myser.net

注:

CN 为www.myser.com

DNS.1 设定为域名 www.myser.net
DNS.2 设定为域名 myser.com
DNS.3 设定为域名 myser.net

生成私钥和自签名证书:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt -config req.conf -sha256

三)拿到证书后,配置服务器

修改Flask中ssl的配置,指定新的私钥文件(sever.key)和证书文件(sever.crt),如下:

from flask import Flask, jsonify
import osASSETS_DIR = os.path.dirname(os.path.abspath(__file__))
app = Flask(__name__)@app.route('/')
def index():return 'Flask is running!'@app.route('/data')
def names():data = {"names": ["John", "Jacob", "Julie", "Jennifer"]}return jsonify(data)if __name__ == '__main__':context = ('server.crt', 'server.key')#certificate and key filesapp.run(debug=True, ssl_context=context)

重启服务

chrome导入根证书,作为信任链之基础

chrome安装自签名证书文件server.crt

访问服务器,证书有效,一切正常,如下图

参考文章:

https://www.jianshu.com/p/35c31b865bb9

https://medium.com/@tbusser/creating-a-browser-trusted-self-signed-ssl-certificate-2709ce43fd15

通过OpenSSL创建自签名证书在Flask实现HTTPS相关推荐

  1. Nginx通过OpenSSL创建自签名证书配置HTTPS及二级目录

    目录 配置Https Nginx配置二级目录 升级示例 部署HTTP 升级为HTTPS 配置Https Nginx通过OpenSSL配置Https及二级虚拟目录 1.创建私钥秘钥和证书 mkdir - ...

  2. OpenSSL 创建自签名证书

    1.生成服务器私钥 openssl genrsa -out client.key 4096 2.生成证书签名请求(CSR) openssl req -new -key client.key -out ...

  3. 使用OpenSSL创建自签名SSL证书

    近期的工作中遇到了数据传输加密的需求,就是在数据传输安全层面都要求使用https协议,因此为Web站点安装SSL证书就成了必须,以下就过程记录. 1.需求及选型 需求有两条: 支持内网IP地址 我们很 ...

  4. Ubuntu18.04 使用 openssl制作自签名证书

    执行"openssl verison",判断系统是否已安装openssl,若没有安装,请使用apt安装openssl. 一.图解自签名过程 二.关于 CRT PEM KEY CST ...

  5. Openssl生成自签名证书并导入浏览器脚本

    Openssl生成自签名证书并导入浏览器 使用说明 1. 准备工作 2. 脚本 3. 导入浏览器 4. 使用证书 使用说明 环境:Centos 7 运行脚本后可以生成根证书.自签名证书(可以指定域名或 ...

  6. 自签名证书和私有CA签名的证书的区别 创建自签名证书 创建私有CA 证书类型 证书扩展名

    自签名的证书无法被吊销,CA签名的证书可以被吊销 能不能吊销证书的区别在于,如果你的私钥被黑客获取,如果证书不能被吊销,则黑客可以伪装成你与用户进行通信 如果你的规划需要创建多个证书,那么使用私有CA ...

  7. VC++网络安全编程范例(2)-创建自签名证书

    数字证书采用公钥体制,即利用一对互相匹配的密钥进行加密.解密.每个用户自己设定一把特定的仅为本人所知的私有密钥(私钥),用它进行解密和签名:同时设定一把公共密钥(公钥)并由本人公开,为一组用户所共享, ...

  8. 基于 OpenSSL 生成自签名证书,数字签名,泛域名证书,ca证书,PKI等

    基于 OpenSSL 生成自签名证书_qhh0205-CSDN博客_openssl自签名证书 windows 下 nginx 双向认证自签名证书配置 windows 下 nginx 双向认证自签名证书 ...

  9. Mac如何创建自签名证书?Mac创建自签名证书图文教程

    Mac上怎么创建自签名证书?您可以使用"钥匙串访问"中的"证书助理"创建自签名证书.自签名证书不提供由证书颁发机构所签名的证书中的各种保证,但如果证书的签名人可 ...

  10. 如何在Windows上为代码签名创建自签名证书

    出自http://www.imooc.com/wenda/detail/577483 由于这篇文章搜索实在费劲,机缘巧合中才找到,为了后面课程学习方便查找,斗胆转载,侵删 慕森王 更新的答案 如果您使 ...

最新文章

  1. iOS环信聊天界面中点击头像和消息的几种状态
  2. 最小割 ---- 2021 ccpc 威海 H city-safety(最大利润 = 最大收益 - 最小花费(最小割))
  3. R语言使用apriori算法进行关联规则挖掘实战:关联规则概念、频繁项集、支持度(support)、置信度(confidence)、提升度(lift)、apriori算法
  4. 波士顿动力机器狗在工厂打工的实录火了
  5. DSP集成开发工具CCS的Git工具使用说明(一)
  6. linux_mint语言卡住,使用linux mint 16的容易死机怎么处理?
  7. 42.数据库 SQL 操作
  8. (Scrapy框架)爬虫2021年CSDN全站综合热榜标题热词 | 爬虫案例
  9. php递归函数理解,详解php递归函数
  10. JAVA计算机毕业设计学生请假管理系统Mybatis+系统+数据库+调试部署
  11. Unity3D 一些工具总结
  12. 什么是超定方程,如何解?
  13. Font Awesome 是一套绝佳的图标字体库和CSS框架
  14. mysql 取月份天数_mysql 之 获取指定月份天数和指定月份上月天数
  15. Win11电脑连网显示无internet访问权限怎么处理?
  16. 伦敦时间现在几点_英国伦敦时间现在几点钟(英国时差和中国差几个小时)
  17. 程序员如何增加收入?
  18. Android百度地图
  19. SURF C++代码 详细阅读(二)—— 极值点检测 确定极值点精确位置
  20. JAVA_HOME环境变量

热门文章

  1. 如何避免循环中丑陋的break和continue
  2. Makefile文件生成 GNU Autotools的使用方法
  3. 挑战性题目DSCT401:全源最短路径Floyd算法的并行实现
  4. CF1047A Little C Loves 3 I
  5. java mysql 博客园_JAVA基础--MySQL
  6. 怎么解Linux内核温控,Linux Thermal 框架解析
  7. java获取元素创建时间_Golang中使用Date进行日期格式化(沿用Java风格)
  8. flutter 动画json_flutter常用内置动画组件
  9. Dart教程(一):dart安装
  10. spring 配置属性细节