Work with Cydia Store API - ios

I made a payed app for Cydia. I like to verify if the user officially bought the application. I already figured out, that there is a Cydia Store API but I have several issues with it. Does anyone ever used it or is there an alternative to verify if the user bought it? The API is using the UDID, which has been made unaccessable in iOS 7, however Cydia and several other application can access the UDID. I figured out that you can calculate the UDID with SHA1 hash of serial + IMEI + wifiMac + bluetoothMac and with the SHA1 hash of serial + ECID + wifiMac + bluetoothMac on the Verizon iPhone 4. I can get the Serial number, but I am not able to get the IMEI, ECID, WiFi MAC and the Bluetooth MAC. Is there a methode to get the UDID on iOS 7?
I really appreciate your help!
Edit
After a long night I figured out how to get the UDID of an device on iOS 7. Its fairly easy.
Add "libMobileGestalt.dlib" and "libMobileGestaltExtensions.dlib" to your "Linked Frameworks and Libraries"
Download MobileGestalt.h and add it to your project
Copy to get the UDID of the device:
CFStringRef value =MGCopyAnswer(kMGUniqueDeviceID);
NSString *udid = (__bridge NSString *)(value);
CFRelease(value);
Now I just have to know how to correctly calculate the signature. This is my current way.
NSString *signature = [self hmacsha1:[[[[NSString stringWithFormat:#"%#", [[dataString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] dataUsingEncoding:NSUTF8StringEncoding]] stringByReplacingOccurrencesOfString:#" " withString:#"+"] stringByReplacingOccurrencesOfString:#"<" withString:#""] stringByReplacingOccurrencesOfString:#">" withString:#""].uppercaseString key:#"abcdef0123456789abcdef0123456789"];
signature = [self toBase64String:signature];
signature = [[[signature stringByReplacingOccurrencesOfString:#"+" withString:#"_"] stringByReplacingOccurrencesOfString:#"/" withString:#"_"] stringByReplacingOccurrencesOfString:#"=" withString:#""];
But somehow the signature is wrong, so the response is: signature=THE_SIGNATURE&error=invalide+signature+MY_QUERY
And I don't know why, because I am hmac_sha1 hashing the text with a key, this is my hashing function:
+(NSString *)hmacsha1:(NSString *)text key:(NSString *)secret {
const char *cKey = [secret cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [text cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC
length:sizeof(cHMAC)];
NSString *hash = [HMAC base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
return hash;
}

Related

iOS Enterprise App Distribution – Provisioning Profile expired

How I can check in App when expired Provisioning Profile and notify user about date?
Example
I have found here. But this file is not included in a bundle of the project. Maybe there are some options? Thanks
Despite this being a MAC OS X prov checker, it applies all the same to iOS too:
https://github.com/LigeiaRowena/ProvisioningInfo
Personally, that information shouldn't bother your users. You should have a clear record of when they expire, and notify the users via push notifications and/or some form of REST api for expiration dates.
Ideally, the best way to handle this is to periodically (at least once a year) push out an update with nothing more than a new embedded mprov.
Do you specifically need your users to notify you as to when your provisioning profiles are expiring?
But in terms of reading the plist file:
[NSDictionary dictionaryWithContentsOfFile:#"path/to/file.plist"]
This also seems to be a previously answered question at:
Get the EXPIRATION date of a Provisioning Profile at Run-time?
but to reiterate the code:
- (NSString*) getExpiry{
NSString *profilePath = [[NSBundle mainBundle] pathForResource:#"embedded" ofType:#"mobileprovision"];
// Check provisioning profile existence
if (profilePath)
{
// Get hex representation
NSData *profileData = [NSData dataWithContentsOfFile:profilePath];
NSString *profileString = [NSString stringWithFormat:#"%#", profileData];
// Remove brackets at beginning and end
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:#""];
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(profileString.length - 1, 1) withString:#""];
// Remove spaces
profileString = [profileString stringByReplacingOccurrencesOfString:#" " withString:#""];
// Convert hex values to readable characters
NSMutableString *profileText = [NSMutableString new];
for (int i = 0; i < profileString.length; i += 2)
{
NSString *hexChar = [profileString substringWithRange:NSMakeRange(i, 2)];
int value = 0;
sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
[profileText appendFormat:#"%c", (char)value];
}
// Remove whitespaces and new lines characters
NSArray *profileWords = [profileText componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//There must be a better word to search through this as a structure! Need 'date' sibling to <key>ExpirationDate</key>, or use regex
BOOL sibling = false;
for (NSString* word in profileWords){
if ([word isEqualToString:#"<key>ExpirationDate</key>"]){
NSLog(#"Got to the key, now need the date!");
sibling = true;
}
if (sibling && ([word rangeOfString:#"<date>"].location != NSNotFound)) {
NSLog(#"Found it, you win!");
NSLog(#"Expires: %#",word);
return word;
}
}
}
return #"";
}

NSString init with data by encoding NSJapaneseEUCStringEncoding fails on IOS 8 simulator

I used to be able to convert EUC japanese data into NSString by using the following code. The expected result is "目標".
But I just tried to use IOS 8 simulator and the result is null.
const char bytes[]={0xcc, 0xdc, 0xc9, 0xb8};
NSData *d=[[NSData alloc] initWithBytes:bytes length:sizeof(bytes)];
NSString *s=[[NSString alloc] initWithData:d encoding:NSJapaneseEUCStringEncoding];
NSLog(#"%#",s);
Any one knows if this is a bug or something I failed to notice?

How to encode the string in to "windows-1252" using ios?

The following string is working perfectly in android,please give me suggestion for encoding this in ios.
Android Example:String s = "hhh";
s.getBytes("Windows-1252");
A quick look at the docs for NSString would give you:
NSString *s = #"hhh";
NSData *data = [s dataUsingEncoding:NSWindowsCP1252StringEncoding];
uint_8 *bytes = [data bytes];
The equivalent code in iOS looks like this
NSString *str = #"hhh";
char buffer[100];
[str getCString:buffer maxLength:100 encoding:NSWindowsCP1252StringEncoding];

Difficulty dealing with encoding in SQLite

I'm trying to get information from a SQLite file, and I when I run a query, the information is returned with ASCII encoding. I'm using the code below to put the returned information into a string.
[NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 2) encoding:NSASCIIStringEncoding];
When I try to use UTF8 encoding to put the returned information into a string, it doesn't work. The code below is used in the app currently on the store.
[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
The string is null. How can I convert the SQLite file so that it is encoded with UTF8? The current version of the app on the store uses the latter code above, so I need to figure out how to convert the file, instead of changing the code in the app.
You can use const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); with stringWithCharacters:length: (UTF16)
const unichar *text = sqlite3_column_text16(_sqlite_stmt, columnIndex);
if (text) {
NSUInteger length = sqlite3_column_bytes16(_sqlite_stmt, columnIndex)/sizeof(unichar);
article = [NSString stringWithCharacters:text length:length];
}
Try this :
char *title = (char *)sqlite3_column_text(compiledStatement, 2);
NSString *str = [NSString stringWithUTF8String:title];
Working fine for me !

sha-512 not working properly on IOS Simulator

I am implementing mobile app sha-512 function that will run on IOS, this function is working fine on all browsers including Safari.
I am testing my application using IOS Simulator.
My application is calling sha-512 function three times from one page/click. The problem is that, at first call sha-512 function produces right result, but at second and third call it produces wrong result.
thanks in advance
This is my code
//Creating Hash Value
NSString *hashkey = [NSString stringWithFormat:#"data"];
// PHP uses ASCII encoding, not UTF
NSLog(#"hashkey : %#",hashkey);
const char *s = [hashkey cStringUsingEncoding:NSASCIIStringEncoding];
NSData *keyData = [NSData dataWithBytes:s length:strlen(s)];
// This is the destination SHA512_Final
uint8_t digest[CC_SHA512_DIGEST_LENGTH] = {0};
// This one function does an unkeyed SHA1 hash of your hash data
CC_SHA512(keyData.bytes, keyData.length, digest);
// Now convert to NSData structure to make it usable again
NSData *out = [NSData dataWithBytes:digest length:CC_SHA512_DIGEST_LENGTH];
// description converts to hex but puts <> around it and spaces every 4 bytes
NSString *hash = [out description];
hash = [hash stringByReplacingOccurrencesOfString:#" " withString:#""];
hash = [hash stringByReplacingOccurrencesOfString:#"<" withString:#""];
hash = [hash stringByReplacingOccurrencesOfString:#">" withString:#""];
Hope it helps you..

Resources