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

相关推荐

  • Nginx配置及命令详解

    Nginx命令行 nginx -s 对应参数 信号 含义 stop TERM 强制关闭整个服务 null INT 强制关闭整个服务 quit QUIT 优雅地关闭整个服务 reopen USR1 重新打开日志记录 reload HUP 重新读取配置文件,并且优雅地退出老的worker nginx.conf重要的指令块 核心功能都在于http{}指令块里,ht…

    2022年6月17日
    1.7K00
  • 已解决:Strict Standards: Non-static method cls_image::gd_version() should not be called statically in…..

    iis网站更换php版本后,遇到问题 原因:PHP升级到5.4X以后的兼容性语法问题 解决: 将php版本换回5.4之前的版本就可以解决

    2023年3月17日
    1.2K00
  • 蓝科模板网站迁移打开空白问题解决

    现象:网站迁移后,发现网站打开空白,原网页能正常打开 分析处理过程:首页进行环境检测,使用php测试页<?php phpinfo(); ?>测试 发现php默认页是能够正常打开的,同时发现网站后台能够正常登录,通过百度发现需要清除缓存才可显示正常首页。 点击清理缓存 这样首页就能够打开了,首页正常打开后可能会遇到一些图片显示不全的问题,可以在后台网站管…

    2022年12月22日
    1.1K00
  • 基于宝塔安装discuz

    前提条件 操作步骤 步骤一:配置PHP 安装扩展 TIP Discuz!Q 依赖于 fileinfo 和 exif 两个扩展运行,部署前需对 PHP 进行相关配置。以下操作将指导您安装fileinfo 和exif 扩展。 删除禁用函数 TIP Discuz!Q 需删除禁用的函数 puten…

    2023年7月31日
    1.5K00
  • 如何通过宝塔面板配置ssl证书

    至于宝塔的安装以及如何安装环境搭建网站,大家可以看我们的另一篇文章: Centos7.6下宝塔安装及资产管理系统部署 基于宝塔面板配置网站ssl证书支持https访问其实很简单,不需要你懂什么技术知识。接下来你跟着我的步骤,就能成功配置网站ssl。 宝塔面板后台设置成功如图所示: 第一步:点击设置 第二步:点击右侧的SSL,选择宝塔SSL,点击申请证书 第三…

    2022年6月14日
    2.4K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信