I am trying to perform Authentication using HTTPS client certificates using perl Dancer framework. I would like to accept requests sent with/without certificate and do validation on the certificate CN to proceed with the valid response (https://medium.com/@sevcsik/authentication-using-https-client-certificates-3c9d270e8326, the link shows how to do it in node.js, need something very similar for perl Dancer/Starman/Plackup)
I have setup ssl using Dancer/Plackup, but have not found a way to get details about the peer certificate to perform validation in Dancer framework
I would like to achieve the following:
If the request is sent
without certificate => 401
with certificate but client has self-signed (CN doesn't match with server cert CN) => 401
with certificate but client cert has been signed using server cert (CN matches server cert CN) => 200
In Dancer you can get the IO::Socket::SSL object with
request->env->{'psgix.io'}, but that does not help you because you have no opportunity to configure it for client verification. IO::Socket::SSL::set_defaults does not run early enough, either.This means it's best to set up Apache httpd or nginx to terminate TLS. Pass on the certificate info you need (e.g. client verification result) in environment variables to the Dancer application.