Because the business needs to implement in-app purchase processing, but in the process of a part of the uncontrolled factors, causing some users to reflect that there is no charge and leakage of a single case.
Careful consideration of a number of pay security issues, all involved in the issue of payment is very sensitive, any party loss is unacceptable, so here to tidy up some of the key to pay security to share.
Payment Methods
IAP refers to In-app Purchase, which is a payment method, not Apple's proprietary payment method, which can also be implemented on other platforms, for Apple IAP.
When it comes to IAP security, there is an obvious logical flaw in Apple's IAP process, which is based on our improper handling, which can lead to problems between the services we provide and the users. First look at the IAP Payment sequence diagram:
Payment Process
1. The client requests the purchase of a product from AppStore (provided that the product information has been obtained) and AppStore verifies that the product has been successfully deducted from the user's Apple account balance.
2.Appstore returns a receipt-data to the client, which records the certificate and signature information for the transaction.
3. The client provides receipt-data to the servers we can trust
4. The server Receipt-data the Base64 code once
5. Send the encoded receipt-data to Itunes.appstore for verification
6.itunes.appstore return validation results to the server
7. The server to the product purchase status and product type, to the client to issue corresponding props and push data Update notification
These seven steps are actually a very safe process. What is the problem? Let's talk about two types of Apple IAP validation models.
Authentication Method
1.IAP built-in Model, local authentication
Some apps or even online games, have skipped the 3~7 step directly, after the 2nd step to get Receipt-data, directly from the client to Itunes.appstore send a verification request, and get results, modify the data according to the results.
When we design the app, we follow the truth that "all the data on the client is unsafe", and it's a deep thought. If there is no independent server-assisted verification, this will avoid the fact that data has been modified, yes, you will make less money.
However, if the app is not verified by a standalone server, it is a bit scary to let the server state release the game props after the client has verified it. This is the IAP built-in Model
Is that simply not going to make the process safe? No, but this security only makes the changes difficult. Apple officially provided the Validating receipts locally to authenticate the Receipt-data on the client side, primarily to verify the validity of the certificate and the signature. If you don't want to write code validation yourself, you can also use the Receipt-data authentication API provided by a third-party organization, which is more famous for urbanairship and Beeblex.
But if it is possible to forge a perfectly legal receipt-data, the same can be achieved by deception. Yes, in order to bypass validating locally, so hackers began to use their own forged receipt-data counter switch, so there is a "legitimate order" can be forged in-appstore. Therefore, this method of locally enhanced authentication does not completely avoid IAP attacks.
2.IAP server Model, authentication for servers
And if we move the validation logic to the server, the process becomes much easier. Because there's no need to worry about Receipt-data being faked. But even if the steps are 4~7 on the server, there are some naïve logic holes:
Reponse content that validates receipt-data is not verified and documented, and products are issued directly based on product. This way, as long as the client submits receipt-data, you need to constantly verify and repeat the product as normal logic. A more secure approach is to:
After each receipt of the Receipt-data, the submitted user account and the Receipt-data in the number of the map and recorded, in each verification receipt-data, first determine whether it already exists.
As long as this verification is done, the entire payment process becomes clear.
ensure successful submission and exception handling of Receipt-data
Based on the IAP server model, and we know that the mobile network is not stable, after the successful payment cannot ensure that the Receipt-data must be submitted to the server. If this is the case, it means that the user was AppStore charge, but did not receive the server issued props. (This leads to a missing sheet)
The solution to this problem is to submit receipt-data to our server on the client, and let our server send a verification request to the Apple server to verify the validity of this receipt-data bill. Before the reply is received, the client must save the Receipt-data and initiate a request to the server on a regular or reasonable UI interface until the server's reply is received and the client's receipt billing record is deleted.
What if the client did not successfully commit the receipt-data? Is the user is deducted fees, also received appstore consumption receipts, but still confiscated props, so complained to the customer service department.
This situation also occurs in previous experiences, with common user and operator disputes. Customer service to the user to request the account number and AppStore receipt number, through the query itunes-connect see if there is indeed this order.
If the order exists, then to contact the developer to query the server, see if the order number and user name corresponds, and whether it has been used, to do this check is to prevent malicious users from using the order number has been used to deceive (verified bill can be re-request verification, once for testing, Manually send the bill to the server for processing and success, falsely claiming to have confiscated the goods.
Of course, if you do not find this order number, it means that the order has not been used, manually to the user to reissue the product can be.
A friend asked how to view the specific order through Itunes-connect, Itunes-connect can not directly see the order information, the following ways to query
1. Bill verification can be sent to Apple via bill and can be replaced manually
2. Compare the list of recorded bills with your own server
3. Use of third-party talkingdata and other trading functions, will automatically record billing data
Recommended
In order to ensure the approval, the client or server needs two-step verification, that is, the verification of the online transaction verification address, if Apple formally verify that the server's return verification code code is 21007, then once again connected to the Sandbox test server for verification.
In the application of arraignment, Apple IAP interrogation is carried out in the sandbox environment, namely: Apple in the Audit app, only in the sandbox environment to buy, the resulting purchase voucher, but also only connect to Apple Test authentication server, if not do double authentication, need to pay special attention to this issue, otherwise it will be rejected.
other
Verify the Receipt:https://sandbox.itunes.apple.com/verifyreceipt in the sandbox
Validating receipt:https://buy.itunes.apple.com/verifyreceipt in a production environment
So how to automatically identify whether the receipt is a sandbox receipt it?
There are two ways to identify receipts in a sandbox environment:
- According to the receipt field environment = sandbox.
- Verify the status code returned by the interface based on the receipt.
If status=21007, indicates that the current receipt is the receipt for the sandbox environment and is validated.
Status code for Apple feedback
- 21000 APP Store does not read the JSON data you provide
- 21002 The receipt data does not conform to the format
- 21003 receipts cannot be verified
- 21004 the shared key you provided is inconsistent with the shared key of the account
- 21005 the receipt server is not currently available
- 21006 the receipt is valid, but the subscription service has expired. When this message is received, the decoded receipt information is also included in the returned content
- 21007 Receipt information is test (sandbox), but is sent to the product environment to verify
- 21008 The receipt information is used in the product environment but is sent to the test environment to verify
by Hgq
The thinking that the invoice verification and the leaking list in iOS purchase service side.