'Create WSGI environ entries to be merged into each request.'

def populate_ssl_environ(self):

    cert = open(self.ssl_certificate, 'rb').read()
    cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert)
    ssl_environ = {'wsgi.url_scheme': 'https', 'HTTPS': 'on'}
    ssl_environ.update({'SSL_SERVER_M_VERSION': cert.get_version(), 'SSL_SERVER_M_SERIAL': cert.get_serial_number()})
    for (prefix, dn) in [('I', cert.get_issuer()), ('S', cert.get_subject())]:
        dnstr = str(dn)[18:(-2)]
        wsgikey = ('SSL_SERVER_%s_DN' % prefix)
        ssl_environ[wsgikey] = dnstr
        while dnstr:
            pos = dnstr.rfind('=')
            (dnstr, value) = (dnstr[:pos], dnstr[(pos + 1):])
            pos = dnstr.rfind('/')
            (dnstr, key) = (dnstr[:pos], dnstr[(pos + 1):])
            if (key and value):
                wsgikey = ('SSL_SERVER_%s_DN_%s' % (prefix, key))
                ssl_environ[wsgikey] = value
    self.environ.update(ssl_environ)
