[Pyobjc-dev] Wrapping SecKeychainFindInternetPassword (using Xcode3 and Pyobjc2)
Brought to you by:
ronaldoussoren
|
From: Michael M. <mic...@gm...> - 2007-12-12 20:12:24
|
Hi, I wrote a C extension module to use
SecKeychainFindInternetPassword, and I wanted to ask here if anyone
else wanted it, and if there was a better way to do the wrapping.
If there's a preferred technique that'll make it more general, I don't
mind putting that wrapper together for public use - especially if it's
automated :)
I didn't use the ObjC Keychain.framework because I really only needed
the one function, and this seemed like less work...
What I did was using the XCode 3 template, I simply added a C file to
munge the strings back and forth, and initialized it in main.m
To wit:
SecKeychainWrapperModule.c:
// include Python.h, Security/Security.h, and Core{Foundation, Services}.h
static PyObject *
SecKeychainWrapperModule_findPasword(PyObject *self __attribute__((unused)),
PyObject *args)
{ ...do some stuff to unwrap username, pass, and protocol, call
SecKeychainFindInternetPassword, then rewrap and return password
data...
}
static PyMethodDef SecKeychainWrapperModuleMethods[] = {
{"findPassword", SecKeychainWrapperModule_findPasword, METH_VARARGS,
"Find a password in the Keychain for a server/username/protocol tuple." },
{NULL, NULL, 0, NULL } /* Sentinel */
};
PyMODINIT_FUNC
initSecKeychainWrapperModule(void)
{
PyObject* mod = Py_InitModule3("SecKeychainWrapperModule",
SecKeychainWrapperModuleMethods,
"Wrapper for part of the
SecKeychain C API" );
if(mod == NULL) return;
}
Then in main.m I added this:
/* Init wrapper for SecKeychain functions */
initSecKeychainWrapperModule();
Just after Py_Initialize().
And that's it. This works pretty well for me, but if there's a better
way to wrap the whole of SecKeychain*, I'd be glad to do it for the
public good.
(Also, if there needs to be some docs on how to do that in the new
pyobjc2 world, I don't mind helping with them)
Thanks,
-mike
--
Michael McCracken
UCSD CSE PhD Candidate
research: http://www.cse.ucsd.edu/~mmccrack/
misc: http://michael-mccracken.net/wp/
|