applereceipt

package module
v0.0.0-...-d8eef1e Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 5 Imported by: 0

README

go-applereceipt Test Go Reference

Go library to parse and verify Apple App Store receipts, locally on the server.

The verifyReceipt endpoint is deprecated. To validate receipts on your server, follow the steps in Validating receipts on the device on your server. — https://developer.apple.com/documentation/appstorereceipts/verifyreceipt

This library implements the PKCS#7 signature verification and ASN.1 parsing of the payload locally on the server, without the need to call Apple's verifyReceipt endpoint. The parsed receipt is filled in a concrete AppReceipt struct, which is auto-generated based on the documented fields published by Apple.

Note that at this moment, receipts from Apple is signed using SHA1-RSA, which has removed support since Go 1.18 and requires GODEBUG=x509sha1=1 to verify receipts. SHA-256 signatures will be available from receipts since August 14, 2023. (TN3138)

Installation

go get github.com/devsisters/go-applereceipt

Usage

package main

import (
	"fmt"

	"github.com/devsisters/go-applereceipt"
	"github.com/devsisters/go-applereceipt/applepki"
)

func main() {
	receipt, err := applereceipt.DecodeBase64("MIIT...", applepki.CertPool())
	if err != nil {
		panic(err)
	}

	fmt.Println(receipt.BundleIdentifier)
}

Documentation

Overview

Code generated by gen.go. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppReceipt

type AppReceipt struct {
	// The app’s bundle identifier.
	BundleIdentifier string
	// The app’s version number.
	AppVersion string
	// An opaque value used, with other data, to compute the SHA-1 hash during validation.
	OpaqueValue []byte
	// A SHA-1 hash, used to validate the receipt.
	SHA1Hash []byte
	// The receipt for an in-app purchase.
	InAppPurchaseReceipts []InAppPurchaseReceipt
	// The version of the app that was originally purchased.
	OriginalApplicationVersion string
	// The date when the app receipt was created.
	ReceiptCreationDate time.Time
	// The date that the app receipt expires.
	ReceiptExpirationDate time.Time

	// Undocumented attributes
	Remaining []ReceiptAttribute
}

func Decode

func Decode(receipt []byte, certPool *x509.CertPool) (AppReceipt, error)

Decode decodes given receipt binary into AppReceipt type. It verifies the payload with given certPool. certPool can be nil to skip verification, but be careful that users can pass a forged receipt.

func DecodeBase64

func DecodeBase64(b64Receipt string, certPool *x509.CertPool) (AppReceipt, error)

DecodeBase64 decodes given base64-encoded receipt into AppReceipt type. It verifies the payload with given certPool. certPool can be nil to skip verification, but be careful that users can pass a forged receipt.

type InAppPurchaseReceipt

type InAppPurchaseReceipt struct {
	// The number of items purchased.
	Quantity int
	// The product identifier of the item that was purchased.
	ProductIdentifier string
	// The transaction identifier of the item that was purchased.
	TransactionIdentifier string
	// For a transaction that restores a previous transaction, the transaction identifier of the original transaction. Otherwise, identical to the transaction identifier.
	OriginalTransactionIdentifier string
	// The date and time that the item was purchased.
	PurchaseDate time.Time
	// For a transaction that restores a previous transaction, the date of the original transaction.
	OriginalPurchaseDate time.Time
	// The expiration date for the subscription, expressed as the number of milliseconds since January 1, 1970, 00:00:00 GMT.
	SubscriptionExpirationDate time.Time
	// For an auto-renewable subscription, whether or not it is in the introductory price period.
	SubscriptionIntroductoryPricePeriod int
	// For a transaction that was canceled by Apple customer support, the time and date of the cancellation. For an auto-renewable subscription plan that was upgraded, the time and date of the upgrade transaction.
	CancellationDate time.Time
	// The primary key for identifying subscription purchases.
	WebOrderLineItemID int

	// Undocumented attributes
	Remaining []ReceiptAttribute
}

type ReceiptAttribute

type ReceiptAttribute struct {
	Type    int
	Version int
	Value   []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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