Currently I am fetching the password by running the following shell command inside python
For Http proxy password
security find-internet-password -s 192.168.1.38 -r htsx -P 808 -w
For Https proxy password
security find-internet-password -s 192.168.1.38 -r htpx -P 808 -w
and I get all those host-name and port by running the following code
>>> import urllib
>>> urllib.getproxies()
{'http': 'http://192.168.1.38:808', 'https': 'http://192.168.1.38:808'}
But Every time I run the above shell command from python, I am being asked to Allow "security" to access the keychain, if I gave Always Allow application to access the keychain for proxy password then the proxy password can even be accessed by other applications which I haven't allowed explicitly. They can access the proxy password just by running the same command (I have tried it from command prompt, this time it didn't prompt me and tried to access it from other python script also it is not asking me permission).
But other applications like AuthBroker shows the following message while accessing proxy
I know I am giving permission to the application security to access the keychain, but other applications are asking permission for themselves. My approach may compromise the security of the system.
I have two questions:
- What is the recommended way to access the keychain for proxy password ?
- Is there any python library that could do this ?
SecKeychainFindInternetPassword
is the function you want, but without reading the background you'll have no idea what half its params mean. – Nguyetni