4

I'm banging my head with receipt validation.

I'm in a phase where I validate if certificate is valid and I need to parse ASN1 file.

Apple suggest to use asn1c, like :

 #include "Payload.h" /* This header file is generated by asn1c. */

 void *pld = NULL;
 size_t pld_sz;

 Payload_t *payload = NULL;
 asn_dec_rval_t rval;

 rval = asn_DEF_Payload.ber_decoder(NULL, &asn_DEF_Payload, (void **)&payload, pld, pld_sz, 0);

I already download asn1c-master.zip from: https://github.com/vlm/asn1c

Now I don't know how to install this lib into Xcode, and if I need some extra work or can I start as apple example after installing asn1c?

Thanks for help.

EDIT :

I do as instructed in INSTALL file : in asn1c-master file I run in terminal :

./configure
make
make check
make install

After that I create in separate folder file receipt.asn1 and add this text in it :

 ReceiptModule DEFINITIONS ::=
 BEGIN

 ReceiptAttribute ::= SEQUENCE {
     type    INTEGER,
     version INTEGER,
     value   OCTET STRING
 }

 Payload ::= SET OF ReceiptAttribute

 END

After that I run

asn1c -fnative-types receipt.ans1

But I gut out :

-fnative-types: Deprecated option
ASN.1 grammar parse error near line 1 (token "{"): syntax error, unexpected '{', expecting TOK_typereference or TOK_capitalreference
Cannot parse "receipt.asn1"
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97

1 Answers1

3

After following the instructions in http://github.com/vlm/asn1c/blob/master/INSTALL

I do the following, in a new directory (i.e., Mac OS X folder):

# Terminal command line from: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW3
asn1c -fnative-types receipt.ans1
# the file receipt.ans1 has contents from Listing 1-1 in the above URL

# converter-sample.c has a main. Don't want that!
rm converter-sample.c

rm Makefile.am.sample

Then, make sure to drag the resulting .c and .h files into an Xcode group, don't put the Mac folder directly into the project,or otherwise, the .c and .h files will not be added to the project. Thus, they won't build and you'll get linker errors

Chris Prince
  • 7,288
  • 2
  • 48
  • 66
  • Thank you for your answer. I don't know if I need to create receipt.ans1 for myself or asn1c -fnative-types receipt.ans1 should create it for me. If I don't create file terminal says: `Deprecated option receipt.ans1: No such file or directory Cannot parse "receipt.ans1"`. If I do create such file terminal says : `ASN.1 grammar parse error near line 1 (token "{"): syntax error, unexpected '{', expecting TOK_typereference or TOK_capitalreference Cannot parse "receipt.ans1"`. There cab't be syntax error because I copy text from apple side. – Marko Zadravec Mar 31 '14 at 05:05
  • Please do the following at the Terminal and paste the result into your question: cat receipt.ans1 – Chris Prince Mar 31 '14 at 14:20
  • Your answer was right. What I didn't see is that if converting .rtf into .txt, some character are replaced and create invalid parsing file. – Marko Zadravec Apr 01 '14 at 06:41