iaplocal

package module
v0.0.0-...-929bddb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

README

GoDoc Build Status

Description

iaplocal is a Go library that supports Apple Local In-App Purchase (IAP) receipt processing.

  • Verify the receipt signature against App Root CA certificate.
  • Parse the receipt from binary, extract in-app receipts.
  • Validate the receipts hash with host GUID.

Installation

go install github.com/googollee/iaplocal

Usage

The simplest possible usage is:

rootBytes, _ := ioutil.ReadFile("./AppleComputerRootCertificate.cer")
rootCA, _ := x509.ParseCertificate(rootBytes)

receiptB64, _ := ioutil.ReadFile("./receipt_b64")
receiptBytes, _ := base64.StdEncoding.DecodeString(string(receiptB64))
receipt, _ := iaplocal.Parse(rootCA, receiptBytes)

guid, _ := uuid.FromString(hostGUID)
receipt.Verify(guid)

License

See LICENSE.

Documentation

Overview

Package iaplocal supports Apple Local In-App Purchase (IAP) receipt processing.

It loads the receipt from binary, parses the receipt's attributes, and verifies the receipt signature and hash.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCertificate returns when parse a receipt
	// with invalid certificate from given root certificate.
	ErrInvalidCertificate = errors.New("iaplocal: invalid certificate in receipt")
	// ErrInvalidSignature returns when parse a receipt
	// which improperly signed.
	ErrInvalidSignature = errors.New("iaplocal: invalid signature of receipt")
)

Functions

This section is empty.

Types

type Receipt

type Receipt struct {
	Quantity              int       `json:"quantity"`
	ProductID             string    `json:"product_id"`
	TransactionID         string    `json:"transaction_date"`
	PurchaseDate          time.Time `json:"purchase_date"`
	OriginalTransactionID string    `json:"original_transaction_id"`
	OriginalPurchaseDate  time.Time `json:"original_purchase_date"`
	ExpiresDate           time.Time `json:"expires_date"`
	WebOrderLineItemID    int       `json:"web_order_line_item_id"`
	CancellationDate      time.Time `json:"cancellation_date"`
	IsInIntroPrice        bool      `json:"is_in_intro_offer_period"`
}

Receipt is the receipt for an in-app purchase.

type Receipts

type Receipts struct {
	BundleID                   string    `json:"bundle_id"`
	ApplicationVersion         string    `json:"application_version"`
	OpaqueValue                []byte    `json:"opaque_value"`
	SHA1Hash                   []byte    `json:"sha1hash"`
	CreationDate               time.Time `json:"creation_date"`
	InApp                      []Receipt `json:"in_app"`
	OriginalApplicationVersion string    `json:"original_application_version"`
	ExpirationDate             time.Time `json:"expiration_date"`
	// contains filtered or unexported fields
}

Receipts is the app receipt.

func Parse

func Parse(root *x509.Certificate, data []byte) (Receipts, error)

Parse parses a receipt binary which certificates with root certificate. Need decode to DER binary if recevied a base64 file.

func (*Receipts) Verify

func (r *Receipts) Verify(guid []byte) bool

Verify verifys the receipts with given guid. TestReceiptValidate shows how to get GUID from string. Check https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW5

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL