Skip to content

roop/AppStoreReceiptDecoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

App Store Receipt Decoder

The Apple App Store receipt is a PKCS7 container signed with Apple's private key and needs to be decrypted with Apple's public key to obtain the contained payload data. The payload data is in ASN.1 DER format.

This project helps in decoding that format.

Usage

To try it, run ./run.sh

To use it in your Swift project, add AppStoreReceipt.swift to the project and use it like this:

let data: NSData // data output from PKCS7_verify
var bundleId: String?
var bundleIdData: NSData?
let receipt = AppStoreReceipt(payloadData: data)
receipt.enumerateReceiptAttributes { (type, version, value) in
    switch (type) {
        case 2: // Bundle id
            bundleId = AppStoreReceipt.decodeASN1String(value)
            bundleIdData = value
        ...
        default:
            break
    }
}

To use it in your Objective-C project, add AppStoreReceipt.swift to the project, add the @objc attribute to the AppStoreReceipt Swift class, import the Swift header (see 'Using Swift from Objective-C' in Using Swift with Cocoa and Objective-C), and use it like this:

NSData* data; // data output from PKCS7_verify
__block NSString* bundleId;
__block NSData* bundleIdData;
AppStoreReceipt *receipt = [AppStoreReceipt receiptWithPayloadData: data];
[receipt enumerateReceiptAttributes:^(NSInteger type, NSInteger version, NSData * __nonnull value) {
    switch (type) {
        case 2:
            bundleId = [AppStoreReceipt decodeASN1String:value];
            bundleIdData = value;
            break;
        ...
        default:
            break;
    }
}];

See main.swift for a more detailed example.

Why

Integrating the ASN.1 compiler-generated code with an iOS project introduces multiple source files and warnings, and is not Swift 1.2-friendly because of the use of function pointers.

This project provides a clean one-file receipt decoder in Swift.

About

Decode the decrypted payload data in Apple App Store receipts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published