fix(ws connection): fix peer_cert_as_username error when ws connect
This commit is contained in:
parent
7d003e0bfc
commit
1eb0f7b3b2
|
@ -544,6 +544,16 @@ listener.ws.external.verify_protocol_header = on
|
|||
## Value: Duration
|
||||
## listener.ws.external.proxy_protocol_timeout = 3s
|
||||
|
||||
## See: listener.ssl.$name.peer_cert_as_username
|
||||
##
|
||||
## Value: cn
|
||||
## listener.ws.external.peer_cert_as_username = cn
|
||||
|
||||
## See: listener.ssl.$name.peer_cert_as_clientid
|
||||
##
|
||||
## Value: cn
|
||||
## listener.ws.external.peer_cert_as_clientid = cn
|
||||
|
||||
## The TCP backlog of external MQTT/WebSocket Listener.
|
||||
##
|
||||
## See: listener.ws.$name.backlog
|
||||
|
|
|
@ -1587,7 +1587,11 @@ end}.
|
|||
]}.
|
||||
|
||||
{mapping, "listener.ws.$name.peer_cert_as_username", "emqx.listeners", [
|
||||
{datatype, {enum, [cn, dn, crt]}}
|
||||
{datatype, {enum, [cn]}}
|
||||
]}.
|
||||
|
||||
{mapping, "listener.ws.$name.peer_cert_as_clientid", "emqx.listeners", [
|
||||
{datatype, {enum, [cn]}}
|
||||
]}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -196,15 +196,21 @@ init(Req, Opts) ->
|
|||
end.
|
||||
|
||||
websocket_init([Req, Opts]) ->
|
||||
Peername = case proplists:get_bool(proxy_protocol, Opts)
|
||||
andalso maps:get(proxy_header, Req) of
|
||||
#{src_address := SrcAddr, src_port := SrcPort} ->
|
||||
{SrcAddr, SrcPort};
|
||||
_ ->
|
||||
cowboy_req:peer(Req)
|
||||
end,
|
||||
{Peername, Peercert} =
|
||||
case proplists:get_bool(proxy_protocol, Opts)
|
||||
andalso maps:get(proxy_header, Req) of
|
||||
#{src_address := SrcAddr, src_port := SrcPort, ssl := SSL} ->
|
||||
ProxyName = {SrcAddr, SrcPort},
|
||||
%% Notice: Only CN is available in Proxy Protocol V2 additional info
|
||||
ProxySSL = case maps:get(cn, SSL, undefined) of
|
||||
undeined -> nossl;
|
||||
CN -> [{pp2_ssl_cn, CN}]
|
||||
end,
|
||||
{ProxyName, ProxySSL};
|
||||
_ ->
|
||||
{cowboy_req:peer(Req), cowboy_req:cert(Req)}
|
||||
end,
|
||||
Sockname = cowboy_req:sock(Req),
|
||||
Peercert = cowboy_req:cert(Req),
|
||||
WsCookie = try cowboy_req:parse_cookies(Req)
|
||||
catch
|
||||
error:badarg ->
|
||||
|
|
Loading…
Reference in New Issue