Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the <a href="http://pyopenssl.sourceforge.net/pyOpenSSL.txt" rel="nofollow">OpenSSL documentation</a> for <code>set_verify()</code>, the key that you care about is the <strong>return code</strong>:</p> <blockquote> <p>callback should take five arguments: A Connection object, an X509 object, and three integer variables, which are in turn potential error number, error depth and <strong>return code</strong>. callback should return true if verification passes and false otherwise.</p> </blockquote> <p>There is a a full working example that shows more or less what you want to do: <a href="https://answers.launchpad.net/pyopenssl/+question/79151" rel="nofollow">When are client certificates verified?</a></p> <p>Essentially you can ignore the first 4 arguments and just check the value of the return code in the fifth argument like so:</p> <pre><code>from OpenSSL.SSL import Context, Connection, SSLv23_METHOD from OpenSSL.SSL import VERIFY_PEER, VERIFY_FAIL_IF_NO_PEER_CERT, VERIFY_CLIENT_ONCE class SecureAJAXServer(BaseServer): def verify_callback(connection, x509, errnum, errdepth, ok): if not ok: print "Bad Certs" else: print "Certs are fine" return ok def __init__(self, server_address, HandlerClass): BaseServer.__init__(self, server_address, HandlerClass) ctx = Context(SSLv23_METHOD) ctx.use_privatekey_file ('keys/server.key') ctx.use_certificate_file('keys/server.crt') ctx.set_session_id("My_experimental_AJAX_Server") ctx.set_verify( VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT | VERIFY_CLIENT_ONCE, verify_callback ) self.socket = Connection(ctx, socket.socket(self.address_family, self.socket_type)) self.server_bind() self.server_activate() </code></pre> <p>Note: I made one other change which is <code>from OpenSSL.SSL import ...</code> to simplify your code a bit while I was testing it so you don't have the <code>SSL.</code> prefix in front of every import symbol.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload