views:

258

answers:

3

I would like to use the button encryption in django-paypal, but it requires M2Crypto which will not build on webfaction servers. Tech support at Webfaction told me that pycrypto is already installed on the system, but I am too dumb to translate from M2Crypto to pycrypto.

Can anyone tell me how to convert the following to work with pycrypto (if possible)? This is just a small snip showing he encryption, I can post the entire function if needed.

    s = SMIME.SMIME()   
    s.load_key_bio(BIO.openfile(CERT), BIO.openfile(PUB_CERT))
    p7 = s.sign(BIO.MemoryBuffer(plaintext), flags=SMIME.PKCS7_BINARY)
    x509 = X509.load_cert_bio(BIO.openfile(settings.PAYPAL_CERT))
    sk = X509.X509_Stack()
    sk.push(x509)
    s.set_x509_stack(sk)
    s.set_cipher(SMIME.Cipher('des_ede3_cbc'))
    tmp = BIO.MemoryBuffer()
    p7.write_der(tmp)
    p7 = s.encrypt(tmp, flags=SMIME.PKCS7_BINARY)
    out = BIO.MemoryBuffer()
    p7.write(out) 
    return out.read()
+1  A: 

pycrypto is very incomplete. It does not support the padding schemes and formats that you need. Adding support for those formats is not trivial and will require a lot of time.

abc
is there something else that does support what is needed?
chris
M2Crypto is a wrapper for openssl. Since openssl is widely used I'm a little surprised that building M2Crypto is not possible on your servers. I'd give it another try. There are a few alternative python wrappers for openssl, but unfortunately I have no experience with them.
abc
A: 

You may be able to set up a virtual machine locally and duplicate enough of the webfaction server environment to build it yourself. Then upload to somewhere on your pythonpath

gnibbler
+1  A: 

I was able to get it to build. Here is all you need to do to make it happen:

cat >> ~/.pydistutils.cfg << EOF
[build_ext]
include_dirs=/usr/include/openssl
EOF
easy_install-2.5 --install-dir=$HOME/lib/python2.5 --script-dir=$HOME/bin m2crypto
chris