tags:

views:

2

answers:

0

Hello, I have PKCS7 signed image in DER format, Verifing with

d2i_PKCS7_bio

API is always success for first time, but each next failed(returns p7 as NULL). What might be wrong in following code?

BIO *in=NULL; 
PKCS7 *p7=NULL;
in=BIO_new(BIO_s_file());
BIO_read_filename(in, fileSigned);
if (in == NULL) 
{
  BIO_printf(bio_err,"load err\n");
  exit(1);
}
p7=d2i_PKCS7_bio(in,NULL);
if (p7==NULL) 
{
  BIO_printf(bio_err,"load pkcs7 err\n");
  BIO_free(in);
  in = NULL;
  exit(1);
}
if (OBJ_obj2nid(p7->type) != NID_pkcs7_signed) 
{
  BIO_printf(bio_err,"load is not pkcs7.\n");
  BIO_free(in);
  in = NULL;
  if(p7!=NULL) PKCS7_free(p7);
}
if(p7!=NULL) PKCS7_free(p7);
p7 = NULL;