(IOS-iap protection) verifies the user's payment receipt and rejects iap Cracker

Source: Internet
Author: User

For iOS app security, there are two main parts that can be avoided by developers. One is to store data encryption. in the previous article, Himi introduced the base64 encryption algorithm; the other is paid product protection! In this article, we will share with you how to protect iap Cracker for jailbreaking users!

For the iap Cracker plug-in, Himi briefly introduces it!

Iap Cracker can be said to be the ultimate tool for iOS jailbreak users. In today's app Store, all built-in paid Games use this plug-in for second-level purchase without pressure! (For paid games, install a XX assistant for jailbreaking users. <You know ~~> You will be able to experience all the games in the app store for free, no matter whether you are charged for downloading or built-in fees !)

Iap Cracker can bypass the payment process of the appstore by simulating a message indicating a successful purchase after you click the paid product to purchase the appstore, no post data is sent to the App store !), Then, we received the "fake" transaction success message in our application and directly added money, equipment, and various types to the user ....

OK. I will not introduce iap Cracker any more. Let's talk about how to protect iap Cracker in Himi;

Apple did not care about the issue of using paid cracking plug-ins to pay for jailbreak users, but it has been clearly stated in the document, but many children's shoes have not been found, as follows:


 

 

Apple prompts developers to pay for the verification payment receipt! Original apple dev official documentation connection:
Https://developer.apple.com/library/ios/?documentation/networkinginternet/conceptual/storekitguide...
The following Himi explains in detail how to add iap protection to our payment process:
1. First import the json class library and NSData + Base64 class into your project. Download:
Json_base.rarhttp: // www.himigame.com /? Dl_id = 70 (105 bytes, 14 times)
2. Then copy the following Himi encapsulated functions to the class where your paid code is located:
 
In 1. h:
2.-(BOOL) putStringToItunes :( NSData *) iapData;
3.
4. m:
5.
6. # import "NSData + Base64.h"
7. # import "NSString + SBJSON. h"
8. # import "JSON. h"
9.
10.-(BOOL) putStringToItunes :( NSData *) iapData {// transactionReceipt
11.
12. NSString * encodingStr = [iapData base64EncodedString];
13.
14. NSString * URL = @ "https://sandbox.itunes.apple.com/verifyReceipt ";
15. // https://buy.itunes.apple.com/verifyReceipt
16. NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init]; // autorelease];
17. [request setURL: [NSURL URLWithString: URL];
18. [request setHTTPMethod: @ "POST"];
19. // set contentType
20. [request addValue: @ "application/json" forHTTPHeaderField: @ "Content-Type"];
21. // set Content-Length
22. [request setValue: [NSString stringWithFormat: @ "% d", [encodingStr length] forHTTPHeaderField: @ "Content-Length"];
23.
24. NSDictionary * body = [NSDictionary dictionaryWithObjectsAndKeys: encodingStr, @ "receipt-data", nil];
25. SBJsonWriter * writer = [SBJsonWriter new];
26. [request setHTTPBody: [writer stringWithObject: body] dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: YES];
27. NSHTTPURLResponse * urlResponse = nil;
28. NSError * errorr = nil;
29. NSData * receivedData = [NSURLConnection sendSynchronousRequest: request
30. returningResponse: & urlResponse
31. error: & errorr];
32.
33. // resolution
34. NSString * results = [[NSString alloc] initWithBytes: [receivedData bytes] length: [receivedData length] encoding: NSUTF8StringEncoding];
35. CCLOG (@ "-Himi-% @", results );
36. NSDictionary * dic = [results JSONValue];
37. if ([[dic objectForKey: @ "status"] intValue] = 0) {// note that status = @ "0" indicates that the receipt is successfully verified.
38. return true;
39 .}
40. return false;
41 .}
1.-(void) paymentQueue :( SKPaymentQueue *) queue updatedTransactions :( NSArray *) transactions // transaction result
2 .{
3. for (SKPaymentTransaction * transaction in transactions)
4 .{
5. switch (transaction. transactionState)
6 .{
7. case SKPaymentTransactionStatePurchased: // transaction completed
8. if ([self putStringToItunes: transaction. transactionreceept]) {
9. // here we will add money and equipment to users.
10 .}
11. break;
12 ...... the code is omitted
13 .}
14 .}
15 .}
The above function enters the SKPaymentTransactionStatePurchased case when messages are obtained successfully (whether it is a message simulated by iap cracker or actually fed back by appstore). Therefore, we generally do not use iap protection, they will directly add gold coins to users in this case! However, as I mentioned above, because iap cracker will simulate a message that returns a successful transaction and enter this case, we will perform another receipt verification with appstore here!
Next, let's talk about the usage of this method. In the general payment code, kids shoes will certainly have the following functions:
In addition, when the transaction is completed, the transactionreceept attribute in the transaction (SKPaymentTransaction) class passed back by appstore contains the signed receipt information returned by AppStore! OK. We need this receipt and post it to the appstore server for receipt verification, therefore, in the case that the SKPaymentTransactionStatePurchased transaction is successful, call the Himi encapsulated function if ([self putStringToItunes: transaction. transactionreceip]) {} re-confirm whether the payment process is correct!
The putStringToItunes function encapsulated by Himi is described as follows:
In this function, we first convert the input data type variable of the receipt to the string type, and then send the receipt to the appstore in json format for verification! Note here! It must be sent in json format, otherwise the appstore server does not recognize it!
Finally, we use json to parse the field (json data) returned by the appstore server. We only need to parse the value of the key "status!
When the appstore verification receipt is correct, the value of the status key we parsed is 0 (0 )!
Below are two forms of json data returned by appstore:
1. Invalid receipt:
1. {"status": 21002, "exception": "java. lang. NullPointerException "}
 
2. If the receipt is correct (click to enlarge ):


 
 

Note that the post address in the Himi-encapsulated function must be modified when it is released!
Because when you test the sandbox, the address is: https://sandbox.itunes.apple.com/verifyReceipt.
But the post address after the official release should be: https://buy.itunes.apple.com/verifyReceipt
Do not forget to modify it when publishing an application!
OK. This article will introduce it here. I hope it will be helpful for children's shoes that have no iap protection!

 
From Li huaming Himi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.