在iOS上用Grabba阅读军事CAC的CHUID?
我正试图通过iOS 8.1上的Grabba从军事ID CAC读取CHUID 我期待得到成功的回应。首先,我运行SelectPIV。我得到0x61和0x18作为状态字。然后,我使用响应中的状态字2来安装Get response命令 我希望得到0x61 on Get响应。相反,我接收0x69和0x85。然后我运行selectCHUID命令。我希望收到0x61。相反,我接收0x6D,我的参考代码将其标记为“错误指令” 无论我以何种顺序发送这3条命令,我都会收到相同的状态词。我使用默认初始化和installGetResponseCommand的定制初始化,以及响应SW2中的第二个状态字LE,获得了与get响应相同的结果 我的公司在其他平台上成功地使用了该代码,在相同的CAC卡上使用了其他设备扫描仪。只有通过iOS上的Grabba,我们才能看到这些结果在iOS上用Grabba阅读军事CAC的CHUID?,ios,iphone,smartcard,rfid,Ios,Iphone,Smartcard,Rfid,我正试图通过iOS 8.1上的Grabba从军事ID CAC读取CHUID 我期待得到成功的回应。首先,我运行SelectPIV。我得到0x61和0x18作为状态字。然后,我使用响应中的状态字2来安装Get response命令 我希望得到0x61 on Get响应。相反,我接收0x69和0x85。然后我运行selectCHUID命令。我希望收到0x61。相反,我接收0x6D,我的参考代码将其标记为“错误指令” 无论我以何种顺序发送这3条命令,我都会收到相同的状态词。我使用默认初始化和insta
- (void)setupAPDUCommands {
unsigned char selectBytes[] = { 0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00};
self.selectPIVCommand = [[GRGrabbaCommandAPDU alloc] initWithCLA:0x00
INS:0xA4
P1:0x04
P2:0x00
Data:[NSData dataWithBytes:selectBytes length:9]
Error:nil];
unsigned char chuidBytes[] = { 0x5C,
0x03,
0x5F,
0xC1,
0x02};
self.CHUIDCommand = [[GRGrabbaCommandAPDU alloc] initWithCLA:0x00
INS:0xCB
P1:0x3F
P2:0xFF
Data:[NSData dataWithBytes:chuidBytes length:5]
Le:0
Error:nil];
self.getResponseCommand = [[GRGrabbaCommandAPDU alloc] initWithCLA:0x00
INS:0xC0
P1:0x00
P2:0x00
Data:nil
Le:0x02 Error:nil];
}
- (UInt8)exchangeAPDUCommand:(GRGrabbaCommandAPDU *)command {
self.promptLabel.text = [command.data description];
NSLog(@"***EXCHANGING APDU COMMAND***");
NSLog(@"CLA: %@", [self stringFromUint:command.cla]);
NSLog(@"INS: %@", [self stringFromUint:command.ins]);
NSLog(@"P1: %@", [self stringFromUint:command.p1]);
NSLog(@"P2: %@", [self stringFromUint:command.p2]);
NSLog(@"LC: %@", [self stringFromUint:command.lc]);
NSLog(@"Data: %@", command.data);
NSLog(@"LE: %@", [self stringFromUint:command.le]);
self.currentCommand = command;
NSError *error;
self.session = [[[GRGrabba sharedGrabba] smartcard] startSession:&error] ;
[SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"Session started: %@", error.description]];
GRGrabbaResponseAPDU *response = [[GRGrabbaResponseAPDU alloc] initWithData:nil SW1:0 SW2:0];
NSError *e2;
[self.session exchangeAPDUCommand:command withResponse:response error:&e2];
NSLog(@"***APDU COMMAND EXCHANGED***");
NSLog(@"SW1: %@", [self stringFromUint:response.sw1]);
NSLog(@"SW2: %@", [self stringFromUint:response.sw2]);
[self processSmartCardScan:response];
return response.sw1;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initializeGrabba];
[self setupAPDUCommands];
}
- (void)initializeGrabba {
GRGrabba *grabba = [GRGrabba sharedGrabba];
grabba.barcode.delegate = self;
grabba.buttons.delegate = self;
grabba.smartcard.delegate = self;
}
- (IBAction)selectPivTapped {
[self exchangeAPDUCommand:self.selectPIVCommand];
}
- (IBAction)readCHUIDTapped {
[self exchangeAPDUCommand:self.CHUIDCommand];
}
- (IBAction)getResponseTapped {
[self exchangeAPDUCommand:self.getResponseCommand];
}
- (void)installGetResponseCommand:(GRGrabbaResponseAPDU *)response {
self.getResponseCommand = [[GRGrabbaCommandAPDU alloc] initWithCLA:0x00
INS:0xC0
P1:0x00
P2:0x00
Data:nil
Le:response.sw2
Error:nil];
}
- (void)processSmartCardScan:(GRGrabbaResponseAPDU *)response {
self.statusLabel.text = [NSString stringWithFormat:@"%i %i %@", response.sw1, response.sw2, response.rData];
if (self.currentCommand == self.selectPIVCommand) {
[self installGetResponseCommand:response];
} else if (self.currentCommand == self.CHUIDCommand) {
self.mutableScanData = [NSMutableData data];
if (response.sw1 == 0x61 || response.sw1 == 0x90) {
[self.mutableScanData appendData:response.rData];
[self exchangeAPDUCommand:self.getResponseCommand];
}
} else if (self.currentCommand == self.getResponseCommand) {
if (response.sw1 == 0x61) {
//recreate get response dynamically
[self.mutableScanData appendData:response.rData];
[self exchangeAPDUCommand:self.getResponseCommand];
} else if (response.sw1 == 0x90) {
[self.mutableScanData appendData:response.rData];
[self processExtractedSmartCardData:self.mutableScanData];
} else {
[self alertUserOfFailedScan];
}
}
}
尝试删除SELECT PIV APDU上的最后两个字节:
unsigned char selectBytes[] = { 0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00};
self.selectPIVCommand = [[GRGrabbaCommandAPDU alloc] initWithCLA:0x00
INS:0xA4
P1:0x04
P2:0x00
Data:[NSData dataWithBytes:selectBytes length:7]
Error:nil];
在get response命令中,Le应该为零 考虑再详细一点。