OpenSSL自签证书生成

一 背景

我们的mqtt broker服务,使用了SSL自签证书,可以提高mqtt连接安全性。

二 生成自签证书

在Centos7下生成,有效时长:100年

# copy openssl的默认配置 到当前目录下
cp /etc/pki/tls/openssl.cnf ./

# 1 放开注释  req_extensions = v3_req
# 2 在v3_req中增加subjectAltName,并在下面增加多个域名如下
----------------------start---------------------------------------------
vim openssl.cnf
[ v3_req ]
 
# Extensions to add to a certificate request
 
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName          = @alt_names
 
[ alt_names ]
DNS.1 = mafgwo.cn
DNS.2 = *.mafgwo.cn
DNS.3 = dev.mafgwo.cn
DNS.4 = *.dev.mafgwo.cn
------------------------end------------------------------------------

# 3 生成ca证书
------------------start-----------------------------------------------------------------------
Country Name (2 letter code) [AU]:CN ← 国家 
State or Province Name (full name) [Some-State]:Guangdong ← 省 
Locality Name (eg, city) []:Guangzhou ← 市 
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ZG ← 公司英文名 
Organizational Unit Name (eg, section) []: ← 可以不输入 
Common Name (eg, YOUR name) []: ← 此时不输入 
Email Address []: ← 电子邮箱,可随意填 或不填
-----------------end---------------------------------------------------------------------------
 
openssl req -new -x509 -days 36500 -config openssl.cnf -extensions v3_ca -keyout ca.key -out ca.crt
 
# 4 生成server证书
openssl genrsa -out server.key 2048
 
----------------start-------------------------------------------------------------
> Country Name (2 letter code) [AU]:CN ← 国家名称,中国输入CN 
> State or Province Name (full name) [Some-State]:Guangdong ← 省名,拼音 
> Locality Name (eg, city) []:Guangzhou ← 市名,拼音 
> Organization Name (eg, company) [Internet Widgits Pty Ltd]:ZG ← 公司英文名 
> Organizational Unit Name (eg, section) []: ← 可以不输入 
> Common Name (eg, YOUR name) []:mafgwo.cn ← 服务器域名或IP地址 
> Email Address []: ← 电子邮箱,可随便填 或不填
 
> Please enter the following ‘extra’ attributes 
> to be sent with your certificate request 
> A challenge password []: ← 可以不输入 
> An optional company name []: ← 可以不输入
----------------end---------------------------------------------------------------
 
openssl req -config openssl.cnf -out server.csr -key server.key -new
 
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 36500
 
# touch /etc/pki/CA/index.txt  该文件没有则需要生成
# echo 01 >> /etc/pki/CA/serial  该文件没有则需要生成
openssl ca -in server.csr -md sha256 -out server.crt -cert ca.crt -keyfile ca.key -extensions v3_req -config openssl.cnf

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/7571

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023年3月8日 下午4:51
下一篇 2023年3月9日 下午4:30

相关推荐

  • 解决Composer Installing dependencies from lock file

    1、问题描述 2、原因 这是因为不匹配composer.json要求的版本。提示我的PHP 7版本太高,不符合composer.json需要的版本,但是在PHP 7下应该也是可以运行的,composer可以设置忽略版本匹配。 3、解决方案 composer install –ignore-platform-reqs 或者 composer update -…

    2023年2月14日
    4700
  • IIS导入证书

    步骤一:导入证书 步骤二:为网站绑定证书 步骤三:验证证书是否安装成功 打开计算机的浏览器,在地址栏输入安装的证书所绑定的域名,验证证书在IIS服务器上是否安装成功。 如果您能够获得响应且地址栏的前部出现图标(如下图所示),表示成功建立了HTTPS连接,证书已经安装成功。

    2023年2月24日
    5700
  • Centos7.9下宝塔部署点可云进销存系统

    1、宝塔安装 见Centos7.6下宝塔安装及资产管理系统部署 2、安装环境 3、源码获取 4、系统部署 1、上传文件并解压 2、创建站点指向子目录 3、配置伪静态 4、配置数据库信息 直接输入 http://www.你的网址.com/install/ 然后输入你的数据库信息 至此 安装完成,默认账户密码:admin / admin888

    2023年2月14日
    6400
  • NGINX的基本编译安装部署

    yum自动安装,不支持自由扩展第三方功能 源码编译安装,可以指定安装路径,并支持自由安装模块 安装前准备 安装GCC编译环境 安装模块依赖 Nginx支持的功能模块需要有第三方的库支持,例如gzip的zlib库,rewrite重写需要的pcre库,HTTPS需要的openssl库等等。 如果出现报错 可以在后面添加命令 –setopt=prote…

    2022年6月17日
    22210
  • Centos 7.9 宝塔面板下安装开源IDC机房资产管理系统-Racktables

    第一步:准备宝塔环境 根据racktables官方文档,选择合适版本,搭建环境。 第二步:安装racktables 1 官网下载(https://www.racktables.org/)racktables安装包,并上传到宝塔。 2 解压安装包,设置网站,创建数据库 3 浏览器完成安装 Please set ownership (chown) and/or …

    2022年12月22日
    8000

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信
OpenSSL自签证书生成