获取钥匙串项的属性

rgo*_*gov 5 security macos keychain

我正在尝试获取钥匙串项的属性.此代码应查找所有可用属性,然后打印其标签和内容.

根据文档,我应该看到像'cdat'这样的标签,但它们只是看起来像一个索引(即,第一个标签是0,接下来是1).这使它变得毫无用处,因为我无法确定哪个属性是我正在寻找的属性.

    SecItemClass itemClass;
    SecKeychainItemCopyAttributesAndData(itemRef, NULL, &itemClass, NULL, NULL, NULL);

    SecKeychainRef keychainRef;
    SecKeychainItemCopyKeychain(itemRef, &keychainRef);

    SecKeychainAttributeInfo *attrInfo;
    SecKeychainAttributeInfoForItemID(keychainRef, itemClass, &attrInfo);

    SecKeychainAttributeList *attributes;
    SecKeychainItemCopyAttributesAndData(itemRef, attrInfo, NULL, &attributes, 0, NULL);

    for (int i = 0; i < attributes->count; i ++)
    {
        SecKeychainAttribute attr = attributes->attr[i];
        NSLog(@"%08x %@", attr.tag, [NSData dataWithBytes:attr.data length:attr.length]);
    }

    SecKeychainFreeAttributeInfo(attrInfo);
    SecKeychainItemFreeAttributesAndData(attributes, NULL);
    CFRelease(itemRef);
    CFRelease(keychainRef);
Run Code Online (Sandbox Code Playgroud)

rgo*_*gov 1

我认为文档会导致一些混乱。

\n\n

我看到的数字似乎是keys 的钥匙串项属性常量

\n\n

但是,SecKeychainItemCopyAttributesAndData 返回一个 SecKeychainAttributeList 结构,其中包含 SecKeychainAttributes 数组。来自 TFD:

\n\n
\n

tag\n 4 字节属性标记。有关有效属性类型,请参阅 \xe2\x80\x9cKeychain 项属性常量\xe2\x80\x9d。

\n
\n\n

属性常量(非“for keys”类型)是我期望看到的 4 个字符值。

\n