Access to CSR extension stack in M2Crypto

I have a certificate signing request with an added extension stack. When creating a certificate based on this request, I would like to have access to this stack for use in creating the final certificate.

However, although it M2Crypto.X509.X509has a number of helpers for accessing extensions ( get_ext, get_ext_atand the like), M2Crypto.X509.Requestit seems that it provides only a member to add extensions, but it does not have the ability to check extensions already associated with this object.

Did I miss something?

+3
source share
2 answers

You're right.

The current version of M2Crypto does not provide the necessary OpenSSL interface X509_REQ_get_extensions.

, , C:

X509_REQ *req = /* ... */;
STACK_OF(X509_EXTENSION) *exts = X509_REQ_get_extensions(req);
int count = sk_X509_EXTENSION_num(exts);
int i;
for (i = 0; i < count; ++i) {
    X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
    /* Do something with ext */
}
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);

M2Crypto SWIG C, API, C.

+2

, Google, .

, M2Crypto , OpenSSL , - YAML, .

def req_extensions(csrFilename):
    cmd = ('openssl req -text -noout -in %s'
        % csrFilename)

    output = subprocess.check_output(cmd.split(),
        stderr=subprocess.STDOUT)

    output = re.sub(r': rsaEncryption', ':', output)
    output = re.sub(r'[0-9a-f]{2}:', '', output)

    return yaml.load(output)

...

csrExt = self.req_extensions('my.csr')
keyUsage = (
    csrExt['Certificate Request']['Data']['Requested Extensions']
          ['X509v3 Key Usage'])

SAN = (
    csrExt['Certificate Request']['Data']['Requested Extensions']
          ['X509v3 Subject Alternative Name'])

.

+2

Source: https://habr.com/ru/post/1783153/


All Articles