码迷,mamicode.com
首页 > 其他好文 > 详细

五、Mosquitto 高级应用之SSL/TLS

时间:2017-09-07 17:05:46      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:开始   实现   讲解   request   搜索   cat   conf   mos   加密   

  mosquitto提供SSL支持加密的网络连接和身份验证、本章节讲述次功能的实现、 在此之前需要一些准备工作。

准本工作: 一台 Linux 服务器、 安装好 openssl (不会明白怎么安装 openssl 的可以在网上搜索下、 我就不在这讲解了)

准本工作完成后我们开始来制作所需要的证书。

注:在生成证书过程 在需要输入 【Common Name 】 参数的地方 输入主机ip

一、Certificate Authority

Generate a certificate authority certificate and key.

  openssl req -newkey rsa:2045 -x509 -nodes -sha256 -days 36500 -extensions v3_ca -keyout ca.key -out ca.crt

二、Server

Generate a server key.

  openssl genrsa -des3 -out server.key 2048

Generate a server key without encryption.

  openssl genrsa -out server.key 2048

Generate a certificate signing request to send to the CA.

  openssl req -out server.csr -key server.key -new

Send the CSR to the CA, or sign it with your CA key:

  openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days <duration>

三、Client

Generate a client key.

  openssl genrsa -des3 -out client.key 2048

Generate a certificate signing request to send to the CA.

  openssl req -out client.csr -key client.key -new

Send the CSR to the CA, or sign it with your CA key:

  openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days <duration>

到此处证书基本生成完成、 此时会在对应的目录下生成如下证书

ca.crt  ca.key  ca.srl  client.crt  client.csr  client.key  server.crt  server.csr  server.key

Server 端:ca.crt、 client.crt 、server.key

Client 端:ca.crt、 client.csr  client.key

其中 ca.crt 是同一个证书。

证书完成后接下来对 Mosquitto 服务进行配置证书

1> 打开配置文件 mosquitto.conf 修改如下配置  

  cafile /home/mosquitto-CA/ssl/ca.crt // 对应上述生成证书的绝对路劲
  certfile /home/mosquitto-CA/ssl/server.crt
  certfile /home/mosquitto-CA/ssl/server.key
  require_certificate true
  use_identity_as_username true

 

配置完成后 保存退出 到这 SSL/TLS  功能基本完成。

2> 启动 Mosquitto f服务

  mosquitto -c mosquitto.conf –v

五、Mosquitto 高级应用之SSL/TLS

标签:开始   实现   讲解   request   搜索   cat   conf   mos   加密   

原文地址:http://www.cnblogs.com/yueli/p/7490453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!