mitmproxy/netlib/certffi.py

42 lines
830 B
Python
Raw Normal View History

2014-08-16 13:53:07 +00:00
from __future__ import (absolute_import, print_function, division)
2015-05-28 08:56:00 +00:00
from cffi import FFI
2014-03-10 04:29:27 +00:00
import OpenSSL
2014-08-16 13:53:07 +00:00
2015-05-28 08:56:00 +00:00
xffi = FFI()
2014-08-16 13:53:07 +00:00
xffi.cdef("""
2014-03-10 04:29:27 +00:00
struct rsa_meth_st {
int flags;
...;
};
struct rsa_st {
int pad;
long version;
struct rsa_meth_st *meth;
...;
};
""")
xffi.verify(
"""#include <openssl/rsa.h>""",
extra_compile_args=['-w']
)
2014-08-16 13:53:07 +00:00
2014-03-10 04:29:27 +00:00
def handle(privkey):
new = xffi.new("struct rsa_st*")
newbuf = xffi.buffer(new)
rsa = OpenSSL.SSL._lib.EVP_PKEY_get1_RSA(privkey._pkey)
oldbuf = OpenSSL.SSL._ffi.buffer(rsa)
newbuf[:] = oldbuf[:]
return new
2014-08-16 13:53:07 +00:00
2014-03-10 04:29:27 +00:00
def set_flags(privkey, val):
hdl = handle(privkey)
2014-08-16 13:53:07 +00:00
hdl.meth.flags = val
2014-03-10 04:29:27 +00:00
return privkey
2014-08-16 13:53:07 +00:00
2014-03-10 04:29:27 +00:00
def get_flags(privkey):
hdl = handle(privkey)
return hdl.meth.flags