GithubHelp home page GithubHelp logo

macchamps / appstorereceiptdecoder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from roop/appstorereceiptdecoder

0.0 1.0 0.0 116 KB

Decode the decrypted payload data in Apple App Store receipts.

Swift 98.98% Shell 1.02%

appstorereceiptdecoder's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.