Devos50
Devos50

Reputation: 2035

Error when importing M2Crypto in Python on Windows x64

I'm trying to use the M2Crypto library on Windows 64 bit. I'm using a 64 bit version of Python and I've compiled M2Crypto from source, linking against Openssl 1.0.2d. This compilation was successful and I've installed the package by running python setup.py install.

When I run Python from command line and I type import M2Crypto, it works. Next, I'm trying to use the library by creating an Elliptic Curve key:

from M2Crypto import EC
kp = EC.gen_params(EC.NID_sect233k1)
kp.gen_key()
kp.save_key("test.key", None)

This gives the following error:

OPENSSL_Uplink(00007ABCAFE839000,08): no OPENSSL_Applink

I'm not really sure what to do with this error. I think the issue has to do with Openssl. Some sources on internet are writing that I should recompile Python but I'm not sure how to do that. I am wondering whether there is a more easy way to fix this error since I don't like to recompile my Python distribution.

This issue is only occurring on Windows. I have no problem with installing M2Crypto on OS X or Linux.

Upvotes: 2

Views: 942

Answers (1)

Reinier Torenbeek
Reinier Torenbeek

Reputation: 17383

I can not reproduce your issue with my own installation of Python and M2Crypto. However, I have seen the no OPENSSL_Applink happen on Windows when openssl/applink.c was not included and compiled into the application and when subsequently a BIO was used to write to a file or to stdin or stdout.

Therefore, you could try using a memory BIO and then reading from that memory BIO and writing the contents to a file in Python itself, like this:

>>> from M2Crypto import EC
>>> kp = EC.gen_params(EC.NID_sect233k1)
>>> kp.gen_key()
>>> from M2Crypto import BIO
>>> membuf = BIO.MemoryBuffer()
>>> kp.save_key_bio(membuf, None)
1
>>> with open('test2.key', 'w') as f:
...     f.write(membuf.read())
...

This is not a real fix, just a workaround.

Upvotes: 2

Related Questions