Search code examples
djangoenvironment-variablesmod-wsgix509mod-ssl

How to access mod_ssl environment variables from django using mod_wsgi?


I'm trying to get the client's certificate and sign an xml file using it. I have added the following to my virtual hosts:

SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +stdEnvVars

This should allow mod_ssl to get the user's certificate. But I don't know how to pass it along to my django app. Any help is appreciated. Thanks.


Solution

  • Those Apache configuration directives mean that mod_ssl environment variables should now be available in the environment inherited by Django. You can therefore access them using the os.environ object in your Django view:

    import os
    client_cert = os.environ['SSL_CLIENT_CERT']
    

    The SSL_CLIENT_CERT variable contains the PEM-encoded client certificate.