I am currently implementing local receipt validation following Apple's Receipt Validation Programming Guide. I can obtain a test receipt but when I try to parse it as follows (i.e. as suggested in Listing 1-5 of the guide)
rval = asn_DEF_Payload.ber_decoder(NULL, &asn_DEF_Payload, (void **)&payload, pld, pld_sz, 0);
I receive the following error (output from ASN_DEBUG()
)
Expected: [UNIVERSAL 17], expectation failed (tn=0, tm=0)
asn_DEF_Payload
(and other C code) have been generated by the ans1c
(the ASN.1 Compiler, v0.9.24) with Listing 1-1 of the guide as input. I have first read in the receipt with NSData dataWithContentsOfURL
from the URL indicated by NSBundle appStoreReceiptURL
. pld
and pld_sz
are the data's bytes
and length
respectively.
What does this error denote and how can it be avoided?
UPDATE It looks as if the parser sees tag 16 (SEQUENCE and SEQUENCE OF) when it expects tag 17 (SET and SET OF) at the beginning of the test recipe. The definition of Payload in Listing 1-1 indeed refers to SET.
UPDATE I have managed the converter that comes with asn1c
as follows.
export CFLAGS=-DPDU=Payload
make -f Makefile.am.sample
./progname -h
I have also managed to copy the receipt from the physical iOS device to OS X like so. When I now try to dump the receipt with ./progname -d -iber -otext receipt
I get this output:
AD: Processing receipt
AD: Decoding 4704 bytes
AD: decode(0) consumed 0+0b (4704), code 2
AD: Clean up partially decoded structure
AD: ofp 1, no=0, oo=0, dbl=0
receipt.ber: Decode failed past byte 0: Input processing error
UPDATE Hmm, this online ASN.1 decoder can dump my test recipe just fine. (It starts with a SEQUENCE, though.) It's apparently a signature and my mistake is (might be) that I should get the payload from inside its signed envelope ...