Initialize BIO variable with NSData bytes on iphone

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)
{
    // Receipt signature is Valid
    // b_receiptPayload contains the payload
}

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?

+4
1

http://www.openssl.org/docs/crypto/BIO_s_mem.html:

BIO *BIO_new_mem_buf(void *buf, int len);

BIO .

BIO *b_receipt = BIO_new_mem_buf((void *)[receiptData bytes], (int)[receiptData length]);

. receiptData b_receipt, .

BIO_new_mem_buf() , void * cast, "" const void * " " void * 'discards qualifiers ".

+7

All Articles