tags:

views:

42

answers:

1

Can anybody tell me how to use PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);

int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca);

any documenatation reference will also work . Please help me.

A: 

Without error-checking:

FILE *p12_file;
PKCS12 *p12_cert = NULL;
EVP_PKEY *pkey;
X509 *x509_cert;
STACK_OF(X509) *additional_certs = NULL;

p12_file = fopen("foo.p12", "rb");
d2i_PKCS12_fp(p12_file, &p12_cert);
fclose(p12_file);

PKCS12_parse(p12_cert, "password", &pkey, &x509_cert, &additional_certs);

The private key is now in pkey, the certificate in x509_cert and any additional certificates in additional_certs.

caf
When I am using the above code, it is crashing whend2i_PKCS12_fp(p12_file, is getting executed.Can anybody tell me why it is happening ?
bharat
@bharat: Sorry, `p12_cert` also needs to be initialised to `NULL` (see updated answer).
caf
@caf: I think it is initialised to NUll in line #02
bharat
@bharat: It is now, because I fixed it - but it wasn't before, and that was the bug.
caf
@caf:Sorry caf, but it is still crashing...
bharat
@bharat: Works fine for me... (you can also just do `p12_cert = d2i_PKCS12_fp(p12_file, NULL);` if you like).
caf