Get common name from Client certificate

Hi,
I am using openssl.x509 and openssl.x509.store library.

I am getting the client certificate as below:
– Get Client Certificate from Request
local client_cert = openssl_x509.new(ngx.var.ssl_client_raw_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 http://nginx.org/en/docs/http/ngx_http_ssl_module.html#variables) and parse it in Lua (via the string library) or via the ngx.re PCRE bindings provided by OpenResty.

Best,

1 Like