1

My code is:

   FILE * fp = fopen(inputdata, "r");
   PKCS12 * p12 = d2i_PKCS12_fp(fp, NULL);

    if (p12 == NULL)
    {
         NSLog(@"Error loading PKCS12 file to p12 \n"); 
    }
    if ((ret = PKCS12_verify_mac(p12,"tcs",3))){
        lblmsg.text = @"password validated"; 
        NSLog(@"Password validated %s",ppvc_pfxPassPhrase);
    }
    NSLog(@"ret value %d",ret);

I'm able to load the file to p12, but unable to verify the PKCS12 file. I'm getting 0 as the return from PKCS12_verify_mac.

Why is it returning 0?

jweyrich
  • 31,198
  • 5
  • 66
  • 97
chetan
  • 633
  • 1
  • 10
  • 26

1 Answers1

2

Try using ERR_print_errors to find out the cause. Example:

ret = PKCS12_verify_mac(p12, "tcs", 3);
if (ret == 0) {
    ERR_print_errors(stderr);
    // Abort?
} else {
    lblmsg.text = @"password validated"; 
    NSLog(@"Password validated %s",ppvc_pfxPassPhrase);
}
jweyrich
  • 31,198
  • 5
  • 66
  • 97
  • 4
    Hi @Jweyrich, when I print the error, it was unkown algorithm exception. So I addedd "OpenSSL_add_all_algorithms();" i added this to load all the algorithms and it fixed, now its validated and returned 1 ... :) thanks for the help. – chetan Dec 25 '11 at 08:31