2012-05-09 19 views
1

在一個簡單的方法來刪除CN的Certs(證書先前已由SecItemAdd從PKCS12導入);我得到的錯誤:ios/SecItemDelete不接受一個SecIdentityRef/kSecMatchItemList

Property list invalid for format: 200 (property lists cannot contain objects of type 'SecIdentity') 

凡根據http://developer.apple.com/library/ios/#DOCUMENTATION/Security/Reference/keychainservices/Reference/reference.html#//apple_ref/c/func/SecItemDelete我想我的指令之後:

To delete an item identified by a transient reference, specify the kSecMatchItemList search key with a reference returned by using the kSecReturnRef return type key in a previous call to the SecItemCopyMatching or SecItemAdd functions.

信。下面的代碼:

NSDictionary * attributes; 
NSString * cnString = @"/CN=foo"; 

attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
       (__bridge id)(kSecClassIdentity), kSecClass, 
       cnString, kSecMatchSubjectContains, 
       kSecMatchLimitAll, kSecMatchLimit, 
       kCFBooleanTrue, kSecReturnRef, 
       nil]; 

CFArrayRef result; 
status = SecItemCopyMatching((__bridge CFDictionaryRef)(attributes), 
     (CFTypeRef *)&result); 

if (status == noErr) { 

    for(int i = 0; i < CFArrayGetCount(result); i++) { 

     SecIdentityRef item = (SecIdentityRef) CFArrayGetValueAtIndex(result, i); 
     NSLog(@"Item #%d: %@", i, item); 

     attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
         (__bridge id)(kSecClassIdentity), kSecClass, 
         [NSArray arrayWithObject:(__bridge id)item], kSecMatchItemList, 
         kSecMatchLimitOne, kSecMatchLimit, 
         nil]; 

     status = SecItemDelete((__bridge CFDictionaryRef)(attributes)); 

     if (status != noErr || status != errSecItemNotFound) 
      NSLog(@"Delete %d/%@failed: %ld (ignored)", i,item, status); 
    }; 
}; 

在控制檯上的輸出是:

Item #0: <SecIdentityRef: 0xc7359ff0> 

查找直後(如果搜索是擴大我們得到的這些數組)。

然後從內心深處Security.dylib:

Property list invalid for format: 200 (property lists cannot contain objects of type 'SecIdentity') 

最終保釋:

Delete 0/<SecIdentityRef: 0xc7359ff0>failed: -50 (ignored) 

我在做什麼錯?

謝謝,

Dw。

回答

0

這已經在最新的GM跌幅中得到修復。現實與文檔同步。

+2

我的iOS 6.1.3和iOS 7.1下獲得這個同樣的失敗。 「SecItemDelete」對於匹配項目列表是否仍能正常工作? – Greg

0

從安全框架的頭文件SecItem.h下的文檔,部分報價:

By default, this function deletes all items matching the specified query. You can change this behavior by specifying one of the follow keys:

  • To delete an item identified by a transient reference, on iOS, specify kSecValueRef with a item reference. On OS X, give a kSecMatchItemList containing an item reference.

  • To delete an item identified by a persistent reference, on iOS, specify kSecValuePersistentRef with a persistent reference returned by using the kSecReturnPersistentRef key to SecItemCopyMatching or SecItemAdd. On OSX, use kSecMatchItemList with a persistent reference returned by using the kSecReturnPersistentRef key with SecItemCopyMatching or SecItemAdd.