Question

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;
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top