Hi,
not sure if anyone else is interested, but here's an update of the Pythonista keychain module drop-in replacement. Available as gist now, will be included in the Black Mamba later.
It's a proof of concept, will probably change API, add more things, ... Don't use this for serious work now.
What's this all about? iOS keychain is powerful and allows you to specify things like:
- when the password is accessible (unlocked device, after first unlock, ...),
- if the password should be synchronised to other devices as well,
- if the user presence is required whenever script wants to access password,
- etc.
Unfortunately, Pythonista keychain module doesn't allow us to control this. It's just a simple text password storage. Module does use system keychain, but there're no options to control all these things. That's the reason why I started to work on this enhancement.
Why? The reason is quite simple. I want to store sensitive data, like our production keys on the iPad and I do not want to use Pythonista keychain module. Because then any other script can silently retrieve my keychain items. One can say, which script? As the author of Black Mamba, I'm going to say Black Mamba for example, just not to offend authors of other scripts. Did you install Black Mamba? Did you read the source code? How can you be sure that I'm not silently calling get_services, get_password for every service and then sending all these passwords to my server? Of course that I'm not doing this. It's just an example. But these things happen. Google for PyPI, npm, ... issues and you'll see. You can say that I shouldn't store production passwords, ... on my iPad within Pythonista when I'm using 3rd party modules. Yes, I shouldn't via keychain module. I wanted to solve this somehow and thus here's this new module allowing me to set user presence requirement, disable syncing, ...
Here's an example:
gp = GenericPassword('s', 'a2')
gp.set_password('hallo3', accessible=kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, access_control=kSecAccessControlTouchIDAny)
p = get_password('s', 'a2')
print(p)
What it does? It stores password hallo3 for the service s and account a2. Whenever you want to retrieve it, iOS system dialog appears (every single time) requiring you to place your finger on the touch ID sensor. Also you can control what happens if fingerprints are changed (you can get your password deleted), if you require same fingerprints set or any, if you require biometrics or passcode is enough, etc.
This is system level stuff. Even when you change code to this one ...
gp = GenericPassword('s', 'a2')
gp.set_password('hallo3', accessible=kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, access_control=kSecAccessControlTouchIDAny)
import keychain
p = keychain.get_password('s', 'a2')
print(p)
... you'll still be asked for your fingerprint. Also you'll be asked for your fingerprint if you'd like to change password for existing service & account which is already protected with biometrics, etc.
I'll finish this one even even if no one is interested. But as I would like to include this in the Black Mamba, comments are appreciated.