python vs ssl

Currently there is no reason to rant about python3 and ssl, as there is no real wrapper yet.

m2crypto

But, for python2.x we got m2crypto.

Using m2crypto with nonblocking sockets?

PyObject *ssl_connect(SSL *ssl) {
    PyObject *obj = NULL;
    int r, err;
 
    Py_BEGIN_ALLOW_THREADS
    r = SSL_connect(ssl);
    Py_END_ALLOW_THREADS
 
 
    switch (SSL_get_error(ssl, r)) {
        case SSL_ERROR_NONE:
        case SSL_ERROR_ZERO_RETURN:
            obj = PyInt_FromLong((long)1);
            break;
        case SSL_ERROR_WANT_WRITE:
        case SSL_ERROR_WANT_READ:
            obj = PyInt_FromLong((long)0);
            break;
        case SSL_ERROR_SSL:
            PyErr_SetString(_ssl_err, ERR_reason_error_string(ERR_get_error()));
            obj = NULL;
            break;
        case SSL_ERROR_SYSCALL:
            err = ERR_get_error();
            if (err)
                PyErr_SetString(_ssl_err, ERR_reason_error_string(err));
            else if (r == 0)
                PyErr_SetString(_ssl_err, "unexpected eof");
            else if (r == -1)
                PyErr_SetFromErrno(_ssl_err);
            obj = NULL;
            break;
    }
 
 
    return obj;
}

_ssl.i
Once this is done, and returns 1, you need a magic oracle to get an idea what happend, and what needs to be done, same problem for nonblocking reads and writes.
Unfortunately m2crypto does not ship with such magic oracle.

2010/11/11/batteries_included-ssl.txt · Last modified: 2010/11/11 01:22 by common
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0