OSX CryptoTokenKit SmartCard returned error 6d00 - macos

I'm trying to read the master file of a smartcard on OSX using CryptoTokenKit but I always get statusword 6d00 as response. I also tried to run the trivial example with some modifications but get the same error. My reader is Gemalto PC Twin Reader.
Please let me know if you have any suggestion to fix it.
I'm using the following code:
TKSmartCardSlot *slot = [self.smartCardManager slotWithName:slotName];
TKSmartCard *card = [slot makeSmartCard];
card.sensitive = YES;
[card beginSessionWithReply:^(BOOL success, NSError *error) {
NSLog(#"%#", error);
NSLog(#"Proto: %ld", card.currentProtocol);
NSData *data = [CommonUtil dataFromHexString:#"3F00"]; //<3f00>
NSLog(#"%#", data);
[card sendIns:0xA4 p1:0x00 p2:0x00 data:data le:#0
reply:^(NSData *replyData, UInt16 sw, NSError *error)
{
NSLog(#"Response: %#", replyData);
if (error) {
if (error.code == TKErrorCodeCommunicationError) {
// set response error code.
}
NSLog(#"%#", error);
}
}];
}];

It is silly, but in the apdu where no response data is expected without the success code 90 00, le should be nil.
[card sendIns:0xA4 p1:0x00 p2:0x00 data:nil le:nil
reply:^(NSData *replyData, UInt16 sw, NSError *error)
{
}

Status Word 6D00 is " Instruction code not supported or invalid "
http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_5_basic_organizations.aspx
Not all the cards allow to select the Master File (0x3F00).

Related

How to send push notifications to a specific user through Parse?

I have already set up push notifications through Parse and Apple, and I can't seem to find a straight forward way to send push notifications to another user.
For my case, I want to send a user a notification when a user sends a friend request to them. here is the code I am using to save to request to the server:
//get current user
PFQuery *query2 = [PFUser query];
[query2 whereKey:#"username" equalTo:pendingFriendName];
PFUser *userTo = (PFUser *)[query2 getFirstObject];
PFQuery *query = [PFQuery queryWithClassName:#"Follow"];
[query whereKey:#"from" equalTo:[PFUser currentUser]];
// execute the query
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFObject *follow = [PFObject objectWithClassName:#"Follow"];
[follow setObject:[PFUser currentUser] forKey:#"from"];
[follow setObject:userTo forKey:#"to"];
[follow saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(succeeded)
{
NSLog(#"success!");
[friendAddedLabel setText:#"Friend Added!"];
}
else
{
NSLog(#"error");
}
}];
}
}];
In addition, is there a way to send a direct reference of the user who sent the request to the user who received the friend request so that it can quickly have the information accessible when the user taps the notifcation instead of going through another query?
First, you have to store the current user into Installation class then send push notification using PFInstallation Query and PFPush.
//save the user into installtion class.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if ([PFUser currentUser].objectId)
{
currentInstallation[#"user"] = [PFUser currentUser];
currentInstallation.channels = #[[NSString stringWithFormat:#"user_%#",[PFUser currentUser].objectId]];
NSLog(#"Saving Installation channel = %#",currentInstallation.channels);
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
NSLog(#"Current installation updated: Error: %#",error);
}];
}
//Then send push notification to particular user.
PFQuery *queryInstallation = [PFInstallation query];
[queryInstallation whereKey:#"user" equalTo:user];
PFPush *push = [[PFPush alloc] init];
[push setQuery:queryInstallation];
NSDictionary * dic = #{#"alert" : text,#"badge" : #"Increment" , #"sender" : [PFUser currentUser].objectId ,#"MediaId" : mediaObject.objectId};
[push setData:dic];
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (error != nil && !succeeded)
{
NSLog(#"SendPushNotification send error.");
}
else
{
NSLog(#"SendPushNotification send success.");
}
}];

How to get all name of RecordType in a private Database CloudKit

I would like to know how I can get an array with all the name of record type in my private database in Cloud Kit for read all my data ?
I save my data :
CKRecord* fav1 = [[CKRecord alloc] initWithRecordType:#"Favoris1"];
[fav1 setObject:#"Favoris 1 name"forKey:#"name"];
[fav1 setObject:#"2003 year"forKey:#"year"];
[self.privateDatabase saveRecord:fav1
completionHandler:^(CKRecord *savedState, NSError *error) {
if (error) {
NSLog(#"ERROR SAVING: %#", error);
}
else{
NSLog(#"SAVE OK");
}
}];
I read my data :
CKQuery *query = [[CKQuery alloc] initWithRecordType:#"Favoris1" predicate:[NSPredicate predicateWithFormat:#"TRUEPREDICATE"]];
[self.privateDatabase performQuery:query
inZoneWithID:nil
completionHandler:^(NSArray *results, NSError *error)
{
if (!error)
{
NSLog(#"results query %#", results);
NSLog(#"--> %#",[[results objectAtIndex:0] objectForKey:#"name"]);
NSLog(#"--> %#",[[results objectAtIndex:0] objectForKey:#"year"]);
}
else
{
NSLog(#"FETCH ERROR: %#", error);
}
}];
I would like to save an other record with another properties like :
CKRecord* fav2 = [[CKRecord alloc] initWithRecordType:#"Favoris2"];
[fav2 setObject:#"Favoris 2 name"forKey:#"name"];
[fav2 setObject:#"2005 year"forKey:#"year"];
How can I have an array with Favoris1 and Favoris2 for read all my record after I have saved ?
in CloudKit there is no function that will return all the available recordType's from a database. You can also not query multiple recordTypes at the same time. You have to perform 2 queries. What you could do is join the resulting arrays together if you need something like that.
Since the objects are the same, it would be better if you just used 1 recordType and add an extra field that would specify your custom type (Favoris1 or Favoris2) Then you could query just the recordType and see in the returned field what custom type it is.

Twilio iOS unrecognized selector sent to Class

I'm new to using Twilio and I'm hoping someone can help me debug my app.
I am making a call to get a capability token and it is returned just fine. I print it in the console to check then it appears when I make the call to initWithCapabilityToken that's where something is breaking and I cant figure it out.
Here is my code...
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:
^(NSURLResponse *response, NSData *data, NSError *error){
// Log Any Reply
if ([data length] >0 && error == nil) {
NSData *jsonData = data;
// Deserialize JSON into Dictionary
error = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingAllowFragments
error:&error ];
if (jsonObject != nil && error == nil) {
NSLog(#"Successfully deserialized JSON response...");
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
NSLog(#"Deserialized JSON Dictionary = %#", deserializedDictionary);
NSString *token = [deserializedDictionary objectForKey:#"token"];
if (token == nil) {
NSLog(#"Error retrieving token");
} else {
NSLog(#"Token: %#", token);
// Setup TCDevice
_phone = [[TCDevice alloc] initWithCapabilityToken:token delegate:self];
}
}
} else if (error != nil){
NSLog(#"An error happened while de-serializing the JSON data.");
}
}else if ([data length] == 0 && error == nil){
NSLog(#"Nothing was downloaded.");
}else if (error != nil){
NSLog(#"Error happened = %#", error);
}
}];
Here is what I get right after my token is logged...
2015-01-29 16:32:14.637 AppName[4649:701822] +[NSString stringWithPJStr:]: unrecognized selector sent to class 0x3377da98
2015-01-29 16:32:14.639 AppName[4649:701822] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSString stringWithPJStr:]: unrecognized selector sent to class 0x3377da98'
*** First throw call stack:
(0x254da49f 0x32c90c8b 0x254df7d5 0x254dd7d7 0x2540f058 0x10ee7d 0x10e32b 0x10e2b7 0x105959 0x10568d 0x7b3ab 0x24fa228d 0x261d52b1 0x2614034d 0x26132b07 0x261d7c1b 0x487e29 0x4822c9 0x489567 0x48a891 0x33351e31 0x33351b84)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks
After reading all of Twilios documentation I discovered I was missing one thing. I had to add -ObjC to Other Linker Flags and that solved my problem.
add this lines to the other linker flags:
-ObjC
-lTwilioClient
-lcrypto
-lssl
it worked for me only with a upper C add the end (-ObjC)
Somewhere you are calling a stringWithPJStr function(selector) that doesn't exist.

`PFFile getDataInBackgroundWithBlock` block not getting called Obj-C

I have the following code, to retrieve an image from Parse. This code block is in a recursive loop that gets called for a list of images in an array.
PFFile *remoteImageFile = object[#"Image"]
[remoteImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
DDLogInfo(#"%s:%d %#", __PRETTY_FUNCTION__, __LINE__, [error debugDescription]);
// other logics
}];
The code fetches most of the images successfully, the sizes of the images being 2MB to 3MB. But randomly it fails for certain files and the block is not getting fired and my whole fetching operation freezes. Couldn't find the reason.
Any help please
I doubt that there is a bug in the Parse framework here. The most probable cause is that your remoteImageFile is nil which means that getDataInBackgroundWithBlock: is not even called.
Can you check by using the following code :
PFFile *remoteImageFile = object[#"Image"];
if (remoteImageFile == nil || ![remoteImageFile isKindOfClass:[PFFile class]]) {
NSLog(#"Error : remoteImageFile = %#", remoteImageFile);
} else {
[remoteImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
DDLogInfo(#"%s:%d %#", __PRETTY_FUNCTION__, __LINE__, [error debugDescription]);
// other logics
}];
}

Clang Error on "Potential null dereference."

I keep getting Clang errors on the following type of code and I can't figure out why they're erroneous or how to resolve them to Clang's satisfaction:
+ (NSString *)checkForLength: (NSString *)theString error: (NSError **)error {
BOOL hasLength = ([theString length] > 0);
if (hasLength) return theString;
else {
*error = [NSError errorWithDomain:#"ErrorDomain" code:hasLength userInfo:nil];
return nil;
}
}
Leaving aside the utterly-contrived nature of the example (which Clang did object to so it's illustrative enough), Clang balks at the error assignment line with the following objection:
Potential null dereference. According to coding standards in 'Creating and Returning NSError Objects' the parameter 'error' may be null.
I like having a pristine Clang report. I've read the cited document and I can't see a way to do what's expected; I checked some open-source Cocoa libraries and this seems to be a common idiom. Any ideas?
The way to do what's expected is shown in listing 3-5 in that document. With your example code:
+ (NSString *)checkForLength: (NSString *)theString error: (NSError **)error {
BOOL hasLength = ([theString length] > 0);
if (hasLength) return theString;
else {
if (error != NULL) *error = [NSError errorWithDomain:#"ErrorDomain" code:hasLength userInfo:nil];
return nil;
}
}
The Cocoa convention is that the return value should indicate success or failure (in this case, you return nil for failure) and the error is filled in with additional information, but only when the caller requests it.
In other words
NSError *error = nil;
NSString *result = [self checkForLength: aString error: &error];
and
NSString *result = [self checkForLength: aString error: NULL];
are both valid ways to invoke the method. So the method body should always check for a NULL error param:
if (error != NULL)
*error = ...;

Resources