当前位置: 首页 > news >正文

openssl双向认证自签名证书生成

编写配置文件openssl.cnf

[ req ]
distinguished_name = req_distinguished_name
req_extensions     = req_ext[ req_distinguished_name ]
countryName            = Country Name (2 letter code)
countryName_default    = US
stateOrProvinceName    = State or Province Name (full name)
stateOrProvinceName_default = California
localityName           = Locality Name (eg, city)
localityName_default   = San Francisco
organizationName       = Organization Name (eg, company)
organizationName_default = YourOrg
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = YourOrg Unit
commonName             = Common Name (e.g. server FQDN or YOUR name)
commonName_default     = example.com
commonName_max         = 64[ req_ext ]
subjectAltName = @alt_names[ alt_names ]
DNS.1 = example.com
DNS.2 = www.example.com
IP.1  = 192.168.1.1

依次执行下面的命令

# 生成 CA 私钥
openssl genrsa -out rootCA.key 2048# 生成 CA 证书签署请求
openssl req -new -x509 -days 3650 -key rootCA.key -out rootCA.crt -config openssl.cnf# 生成服务端私钥
openssl genrsa -out server.key 2048# 生成服务端 CSR
openssl req -new -key server.key -out server.csr -config openssl.cnf# 生成服务端证书
openssl x509 -req -in server.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out server.crt -days 3650 -extensions req_ext -extfile openssl.cnf# 生成客户端私钥
openssl genrsa -out client.key 2048# 生成客户端 CSR
openssl req -new -key client.key -out client.csr -config openssl.cnf# 生成客户端证书
openssl x509 -req -in client.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out client.crt -days 3650 -extensions req_ext -extfile openssl.cnf

查看证书

openssl x509 -in server.crt -text -noout

打包证书

openssl pkcs12 -export -out client.p12 -inkey client.key -in client.crt -certfile rootCA.crtopenssl base64 -in client.p12 -out client.p12.b64

nginx启用双向认证

    sl_certificate /path/to/server.crt;ssl_certificate_key /path/to/server.key;ssl_client_certificate /path/to/rootCA.crt;   # 用于验证客户端证书的 CA 证书ssl_verify_client on;                     # 启用双向认证

快速生成一个证书

openssl req -x509 -newkey rsa:2048 -sha256 -nodes -keyout key.pem -out ca.pem -days 3650等于
openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out ca.csr//用于向第三方机构申请证书
openssl req -new -x509 -key key.pem -out ca.pem -days 3650

http://www.lryc.cn/news/432434.html

相关文章:

  • 如何使用 Python 读取 Excel 文件:从零开始的超详细教程
  • 仕考网:公务员笔试和面试哪个难?
  • C++知识点总结(55):时间优化
  • GitHub每日最火火火项目(9.7)
  • 11Python的Pandas:可视化
  • 【周易哲学】生辰八字入门讲解(二)
  • 传统CV算法——基于Opencv的多目标追踪算法
  • 人生苦短我用Python excel转csv
  • Web2和Web3笔记
  • 单元测试 Mock不Mock?
  • 常用排序算法(上)
  • 【从问题中去学习k8s】k8s中的常见面试题(夯实理论基础)(二十六)
  • 小程序的页面跳转方式
  • 第 21 章 DOM 操作表格及样式
  • vc-align源码分析 -- ant-design-vue系列
  • 计算机网络(四) —— 简单Tcp网络程序
  • 简单的Linux Ftp服务搭建
  • SQL的高级查询练习知识点(day24)
  • Python条件表达式优化的10个实例
  • oatpp apiclient 客户端get,post请求python fastapi demo
  • RK3568平台(内存篇)EMMC介绍
  • Python批量读取身份证信息录入系统和重命名
  • IBM Storwize V7000存储控制器故障节点报错574
  • 通信工程学习:什么是SSB单边带调制、VSB残留边带调制、DSB抑制载波双边带调制
  • MapSet之二叉搜索树
  • OpenCV图像分割教程
  • python科学计算:NumPy 线性代数与矩阵操作
  • Unity面向对象补全计划 之 List<T>与class(非基础)
  • ant design vue+vue3+ts+xlsx实现表格导出问excel文件(带自定义表头)~
  • 基于Python爬虫的淘宝服装数据分析项目