If I have X509*one that openssl provided is the best way to find out the bitness of the RSA public key in a certificate? I can’t figure it out. I am sure that if I go back to verifying the SSL certificate certificate, I can get ptr with x509 using
X509 * cert = X509_STORE_CTX_get_current_cert(the_x509_store_ctx);
and I would suggest that I get a public key, like this
EVP_PKEY *public_key = X509_get_pubkey(cert);
and then I need to check if this is an RSA, presumably?
if (public_key && (EVP_PKEY_RSA == public_key->type))
and as soon as I find out that I received the public key and that it is RSA, I would like to do this:
int key_length = BN_num_bits(public_key->pkey.rsa->n);
but I found that although it works pretty well on openssl 0.9.8, in 1.0.1h it segfaults on Windows. BIGNUM 'n' doesn't seem to be valid - the ptr data in it has a pointer to garbage.
Any idea what is wrong?