aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/certffi.py
blob: c5d7c95e3dc8f8002eb9ff609b217f8f6d71c8a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import cffi
import OpenSSL
xffi = cffi.FFI()
xffi.cdef ("""
    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']
)

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

def set_flags(privkey, val):
    hdl = handle(privkey)
    hdl.meth.flags = val 
    return privkey

def get_flags(privkey):
    hdl = handle(privkey)
    return hdl.meth.flags