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

相关推荐

  • PHP编译安装时常见错误及解决办法

    1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. *27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. …

    2023年4月28日
    31800
  • LAMP环境下部署DiscuzQ

    一、安装Apachae yum安装Apache,并设置开机自启动 在网页浏览器输入ip地址,查看Apache是否正常 二、安装配置 MariaDB 执行以下命令,查看系统中是否已安装 MariaDB。 rpm -qa | grep -i mariadb       返回结果类似如下内容,则表示已存在 MariaDB。 &nbsp…

    2022年12月6日
    42600
  • DedeCMS系统后台登陆并跳转回登陆界面的解决方法

    问题描述 在登陆界面输入账号密码后会有3-5秒的卡顿才会进入下面的页面,然后再卡顿3-5秒就跳回登陆界面。 解决方法 Windows系统 出现该问题的原因是网站web目录没有写入权限,因此只要将web目录增加写入权限即可 Linux系统 修改DATA和sessions的目录属性为可写,即(777) 清空sessions内除index.html以外的所有文件 …

    2022年8月22日
    51000
  • IIS发布网站时报403错误的所有原因及解决方案

    在使用IIS的时候,如果遇到403相关的错误,我们往往束手无策,不知道是什么权限的原因。现总结如下,供以后参考。 1、403.1 – 执行访问被禁止 没有足够的执行权限,例如你访问的index.php文件,但是该文件并没有执行权限,那么浏览器在访问时就会出现该错误,然后你就需要去修改目录的权限了 2、403.2 – 读访问被禁止验证是…

    2022年6月21日
    1.4K00
  • IIS导入证书

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

    2023年2月24日
    48500

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信