Validating App Store Receipts Without verifyReceipt
An App Store receipt is more than an opaque token to hand to a server. It is a signed container holding a snapshot of a user's purchase history, and Apple documents enough of its structure that you can inspect it yourself. This guide walks through the container format, the trust chain behind the signature, and the custom ASN.1 layout of the receipt payload, then explains where local parsing stops being a good idea.
What an App Store Receipt Actually Contains
Receipts have long been treated as tokens: read the file, base64-encode it, and ship it to a server. That habit hides what the file really is. Since iOS 7, Apple has exposed a disk location through NSBundle.appStoreReceiptURL, and the file at that location is meant to serve as the source of truth for in-app purchases instead of the StoreKit payment queue, which is awkward to build around.
The receipt is a documented binary structure, not a black box. It carries most of the same information you would otherwise retrieve by validating through Apple's /verifyReceipt endpoint, which is why it is worth understanding before deciding whether to parse it yourself.
Checking the Receipt Signature
The file is encoded with ASN.1, an older binary encoding scheme comparable to Protobuf or Thrift. Apple wraps the actual receipt data, itself another ASN.1 blob, inside a PKCS#7 container. That container holds three things: the signed data, a signature, and the certificates needed to verify the signature.
The walkthrough uses Python. The first step parses the PKCS#7 container and pulls out the certificates, the signature, and the receipt data. The parsing code is provided in the accompanying module and is not reproduced here.
Apple guarantees receipt contents with asymmetric cryptography. It hashes the receipt data, encrypts that hash with a private key only Apple holds, and calls the result a signature. Because only Apple's published public key can decrypt the hash, a matching hash proves the data is exactly what Apple signed, with no round trip to Apple required.
Verification works in reverse. Decrypt the signature to recover Apple's hash, compute the same hash over the included receipt data with the same hashing function, and compare the two. A match means the receipt data has not been altered since Apple signed it.
Apple does not sign receipts with its root certificate directly. Instead it issues a chain of trust: the Apple Root Certificate, a World Wide Developer Relations Intermediate Certificate, and the iTunes App Store Certificate, which is the one that actually signs the receipt data. The receipt typically carries all three.
To anchor that chain, obtain a trusted copy of the Apple Root Certificate from Apple. Assuming the machine has not been compromised by a determined in-app-purchase cracker, that certificate can be trusted, and it bootstraps trust in the certificates bundled inside the receipt. The trusted root validates the WWDR certificate, and the validated WWDR certificate in turn validates the iTunes App Store Certificate. The OpenSSL Python wrapper supplies the store and context objects needed for these checks.
With the iTunes App Store Certificate extracted and validated, it can verify the signature on the receipt data. At that point the container is unpacked, the certificates are validated against a trusted root, and the signature is confirmed, so the receipt data can be treated as unmodified since Apple signed it. The next phase is reading the purchase information inside.
Reading the Receipt Fields
The signed receipt data is also an ASN.1 container, but it uses a custom format Apple created for App Store receipts rather than a public specification like PKCS#7 or X.509. Apple documents the fields, and the same reference page is often used when reading Apple's JSON responses.
The structure is loose. A ReceiptAttribute is a tuple of an integer type, an integer version, and an octet-string value, and the payload is a set of those records. The type field, read alongside Apple's documentation, tells you how to interpret the binary value blob. The asn1crypto module lets you declare custom types so much of the parsing is handled automatically.
Once the attributes are parsed, they can be collected into a dictionary, since all but one type appears only once, and converted to native Python types. The in_app type is the exception: it can appear many times, so those values are set aside for a second pass. The resulting dictionary holds much of the same data you would expect in a /verifyReceipt response.
Reading In-App Purchase Records
The top-level fields describe the app purchase or download, but the in-app purchases are usually the interesting part. Each in_app attribute value is itself an ASN.1 container with a definition that mirrors the top-level receipt: a sequence of type, version, and value, collected into a set.
The same extraction routine applies to each in-app record, producing native Python objects. The captured sample output shows the shape of the result: a receipt dictionary with bundle_id, application_version, creation_date, opaque_value, original_application_version, and sha1_hash, plus an in_app list. In that sample the list holds three records for the product onemonth_freetrial, all sharing original_transaction_id 1000000339835086, with successive purchase_date and expires_date values and distinct transaction_id values. That pattern is what a renewal sequence looks like when read straight from the receipt.
At this point the receipt has been unpacked and validated without sending it to Apple.
Where Local Validation Falls Short
Local parsing has real limits. The largest is that subscription-related fields such as latest_receipt_info and pending_renewal_info are not available. The receipt file is only a snapshot, and you may need to update a user's subscription state even when they have not sent the most recent receipt.
Validating receipts yourself is also error-prone, close to the advice against rolling your own crypto: risky and usually unnecessary. The walkthrough's own code is explicitly not meant for production validation. It also skips important checks such as certificate expiration. For most teams, Apple's /verifyReceipt service or a dedicated subscription platform is the safer path than maintaining this logic in-house.
| Type code | Field name | Parsed as |
|---|---|---|
| 2 | bundle_id | UTF8String |
| 3 | application_version | UTF8String |
| 4 | opaque_value | OctetString |
| 5 | sha1_hash | OctetString |
| 12 | creation_date | IA5String |
| 17 | in_app | OctetString |
| 19 | original_application_version | UTF8String |
| 21 | expiration_date | IA5String |
Type codes and value types are taken from the published walkthrough's custom ASN.1 mapping. Only the in_app type appears more than once in a receipt.
| Type code | Field name | Parsed as |
|---|---|---|
| 1701 | quantity | Integer |
| 1702 | product_id | UTF8String |
| 1703 | transaction_id | UTF8String |
| 1704 | purchase_date | IA5String |
| 1705 | original_transaction_id | UTF8String |
| 1706 | original_purchase_date | IA5String |
| 1708 | expires_date | IA5String |
| 1711 | web_order_line_item_id | Integer |
| 1712 | cancellation_date | IA5String |
| 1719 | is_in_intro_offer_period | Integer |
Each in_app value is itself an ASN.1 set of these attributes, parsed with the same tuple structure as the top-level receipt.
Frequently asked questions
Why would I parse a receipt locally instead of calling Apple's /verifyReceipt endpoint?
The receipt already contains most of the information that endpoint returns, so parsing it locally avoids a round trip and keeps the data on your side. The tradeoff is that you take on the cryptography and parsing yourself, and the walkthrough's own code is explicitly not production-ready. For most teams the endpoint or a managed service remains the lower-risk choice.
What is the difference between a bad signature and a bad certificate?
A certificate failure means the chain of trust did not validate: the WWDR certificate or the iTunes App Store Certificate could not be traced back to the trusted Apple Root Certificate. A signature failure means the certificates checked out but the hash recomputed from the receipt data did not match the hash decrypted from Apple's signature, which indicates the data was altered after signing.
Can I get subscription renewal details from the receipt file alone?
Not fully. Fields such as latest_receipt_info and pending_renewal_info are not available from the receipt file. Because the file is only a snapshot, you may need to update a user's subscription state even when they have not sent you their most recent receipt.
The receipt data signature is valid.
{'application_version': '1',
'bundle_id': 'com.jacobeiting.subtester',
'creation_date': '2017-10-03T00:58:43Z',
'opaque_value': b'\xdb\x81(\xb1=\xce.<i\xbdkS\xc6\xbe%\x08',
'original_application_version': '1.0',
'sha1_hash': b',\x88\x7f\x9f4\x1b\xc2\xa9W\x18\x1d\x81\x1c%\xbb\x91"*\xe97'}
in_apps count = 8{'application_version': '1',
'bundle_id': 'com.jacobeiting.subtester',
'creation_date': '2017-10-03T00:58:43Z',
'in_app': [{'cancellation_date': '',
'expires_date': '2017-10-02T23:16:23Z',
'original_purchase_date': '2017-10-02T23:08:25Z',
'original_transaction_id': '1000000339835086',
'product_id': 'onemonth_freetrial',
'purchase_date': '2017-10-02T23:11:23Z',
'quantity': 1,
'transaction_id': '1000000339835183',
'web_order_line_item_id': 1000000036447552},
{'cancellation_date': '',
'expires_date': '2017-10-02T23:21:23Z',
'original_purchase_date': '2017-10-02T23:08:25Z',
'original_transaction_id': '1000000339835086',
'product_id': 'onemonth_freetrial',
'purchase_date': '2017-10-02T23:16:23Z',
'quantity': 1,
'transaction_id': '1000000339835291',
'web_order_line_item_id': 1000000036447572},
{'cancellation_date': '',
'expires_date': '2017-10-02T23:11:23Z',
'original_purchase_date': '2017-10-02T23:08:25Z',
'original_transaction_id': '1000000339835086',
'product_id': 'onemonth_freetrial',
'purchase_date': '2017-10-02T23:08:23Z',
'quantity': 1,
'transaction_id': '1000000339835086',
'web_order_line_item_id': 1000000036447550}],
'opaque_value': b'\xdb\x81(\xb1=\xce.<i\xbdkS\xc6\xbe%\x08',
'original_application_version': '1.0',
'sha1_hash': b',\x88\x7f\x9f4\x1b\xc2\xa9W\x18\x1d\x81\x1c%\xbb\x91"*\xe97'}