I need to check receipts from In-App Purchases inside an iPhone application (iOS 7 only).
Unfortunately, cryptography, openssl, and an in-app purchase are completely new to me, so I have some problems to get them working.
I follow the Apple manual, which checks receipts locally, and I included openssl in my project as a static library. This is the code provided by Apple to verify the signature using OpenSSL:
BIO *b_receipt;
BIO *b_x509;
PKCS7 *p7 = d2i_PKCS7_bio(b_receipt, NULL);
X509_STORE *store = X509_STORE_new();
X509 *appleRootCA = d2i_X509_bio(b_x509, NULL);
X509_STORE_add_cert(store, appleRootCA);
BIO *b_receiptPayload;
int result = PKCS7_verify(p7, NULL, store, NULL, b_receiptPayload, 0);
if (result == 1)
{
}
I use this code to get a receipt and certificate:
NSData *receiptData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSData *certificateData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"AppleIncRootCertificate" withExtension:@"cer"]];
How can I use these two NSDatato initialize BIO b_receiptand variables b_x509?