« The Open Source Monopoly | Main | SSL bad write retry »

20 January 2005

Hacking M2Crypto

M2Crypto = Python + OpenSSL + SWIG

Architecturally, M2Crypto consists of two layers. The lower layer uses SWIG to hook up the OpenSSL C API functions, making these available as Python functions. The upper layer provides Pythonic object-oriented interfaces to the lower layer. The naming convention for the lower layer matches OpenSSL's API naming closely; this means that, most of the time, you can refer to OpenSSL's documentation to figure out what a function in the lower layer does.

As an example, suppose you want to implement the functionality of "openssl pkcs12 some-specific-operation" in M2Crypto. Here's how:

» Look in <openssl>/apps/pkcs12.c for the parts that implement some-specific-operation. Note the structures and functions used. See <openssl>/include/pkcs12.h for the definitions of said structures and functions. Check OpenSSL's docu for those functions.

» Now create the SWIG interface file <m2crypto>/SWIG/_pkcs12.i. Add whatever glue code is necessary so that

» Next create the file <m2crypto>/M2Crypto/PKCS12.py. Add Python wrapper classes to the pointers to structures; the glue functions that work on said pointers become methods of these Python OO wrapper classes. Add utility functions at the module level for the convenience of the module user (i.e., the application programmer). Write unit tests along the way. Write doc strings! ;-)

» Send patches; unified diffs, please.

I accept all patches. If they fit in easily, I put them in. If they don't I stick them in the contrib/ directory with a README. If I appear to be sitting on your patches, maybe it is because your patches scare me into re-evaluating my aforementioned liberal patch policy. ;-) Or, maybe I am just sitting on them. Prod me.


Posted by ngps at 16:56 | Comments (3) | Trackbacks (0)
Comments
Re: Hacking M2Crypto

well it should compile first in python2.4
hopefully
http://mail.python.org/pipermail/python-list/2005-January/260548.html
helped me

in general superb!

Posted by: Nikos Kouremenos at February 26,2005 06:56
Re: Hacking M2Crypto

It does compile on Python 2.4. The version of setup.py in SVN works "out of the box" I believe.

Posted by: Ng Pheng Siong at March 02,2005 23:29
Re: Hacking M2Crypto

Hi,

Id like to build M2Crypto with older version of openssl - namely openssl-0.9.6g-34. for some reasons I cant upgrade openssl. can you point out some directions how I can patch m2crypto ?

Posted by: Artyom Tyazhelov at August 31,2005 03:33
Trackbacks
Please send trackback to:http://sandbox.rulemaker.net/ngps/198/tbping
There is no trackback.