'SNI certificate callback.
This method will set a new OpenSSL context object for this
connection when an incoming connection provides an SNI name
(in order to serve the appropriate certificate, if any).
:param connection: The TLS connection object on which the SNI
extension was received.
:type connection: :class:`OpenSSL.Connection`'

def _pick_certificate_cb(self, connection):

    server_name = connection.get_servername()
    try:
        (key, cert) = self.certs[server_name]
    except KeyError:
        logger.debug('Server    name    (%s)    not    recognized,    dropping    SSL', server_name)
        return
    new_context = OpenSSL.SSL.Context(self.method)
    new_context.set_options(OpenSSL.SSL.OP_NO_SSLv2)
    new_context.set_options(OpenSSL.SSL.OP_NO_SSLv3)
    new_context.use_privatekey(key)
    new_context.use_certificate(cert)
    connection.set_context(new_context)
