Yubico / yubikit-ios

Yubico Mobile iOS SDK - YubiKit
Apache License 2.0
194 stars 43 forks source link

Missing return after completion in PIV `signWithKeyInSlot` #140

Open samngms opened 7 months ago

samngms commented 7 months ago

Whenever there is an error in signWithKeyInSlot, there will also be an "Illegal callback invocation from native module. This callback type only permits a single invocation from native code.", after investigation there is a missing "return" in the code.

- (void)signWithKeyInSlot:(YKFPIVSlot)slot type:(YKFPIVKeyType)keyType algorithm:(SecKeyAlgorithm)algorithm message:(nonnull NSData *)message completion:(nonnull YKFPIVSessionSignCompletionBlock)completion {
    NSError *padError = nil;
    NSData *payload = [YKFPIVPadding padData:message keyType:keyType algorithm:algorithm error:&padError];
    if (padError != nil) {
        completion(nil, padError);
        return; <--- missing this line
    }
    return [self usePrivateKeyInSlot:slot type:keyType message:payload exponentiation:false completion:^(NSData * _Nullable data, NSError * _Nullable error) {
        completion(data, error);
    }];
}
samngms commented 7 months ago

https://github.com/Yubico/yubikit-ios/pull/141 is the fix, just add one line of the code