瀏覽代碼

feat(exhook): add ssl cert info to ClientInfo

Ertan Deniz 4 年之前
父節點
當前提交
07d5c0f9df

+ 6 - 0
apps/emqx_exhook/priv/protos/exhook.proto

@@ -335,6 +335,12 @@ message ClientInfo {
   bool  is_superuser = 9;
   bool  is_superuser = 9;
 
 
   bool  anonymous = 10;
   bool  anonymous = 10;
+
+  // common name of client TLS cert
+  string cn = 11;
+
+  // subject of client TLS cert
+  string dn = 12;
 }
 }
 
 
 message Message {
 message Message {

+ 3 - 1
apps/emqx_exhook/src/emqx_exhook_handler.erl

@@ -254,7 +254,9 @@ clientinfo(ClientInfo =
       protocol => stringfy(Protocol),
       protocol => stringfy(Protocol),
       mountpoint => maybe(Mountpoiont),
       mountpoint => maybe(Mountpoiont),
       is_superuser => maps:get(is_superuser, ClientInfo, false),
       is_superuser => maps:get(is_superuser, ClientInfo, false),
-      anonymous => maps:get(anonymous, ClientInfo, true)}.
+      anonymous => maps:get(anonymous, ClientInfo, true),
+      cn => maybe(maps:get(cn, ClientInfo, undefined)),
+      dn => maybe(maps:get(dn, ClientInfo, undefined))}.
 
 
 message(#message{id = Id, qos = Qos, from = From, topic = Topic, payload = Payload, timestamp = Ts}) ->
 message(#message{id = Id, qos = Qos, from = From, topic = Topic, payload = Payload, timestamp = Ts}) ->
     #{node => stringfy(node()),
     #{node => stringfy(node()),

+ 3 - 1
apps/emqx_exhook/test/props/prop_exhook_hooks.erl

@@ -452,7 +452,9 @@ from_clientinfo(ClientInfo) ->
       protocol => stringfy(maps:get(protocol, ClientInfo)),
       protocol => stringfy(maps:get(protocol, ClientInfo)),
       mountpoint => maybe(maps:get(mountpoint, ClientInfo, <<>>)),
       mountpoint => maybe(maps:get(mountpoint, ClientInfo, <<>>)),
       is_superuser => maps:get(is_superuser, ClientInfo, false),
       is_superuser => maps:get(is_superuser, ClientInfo, false),
-      anonymous => maps:get(anonymous, ClientInfo, true)
+      anonymous => maps:get(anonymous, ClientInfo, true),
+      cn => maybe(maps:get(cn, ClientInfo, <<>>)),
+      dn => maybe(maps:get(dn, ClientInfo, <<>>))
     }.
     }.
 
 
 from_message(Msg) ->
 from_message(Msg) ->