Esempio n. 1
0
        static unsafe string GetUsernameFromKeychainItemRef(IntPtr itemRef)
        {
            int[] formatConstants = { (int)CssmDbAttributeFormat.String };
            int[] attributeTags   = { (int)SecItemAttr.Account };

            fixed(int *tags = attributeTags, formats = formatConstants)
            {
                var attributeInfo = new SecKeychainAttributeInfo {
                    Count  = 1,
                    Tag    = tags,
                    Format = formats
                };
                SecKeychainAttributeList *attributeList = null;
                SecItemClass itemClass = 0;

                try {
                    SecStatusCode status = SecKeychainItemCopyAttributesAndData(itemRef, &attributeInfo, ref itemClass, &attributeList, IntPtr.Zero, IntPtr.Zero);

                    if (status == SecStatusCode.ItemNotFound)
                    {
                        throw new Exception("Could not add internet password to keychain: " + status.GetStatusDescription());
                    }

                    if (status != SecStatusCode.Success)
                    {
                        throw new Exception("Could not find internet username and password: " + status.GetStatusDescription());
                    }

                    var userNameAttr = (SecKeychainAttribute *)attributeList->Attrs;

                    if (userNameAttr->Length == 0)
                    {
                        return(null);
                    }

                    return(Marshal.PtrToStringAuto(userNameAttr->Data, (int)userNameAttr->Length));
                } finally {
                    SecKeychainItemFreeAttributesAndData(attributeList, IntPtr.Zero);
                }
            }
        }
Esempio n. 2
0
 static extern unsafe OSStatus SecKeychainItemModifyAttributesAndData(IntPtr itemRef, SecKeychainAttributeList *attrList, uint length, byte [] data);
Esempio n. 3
0
 static extern unsafe OSStatus SecKeychainItemCreateFromContent(SecItemClass itemClass, SecKeychainAttributeList *attrList,
                                                                uint passwordLength, byte[] password, IntPtr keychain,
                                                                IntPtr initialAccess, ref IntPtr itemRef);
Esempio n. 4
0
 static extern unsafe OSStatus SecKeychainSearchCreateFromAttributes(IntPtr keychainOrArray, SecItemClass itemClass, SecKeychainAttributeList *attrList, out IntPtr searchRef);
Esempio n. 5
0
 static extern unsafe SecStatusCode SecKeychainItemFreeAttributesAndData(SecKeychainAttributeList *list, IntPtr data);
Esempio n. 6
0
 static unsafe SecKeychainAttribute *GetUsernameAttributeFromAttributeList(SecKeychainAttributeList *attributeList)
 {
     return((SecKeychainAttribute *)attributeList->Attrs);
 }