Skip to content

Commit

Permalink
Changed select application to use chaining. Fixed issue where send re…
Browse files Browse the repository at this point in the history
…maining apdu was malformed.
  • Loading branch information
jensutbult committed Aug 22, 2024
1 parent f59d42c commit 83b0ad5
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,23 @@ -(instancetype)initWithConnectionController:(id<YKFConnectionControllerProtocol>
}

- (void)selectApplication:(YKFSelectApplicationAPDU *)apdu completion:(YKFSmartCardInterfaceResponseBlock)completion {
[self.connectionController execute:apdu completion:^(NSData *response, NSError *error, NSTimeInterval executionTime) {
[self executeCommand:apdu completion:^(NSData * _Nullable data, NSError * _Nullable error) {
if (error) {
completion(nil, error);
return;
}
UInt16 statusCode = [self statusCodeFromKeyResponse:response];
NSData *data = [self dataFromKeyResponse:response];
if (statusCode == YKFAPDUErrorCodeNoError) {
completion(data, nil);
} else if (statusCode == YKFAPDUErrorCodeMissingFile || statusCode == YKFAPDUErrorCodeInsNotSupported) {
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorMissingApplicationCode];
completion(nil, error);
if ([error isKindOfClass:[YKFSessionError class]]) {
UInt16 statusCode = error.code;
if (statusCode == YKFAPDUErrorCodeMissingFile || statusCode == YKFAPDUErrorCodeInsNotSupported) {
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorMissingApplicationCode];
completion(nil, error);
} else {
NSAssert(TRUE, @"The key returned an unexpected SW when selecting application");
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorUnexpectedStatusCode];
completion(nil, error);
}
} else {
completion(nil, error);
}
} else {
NSAssert(TRUE, @"The key returned an unexpected SW when selecting application");
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorUnexpectedStatusCode];
completion(nil, error);
completion(data, nil);
}
}];
}
Expand Down Expand Up @@ -101,7 +102,7 @@ - (void)executeCommand:(YKFAPDU *)apdu sendRemainingIns:(YKFSmartCardInterfaceSe
ins = 0xA5;
break;
}
YKFAPDU *sendRemainingApdu = [[YKFAPDU alloc] initWithData:[NSData dataWithBytes:(unsigned char[]){0x00, ins, 0x00, 0x00} length:4]];
YKFAPDU *sendRemainingApdu = [[YKFAPDU alloc] initWithData:[NSData dataWithBytes:(unsigned char[]){0x00, ins, 0x00, 0x00, 0x00} length:5]];
// Queue a new request recursively
[self executeCommand:sendRemainingApdu sendRemainingIns:sendRemainingIns timeout:timeout data:data completion:completion];
return;
Expand Down

0 comments on commit 83b0ad5

Please sign in to comment.