Process x509 client certificates in Perl

笑着哭i 提交于 2019-12-12 04:34:09

问题


I am working with Web::ID and have some questions.

From the FAQ for Web::ID:

How can I use WebID in Perl?

[...]

Otherwise, you need to use Web::ID directly. Assuming you've configured your web server to request a client certificate from the browser, and you've managed to get that client certificate into Perl in PEM format, then it's just:

my $webid = Web::ID->new(certificate => $pem);

my $uri = $webid->uri;

And you have the URI.

Anyway I'm stuck at the .. get that client certificate into Perl .. part.

I can see the client certificate is being passed along to the script by examining the %ENVenvironment variable. But I am still unsure how to actually process it in the way that Web::ID does... like examine the SAN.


回答1:


According to the documentation of mod_ssl you will find the PEM encoded client certificate in the environment variable SSL_CLIENT_CERT, so all you need is to call

 my $webid  = Web::ID->new(certificate => $ENV{SSL_CLIENT_CERT});

However, Apache does not set the SSL_CLIENT_CERT environment variable by default. This is for performance reasons - setting a whole bunch of environment variables before spawning your Perl script (via mod_perl, or CGI, or whatever) is wasteful if your Perl script doesn't use them, so it only sets a small set of environment variables by default. You need to configure Apache correctly to tell it you want ALL DA STUFFZ. In particular you want something like this in .htaccess, or your virtual host config, or server config file:

SSLOptions +StdEnvVars +ExportCertData

While you're at it, you also want to make sure Apache is configured to ask clients to present a certificate. For that you want something like:

SSLVerifyClient optional_no_ca

All this is kind of covered in the documentation for Web::ID but not especially thoroughly.



来源:https://stackoverflow.com/questions/26658650/process-x509-client-certificates-in-perl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!