Fairplay SPC request returns nil - ios

I'm attemping to use the [AVAssetResourceLoadingRequest streamingContentKeyRequestDataForApp:contentIdentifier:options:error:]; method to obtain an SPC key but I'm getting nil returned to me instead of the intended SPC value. I am mainly referencing the provided example Fairplay application. I'm using an encoded request URL host string as a content identifier and a .DER certificate retrieved from the SPC server as the app data. Has anyone else experienced this issue?
NSString *hostString = [URL host];
NSData *assetId = [NSData dataWithBytes:[hostString cStringUsingEncoding:NSUTF8StringEncoding] length:[hostString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
NSData *certificate = (obtained via Key Server).
NSError *error;
NSData *SPC = [loadingRequest streamingContentKeyRequestDataForApp:certificate contentIdentifier:assetId options:nil error:&error]
The output of SPC here is nil. The full error description is as follows:
Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed"
UserInfo=0x170461980
{NSUnderlyingError=0x1740548e0 "The operation couldn’t be completed. (OSStatus error -12640.)",
NSLocalizedFailureReason=An unknown error occurred (-12640),
NSLocalizedDescription=The operation could not be completed}

It turns out that the test stream was not correctly encrypted using SAMPLE-AES encryption.

Related

NSURL Error code extraction

I try to do my NSURL error-handling and have a little problem.
When i'm getting an error i want to handle it different for different error-codes.
In my case i want to check if the error that i'm getting is the one with errorcode 1005.
This is what I get when I print as follows:
NSLog(#"%#",error);
Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x1700ff000 {NSErrorFailingURLStringKey=MyURL, NSErrorFailingURLKey=MyURL, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSURLSessionDownloadTaskResumeData=<CFData 0x17025a580 [0x1936b2c80]>{length = 3640, capacity = 4096, bytes = 0x3c3f786d6c2076657273696f6e3d2231 ... 2f706c6973743e0a}, NSUnderlyingError=0x17025cf80 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}
and this is what I want to extract from it:
-1005
I already searched for it and found a solution which doesn't work. (I get EXC_BAD_ACCESS)
NSLog(#"%#", [error code]);
Afterwards I want to compare it similar to:
if(error.code == -1005){
//handle error
}
You can't use:
NSLog(#"%#", [error code]);
Because code is NSInteger. Use:
NSLog(#"%d", [error code]);
Refer: NSError Class Reference for more details

Working with AES encryption in IOS

I am getting problem while encryption.
The server is sending json data which is aes256 encrypted and then base64 encoded.
while in the ios client side i am able to get the response and decode it using base64.
The AES256 decryption works on some libraries(3rd party or wrappers aroound CommonCryptor.h) and not working in another.
When decryption is working the parsing is not working.
The following are the wrappers libraries and the respective code.
RNCryptor
(https://github.com/rnapier/RNCryptor)
NSData *decodedData = [Util decode:data];
NSData *RNDecryptedData = [RNDecryptor decryptData:decodedData withPassword:randomString error:&error];
if (error == nil) {
NSLog(#"RNDecryptedData - %#",[Util hexStringFromData:RNDecryptedData]);
response = [NSJSONSerialization JSONObjectWithData:RNDecryptedData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"response - %#",response);
NSLog(#"error1 - %#",error);
} else
NSLog(#"error2 - %#",error);
I am getting following error while decryption.
EncryptedParsing[4402:70b] error2 - Error Domain=net.robnapier.RNCryptManager Code=2 "Unknown header" UserInfo=0x8c6bd60 {NSLocalizedDescription=Unknown header}
CCrypto
(https://github.com/Gurpartap/AESCrypt-ObjC)
NSData *decodedData = [Util decode:data];
NSData *CCDecryptedData = [decodedData decryptedAES256DataUsingKey:randomString error:&error];
if (error == nil) {
response = [NSJSONSerialization JSONObjectWithData:CCDecryptedData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"response - %#",response);
NSLog(#"error1 - %#",error);
} else
NSLog(#"error2 - %#",error);
Here I am getting the decrypted data, but while parsing it is giving following error
EncryptedParsing[4469:70b] error1 - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a51520 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
NSData+AES256
(http://pastie.org/426530)
NSData *decodedData = [Util decode:data];
NSData *AES256DecryptedData = [decodedData AES256DecryptWithKey:randomString];
response = [NSJSONSerialization JSONObjectWithData:AES256DecryptedData options:NSJSONReadingMutableLeaves error:&error];
NSLog(#"error - %#",error);
I am getting the decryption data, while parsing i am getting following error
EncryptedParsing[4646:70b] error - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a710c0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
Along with these I have also used CocoaSecurity (https://github.com/kelp404/CocoaSecurity)
But it is not working.
I am using NSData+Base64 (https://github.com/l4u/NSData-Base64) for base64 decoding
By the way there is no problem from server side(we tested it).
I want to know the error i am doing. Or is there any other way to achieve it
There is no universal standard way to encode AES encrypted data. You need agreement on both sides about how to encode the various metadata required.
RNCryptor is failing to decrypt because it expects the data to be in the RNCryptor format.
CCCrypto and AES256DecryptWithKey are probably interpreting the key differently than you intend. Neither verifies that the key you pass is correct, so you likely are getting garbage back. If that's the case, I would expect that for some messages you get garbage back, and for other messages you get nothing back, or an error.
RNCryptor has implementations in several languages if you need a cross-platform solution. If you are required to conform to a server format (which is likely not secure encryption from the looks of your code), then you'll need to provide the server code in order to determine the correct client code.
try to replace NSJSONReadingMutableLeaves with kNilOptions.

QuickBlox downloading content receiving QBASIHTTPRequestErrorDomain code 1

I'm using the iOS SDK to access download content from the content module. It seems in the delegate method -(void)completedWithResult:(Result*)result, I can have cases where result.success is YES while result.file would be nil.
-(void)completedWithResult:(Result*)result
{
if (result.success) { // YES here
if ([result isKindOfClass: [QBCFileDownloadTaskResult class]]) {
FileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;
res.file; // This is NULL.
res.errors; // This is an empty NSArray
}
}
}
Console log prints this message:
<QBASIHTTPRequest: 0xc26d200>
headers:(null)
body:
error:Error Domain=QBASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x9f27a50 {NSUnderlyingError=0x9f18300 "The operation couldn’t be completed. Connection reset by peer", NSLocalizedDescription=A connection failure occurred}
Is this normal? I would expect in this case res.success a NO.
Let's try latest version of iOS SDK 1.8
http://quickblox.com/developers/IOS#Framework_changelog:
Here is one big change:
replaced core network library ASIHTTPRequest with AFNetworking

stackmob ios datastore http 401 error

I'm using the iOS DataStore API to upload data to StackMob. I get this error when I try to use my smclient initialized with my public key.
HTTP Code=401 "The operation couldn’t be completed. (HTTP error 401.)" UserInfo=0xa14dac0 {error=Insufficient authorization}
Sample code
[[self.smclient dataStore] createObject:eventDictObj
inSchema:#"EventSchema"
onSuccess:^(NSDictionary *object, NSString *schema)
{
NSLog(#"Created online event : %#", object);
successBlock();
}
onFailure:^(NSError *error, NSDictionary* object, NSString *schema)
{
failedBlock(error);
}];
And smclient is initialized as follows
self.smclient = [[SMClient alloc] initWithAPIVersion:#"0" publicKey:#"xxxxxxxxxx"];
For this use case I don't need to use the logged in user credentials to create this entry in StackMob
Make sure that the permissions are set to Open on your stack mob database.

Accessing localized error message from ASIHTTPrequest calls

I'm using the ASIHTTPRequest to perform some HTTP calls. In a certain case when the network isn't available, I display a dialog with the error from the NSError object returned. My problem occurs when I change my language settings (to Spanish). The localizedDescription always returns in English:
NSLog(#"userInfo: %#", [error userInfo]);
NSLog(#"localizedDescription: %#", [error localizedDescription]);
prints:
2012-04-05 22:02:05.519 MyApp[18644:207] userInfo: {
NSLocalizedDescription = "A connection failure occurred";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=61 \"The operation couldn\U2019t be completed. Conexi\U00f3n rechazada\" UserInfo=0x594f880 {}";
}
2012-04-05 22:02:05.519 MyApp[18644:207] localizedDescription: A connection failure occurred
localizedDescription is still in English, but inside [error userInfo], in the NSUnderlyingError, there is a Spanish translation available, but I don't know how to access it via the NSError object returned.
A similar question was previous asked, but the answer is not satisfactory and not scalable for all possible error messages.

Resources