views:

91

answers:

1

I'm using the pyOpenSSL interface to the OpenSSL library but it is missing some functions I need and I can't or don't want to modify it to support these methods (for various reasons).

So what I want to achieve, is to retrieve the OpenSSL object pointer. After that, I will be able to call the missing functions through ctypes. What is the best method to do that ?

I have already found that I can use id() to get the pointer to the pyOpenSSL object. How can I access the ssl variable with that.

From pyOpenSSL/connections.h:

  typedef struct {
      PyObject_HEAD
      SSL                 *ssl;
      ssl_ContextObj      *context;
      PyObject            *socket;
      PyThreadState       *tstate;
      PyObject            *app_data;
  } ssl_ConnectionObj;
+3  A: 

Pointers doesn't really make much sense in Python, as you can't do anything with them. They would just be an integer. As you have noticed you can get the address of an object with the id method. But that's just what it is, the address. It's not a pointer, so you can't do anything with it.

You could also see it like this: Everything in Python are pointers. The variable you have for the pyOpenSSL object is the pointer. But it is the pointer to the pyOpenSSL-object, not to the connection structure. It's unlikely you can access that structure directly.

So you have to tell us what you want to do instead. Maybe there is another solution.

Lennart Regebro
I want to use the SSL_set_verify function which is not available in pyOpenSSL (there is only set_verify on the context object, not the SSL connection) and I don't want to modify pyOpenSSL (I want to use the one packaged by Ubuntu 8.04 LTS which is unlikely to be modified even if I contribute a patch).
math
You generally can't use a function that is not exposed. You might be able to do it if you skip using pyOpenSSL altogether, and just use ctypes all the way. I'm not very familiar with ctypes, but I doubt you can use it in a mix, as it will be hard for you get the right handles from pyOpenSSL.I think your best bet is to submit a patch, and the install pyOpenSSL from source.
Lennart Regebro