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

相关推荐

  • kibana报错:Unable to revive connection: http://localhost:9200/解决办法

    kibana报错:Unable to revive connection: http://localhost:9200/ 第一种情况(新手):先把elasticsearch.bat打开,再打开kibana.bat,原因主要是不打开elasticsearch自然生成不了地址,kibana自然也就找不到地址。如果不行请采用第二种或第三种。 第二种方法:通过doc…

    2023年8月23日
    2.0K00
  • SpringBoot 启动打印 Banner:佛祖保佑,永无BUG!

    在Resources目录下新建banner.txt 输入内容如下

    2023年9月13日
    2.0K00
  • NGINX的基本编译安装部署

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

    2022年6月17日
    1.5K10
  • DeDeCMS MySQL Column ‘nature’ has duplicated value ‘婆婆妈妈’ in SET 错误解决方案

    我们在做网站迁移,或者备份数据库时,需要导出一个.sql的数据库文件,然后再把这个.sql文件导入到新的数据库当中,但是我们在导入 dedecms 模板的 sql 数据库时,有时候会提示 Column ‘nature’ has duplicated value ‘婆婆妈妈’ in SET 这个错误的,那么我们该如何去解决呢? 解决方案一: 登录到原有的程序后…

    2022年6月14日
    1.8K00
  • 使用Openssl 自签发IP证书

    使用Openssl 自签发IP证书 日常交付项目中,总是有这样的场景,再使用一些融合通讯的业务时,需要HTTPS 环境,那就涉及到SSL 证书的签发 考虑到项目成本的问题,往往都是本地自签发IP 证书使用;使用openssl生成根证书,签发服务端证书,安装根证书使浏览器信任自签证书。 创建证书脚本:ssl.sh 证书脚本内容: 签发证书 签发好的证书 安装根…

    2023年5月26日
    1.8K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信