Get common name from Client certificate

I am using openssl.x509 and library.

I am getting the client certificate as below:
– Get Client Certificate from Request
local client_cert =

– Get Subject from Client Certificate sent in Request
local subject = client_cert:getSubject()

I need to get the common name from the subject, how can I get it?

@subrat Hello,

You can use the ngx.var.ssl_client_s_dn NGINX variable (See and parse it in Lua (via the string library) or via the PCRE bindings provided by OpenResty.


1 Like