OSX CryptoTokenKit SmartCard returned error 6d00

2019-08-11 21:59发布

问题:

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);
             }
         }];
    }];

回答1:

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)
         {
         }


回答2:

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).