iPhone: HTTPS client cert authentication

前端 未结 3 1203
北海茫月
北海茫月 2020-12-22 23:48

I\'m fighting with a client certificate authentication. When a server needs a credential (a certificate in this case), this method is invoked from NSURLConnection d

3条回答
  •  悲哀的现实
    2020-12-23 00:50

    You can also search for identity in keychain if you store this information there:

    + (SecIdentityRef)dumpSecIdentityRef
    {
    OSStatus    err;
    CFArrayRef  result;
    CFIndex     resultCount;
    CFIndex     resultIndex;
    
    result = NULL;
    err = SecItemCopyMatching((__bridge CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
                                                          (__bridge id)kSecClassIdentity,
                                                          kSecClass, kSecMatchLimitAll,
                                                          kSecMatchLimit, kCFBooleanTrue,
                                                          kSecReturnRef, kCFBooleanTrue,
                                                          kSecReturnAttributes, nil],
                              (CFTypeRef *) &result);
    
    if ((result != NULL) && (err == noErr)) {
    
        NSMutableArray *identitiesArray = [NSMutableArray new];
    
        resultCount = CFArrayGetCount(result);
        for (resultIndex = 0; resultIndex < resultCount; resultIndex++) {
            NSDictionary *  thisResult;
            thisResult = (__bridge NSDictionary *) CFArrayGetValueAtIndex(result, resultIndex);
            NSLog(@"%@", (__bridge id)(result));
            [identitiesArray addObject:thisResult];
        }
    
        CFRelease(result);
        //TO DO - choose correct identity object from array.
        SecIdentityRef myIdentity = (__bridge SecIdentityRef)([[identitiesArray objectAtIndex:0] valueForKey:@"v_Ref"]);
    
        return myIdentity;
    }
    return nil;
    }
    

提交回复
热议问题