Class: ItunesReceiptDecoder::Decode::UnifiedReceipt

Inherits:
Base
  • Object
show all
Defined in:
lib/itunes_receipt_decoder/decode/unified_receipt.rb

Overview

ItunesReceiptDecoder::Decode::UnifiedReceipt

Constant Summary collapse

PUBLIC_KEY =
OpenSSL::PKey::RSA.new <<-PUBLIC_KEY
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyjhUpstWqsgkOUjpjO7s
X7h/JpG8NFN6znxjgGF3ZF6lByO2Of5QLRVWWHAtfsRuwUqFPi/w3oQaoVfJr3sY
/2r6FRJJFQgZrKrbKjLtlmNoUhU9jIrsv2sYleADrAF9lwVnzg6FlTdq7Qm2rmfN
UWSfxlzRvFduZzWAdjakh4FuOI/YKxVOeyXYWr9Og8GN0pPVGnG1YJydM05V+RJY
DIa4Fg3B5XdFjVBIuist5JSF4ejEncZopbCj/Gd+cLoCWUt3QpE5ufXN4UzvwDtI
jKblIV39amq7pxY1YNLmrfNGKcnow4vpecBqYWcVsvD95Wi8Yl9uz5nd7xtj/pJl
qwIDAQAB
-----END PUBLIC KEY-----
PUBLIC_KEY
RECEIPT_FIELDS =
{
  0 => :environment,
  2 => :bundle_id,
  3 => :application_version,
  4 => :opaque_value,
  5 => :sha1_hash,
  12 => :creation_date,
  17 => :in_app,
  19 => :original_application_version,
  21 => :expiration_date,
  1701 => :quantity,
  1702 => :product_id,
  1703 => :transaction_id,
  1705 => :original_transaction_id,
  1704 => :purchase_date,
  1706 => :original_purchase_date,
  1708 => :expires_date,
  1712 => :cancellation_date,
  1711 => :web_order_line_item_id
}
TIMESTAMP_FIELDS =
%i(creation_date expiration_date purchase_date
original_purchase_date expires_date
cancellation_date)

Instance Attribute Summary

Attributes inherited from Base

#environment, #options, #raw_receipt, #receipt

Instance Method Summary collapse

Methods inherited from Base

#initialize, #production?, #sandbox?

Constructor Details

This class inherits a constructor from ItunesReceiptDecoder::Decode::Base

Instance Method Details

#signature_valid?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/itunes_receipt_decoder/decode/unified_receipt.rb', line 67

def signature_valid?
  serial = pkcs7.signers.first.serial.to_i
  cert = pkcs7.certificates.find { |c| c.serial.to_i == serial }
  cert && cert.verify(PUBLIC_KEY)
end

#styleObject



55
56
57
# File 'lib/itunes_receipt_decoder/decode/unified_receipt.rb', line 55

def style
  :unified
end

#uuid_valid?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/itunes_receipt_decoder/decode/unified_receipt.rb', line 59

def uuid_valid?(uuid)
  digest = OpenSSL::Digest::SHA1.new
  digest << uuid.scan(/[0-9A-F]{2}/).map(&:hex).pack('c*')
  digest << @receipt[:opaque_value]
  digest << @raw_bundle_id
  digest.digest == @receipt[:sha1_hash]
end