The error was because I was passing in a wrong pointer type for req_p into create_cert.
Solution was to change create_cert to this:
int create_cert(X509 *req_p, X509 **cert, EVP_PKEY **priv_key_p, char * passphrase)
题
I am getting a segmentation fault with the following code. I am pretty sure it is because a function is trying to use the address of a variable instead of it's value. I am a bit new to pointers.
int main(int argc, char *argv[])
{
EVP_PKEY priv_key_p;
X509_REQ req_p;
X509 cert;
PKCS7 pkcs7;
/*Need to store value in req_p and priv_key_p*/
makecsr(&req_p, &priv_key_p, passphrase);
/*Need to use value of req_p and priv_key_p*/
create_cert(&req_p, &cert, &priv_key_p, passphrase);
}
int create_cert(X509_REQ *req_p, X509 *cert, EVP_PKEY *priv_key_p, char *passphrase)
{
int i;
long serial = 1;
EVP_PKEY *pkey;
const EVP_MD *digest;
X509_NAME *name;
X509V3_CTX ctx;
/* verify signature on the request */
if (!(pkey = X509_REQ_get_pubkey (req_p))) <--- Segmentation fault here!
int_error ("Error getting public key from request");
....
}
Using GDB, after makecsr has executed, I can print the value of priv_key_p and req_p no problem.
However, inside the create_cert function, I can only print the value by writing p *priv_key_p / *req_p
Error
Program received signal SIGSEGV, Segmentation fault.
0xb7ebb747 in X509_REQ_get_pubkey ()
from /lib/i386-linux-gnu/libcrypto.so.1.0.0
解决方案 2
The error was because I was passing in a wrong pointer type for req_p into create_cert.
Solution was to change create_cert to this:
int create_cert(X509 *req_p, X509 **cert, EVP_PKEY **priv_key_p, char * passphrase)
其他提示
your code:
if (!(pkey = X509_REQ_get_pubkey (req_p))) <--- Segementation fault here!
int_error ("Error getting public key from request");
....
try this one:
if (!(pkey == X509_REQ_get_pubkey (req_p))) <--- Segementation fault here!
int_error ("Error getting public key from request");
....