ronaldoussoren / pyobjc

The Python <-> Objective-C Bridge with bindings for macOS frameworks
https://pyobjc.readthedocs.io
563 stars 47 forks source link

framework-Security error #536

Closed Alexandro1112 closed 1 year ago

Alexandro1112 commented 1 year ago

Can not return password from keychains via framework-Security. Hello, @ronaldoussoren. I trying get saved password from key-chains util via python.I had this script:

import Security

e = Security.SecKeychainFindGenericPassword(1, 10,
                                            'https://appstorrent.ru'.encode(), 
                                            len('https://appstorrent.ru'),
                                            'https://appstorrent.ru'.encode(),
                                            None,
                                            None,
                                            True)
print(e)

Mac OS Big Sur 11.7.4

**However, program return:

(-50, 0, None, True)

How to solve the problem?

ronaldoussoren commented 1 year ago

-50 is the value for errSecParam, which means "One or more parameters passed to the function are not valid." according to the Security framework documentation.

You get this error because you are passing the wrong arguments to this function, the Objective-C prototype for this function is:


OSStatus SecKeychainFindGenericPassword(
       CFTypeRef keychainOrArray, 
       UInt32 serviceNameLength, 
       const char *serviceName, 
       UInt32 accountNameLength, 
       const char *accountName, 
       UInt32 *passwordLength, 
       void * _Nullable *passwordData, 
       SecKeychainItemRef  _Nullable *itemRef);
Alexandro1112 commented 1 year ago

Thanks.As i knew, I need use ctypes for decode path to keychain framework to int32.