I am trying to print out the error that is input to the certificate verification callback function[I am using pyopenssl]:
def verify_cb(context, certificate, errornum, depth, ok):
if (lib.X509_V_OK == errornum):
print lib.X509_verify_cert_error_string(errornum)
I thought the above code would print ok
. However it returns <cdata 'char *' 0x7fff8b400f0f>
. Debugging this in pdb I get the following:
(Pdb) lp=lib.X509_verify_cert_error_string(errnum)
(Pdb) type(lp)
<type '_cffi_backend.CData'>
(Pdb) lp[0]
'o'
(Pdb) lp[1]
'k'
(Pdb) lp[2]
'\x00'
Does anyone know how I can get the value of this as a python string other that iterating through this till I get a \x00
character? Thank you.
Ok I figured it out. The following gets it to work:
from OpenSSL._util import ffi
ffi.string(lib.X509_verify_cert_error_string(errornum))