How can my server securely authenticate iPhone in-app purchase?

前端 未结 4 1124
野的像风
野的像风 2020-12-04 06:31

Look at Apple\'s diagram for the server purchase model.

In step #9, how can the server know that it is really talking with an iPhone that is entitled to the purchase

4条回答
  •  清歌不尽
    2020-12-04 06:49

    UDID Does Not Work Anymore

    Beniot answer is great, however, these days, as mentioned by Joe D'Andrea, UDID is deprecated and the last time I tried, an App that used the call to get the UDID failed to pass validation during upload to iTunes.

    Time-limited Receipts as Alternative to Receipt Counters

    To add on to hloupyhonza's answer, besides having a "download request" counter for a particular receipt, you can just limit the receipt validity by time. I found anything between 12 to 24 hours reasonable.

    This method also allows the purchaser to use the purchase on any other device he owns as long as he logs into the App Store with the same Apple ID. Note: Each time Restore Purchases is done, Apple returns a completely new receipt (with details of the original receipt contained) - this allows purchases to be restored past the time limit we set for a particular receipt.

    Preventing "Off-The-Shelf" Hacks

    To prevent typical "Googled" hacking solutions (my data shows this constitutes almost all of IAP hacking attempts), I use a checksum (pick your favorite algorithm, doesn't matter unless you want to make it watertight) of the following concatenation:

    • receipt-data json string
    • A shared secret key
    • Validation success status code.

    The App will verify the checksum returned by our validation server. This is not watertight though, as the hacker may retrieve the shared key from your App's binary. But it has prevented all "off-the-shelf" hacks thus far and that's good enough for my use.

提交回复
热议问题