客户端和服务器做TLS双向认证
Nginx终结SSL后将请求转到emq的1883端口
emq配置http_auth认证,客户端可以连上,但是http_auth对应的HTTP认证服务器拿不到客户端证书subject。
Nginx配置如下
stream {
upstream mqtt_server {
server 10.8.168.124:1883;
}
server {
listen 8883 so_keepalive=on ssl;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
ssl_certificate /usr/local/nginx/certs/emqx.pem;
ssl_certificate_key /usr/local/nginx/certs/emqx.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 4h;
ssl_prefer_server_ciphers on;
proxy_connect_timeout 6m;
ssl_client_certificate /usr/local/nginx/certs/ca.pem;
ssl_trusted_certificate /usr/local/nginx/certs/ca.pem;
ssl_verify_depth 2;
ssl_verify_client on;
proxy_timeout 6m;
proxy_pass mqtt_server;
}
}
http_auth配置的请求体
{
“certCommonName”: “${cert_common_name}”,
“certSubject”: “${cert_subject}”,
“clientid”: “${clientid}”,
“password”: “${password}”,
“username”: “${username}”
}
HTTP 认证服务收到的请求日志如下
{“@timestamp”:“2023-11-07T08:55:31.813+08:00”,“@version”:“1”,“method”:“POST”,“protocol”:“HTTP/1.1”,“status_code”:404,“requested_url”:“POST /mqtt/v5/auth HTTP/1.1”,“requested_uri”:“/mqtt/v5/auth”,“remote_host”:“10.8.168.124”,“content_length”:124,“elapsed_time”:11,“request_headers”:{“accept”:“application/json”,“cache-control”:“no-cache”,“connection”:“keep-alive”,“content-length”:“106”,“content-type”:“application/json”,“country”:“TH”,“host”:“10.8.168.124:8080”,“keep-alive”:“timeout=30, max=1000”},“requestContent”:“{"username":"hu_sn111","password":"hu_sn111","clientid":"local-9993","certSubject":"","certCommonName":""}”,“serverName”:“gwm-message-push-service”,“logType”:“accesslog”}