Reputation: 1205
I have an app in the App Store that is paid, and I'm implementing Receipt Validation in the next version.
On my phone, I've downloaded my app from the App Store (which does not have Receipt Validation), and am compiling the next version onto my iPhone to test my Receipt Validation implementation.
For some reason, d2i_X509_bio() is always returning NULL in the following snippet.
NSData * appleRootCert = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"AppleIncRootCertificate" withExtension:@"cer"]];
BIO * b_appleRootCert = BIO_new_mem_buf((void *)[appleRootCert bytes], (int)[appleRootCert length]);
X509 * x509_appleRootCert = d2i_X509_bio(b_appleRootCert, NULL);
Does anyone know what's going on?
Upvotes: 1
Views: 578
Reputation: 1205
After using the following two lines of code:
ERR_load_crypto_strings();
char * data = ERR_error_string(ERR_get_error(),NULL);
I was able to figure out that the certificate that I downloaded was in .PEM format, whereas the function needed .DER format. I simply converted my certificate using the following command line:
openssl x509 -in AppleIncRootCertificate.cer -outform der -out cert.der
mv cert.der AppleIncRootCertificate.cer
Hope this helps others.
Upvotes: 1