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

相关推荐

  • LNMP黄金架构的搭建

    LNMP组合工作流程 LNMP工作流是用户通过浏览器输入域名访问Nginx web服务,Nginx判断请求是静态请求则由Nginx返回给用户。如果是动态请求(如.php结尾),那么Nginx会将该请求通过FastCGI接口发送给PHP引擎(php-fpm进程)进行解析,如果该动态请求需要读取mysql数据库,php会继续向后读取数据库,最终Nginx将获取的…

    2022年7月7日
    1.9K00
  • Discuz! Database Error的解决办法

    原因一:数据库表太大 比如mysql数据库的表内容太大,超过10G就有可能会影响discuz论坛的运行。 这种情况可以通过对数据库分表的方法来解决。 原因二:数据库配置错误 有时候可能是主机搬家、数据库搬家等,造成数据库信息填写错误,或旧数据库信息没有及时更新等,比如数据库用户名、密码、数据库表填写错误等。 可以修正一下相关数据库信息即可,可以找到confi…

    2023年2月21日
    1.6K00
  • nginx安全:配置allow/deny控制ip访问

    一,nginx中allow/deny指令的用途 1, Nginx的deny和allow指令是由ngx_http_access_module模块提供, Nginx安装默认内置了该模块 2, nginx访问控制模块: 想禁止哪个ip访问就加上deny IP, 想允许哪个ip访问就加上allow IP, 想禁止或者允许所有,则allow all或者deny all…

    2023年3月1日
    1.5K00
  • 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
  • SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server.

    由于系统Microsoft ODBC Driver for SQL Server 驱动没有安装造成PHP无法链接sql server数据库 在https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16下…

    2023年4月6日
    1.8K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信