[12]MQTT mosquitto一方向SSL認証の構成方式

2417 ワード

MQTT mosquittoは一方向と双方向のSSL認証をサポートしていることを知っています.まず、単一認証のプロファイルをどのように構成すべきかを見てみましょう.ワンウェイSSL証明書とは、MQTTのクライアントがMQTTのサーバ側にアクセスする際に、SSL暗号化通信を利用する場合、SSL暗号化通信を確立する前に、クライアントが証明書によってサービス側が信頼できるかどうかを検証する必要がある、したがって、クライアントは、サーバ側から送信された証明書を、何らかの経路で取得したサーバ側CA証明書またはサーバ証明書と比較し、マッチングに成功すれば信頼性の高い安全なSSL接続を実行する.
MQTT mosquittoを起動するときは、次のコマンドを使用できます.
mosquitto [-c config file] [ -d | --daemon ] [-p port number] [-v]
起動方法を指定します.ここで、-cの後にmosquittoを起動して調整できるパラメータが付いています.例えば、基本認証をオンにするかどうか、ポートが何なのか、SSLの一方向と双方向の認証構成などです.
-dは、MQTT mosquittoがバックグラウンドで実行されることを示す.
-pは、現在のmosquittoサービスインスタンスが起動した後、[-c config file]で指定されたプロファイルのポートを上書きするポート番号をリスニングします.
-vコードデバッグモード(verbose)は、より多くの情報を出力できます.
我々自身がOpenSSLによって関連するCA証明書とサーバ側の自己署名公開鍵と秘密鍵を生成したと仮定する.場所の分布は次のとおりです.
(1)CA証明書の場所
D:mosquittocertificatesca.crt(2)サーバ側の自己署名公開鍵のアドレス
D:\mosquitto\certificates\server.crt
(3)サーバ側の自己署名の公開鍵のアドレス
D:\mosquitto\certificates\server.key
一方的なSSLのmosquittoサーバ側のコンフィギュレーションファイルのコンフィギュレーションは次のようになります.
次の構成はD:mosquittosinglewaysslという名前で保存するとします.confのテキストファイルでは、
# See also the mosquitto-tls man page.
# At least one of cafile or capath must be defined. They both
# define methods of accessing the PEM encoded Certificate
# Authority certificates that have signed your server certificate
# and that you wish to trust.
# cafile defines the path to a file containing the CA certificates.
# capath defines a directory that will be searched for files
# containing the CA certificates. For capath to work correctly, the
# certificate files must have ".crt" as the file ending and you must run
# "c_rehash " each time you add/remove a certificate.
cafile D:\mosquitto\certificates\ca.crt
#capath
# Path to the PEM encoded server certificate.
certfile D:\mosquitto\certificates\server.crt
# Path to the PEM encoded keyfile.
keyfile D:\mosquitto\certificates\server.key
# This option defines the version of the TLS protocol to use for this listener.
# The default value will always be the highest version that is available for
# the version of openssl that the broker was compiled against. For openssl >=
# 1.0.1 the valid values are tlsv1.2 tlsv1.1 and tlsv1. For openssl < 1.0.1 the
# valid values are tlsv1.
tls_version tlsv1

mosquittoサーバ側の一方向のSSLサービスは、以下のように起動することができる.
mosquitto D:\mosquitto\
singlewayssl.conf -p 1884 -v