[Ironpython-users] using IronPython with pycrypto

Jeff Hardy jdhardy at gmail.com
Mon Nov 3 14:12:15 CET 2014


Hi Baron,
Sorry for the late reply. You've encountered the biggest issue with
IronPython, which is that it can't load Python extensions that are
written in C.

In this case, the _AES modules (_AES.so) is a C library that depends
on CPython's implementation. Unfortunately, if PyCrypto doesn't
provide a pure-Python fallback (and it looks like it doesn't, although
I may have missed it), there's no way to get it to work in IronPython
(there is the old IronClad project, but it hasn't been updated in
years and almost certainly would not work with current versions).

- Jeff

On Wed, Oct 29, 2014 at 10:43 PM, Baron Oldenburg
<Baron.Oldenburg at leviathansecurity.com> wrote:
> Hello!
>
>
>
> I’m attempting to import a module (KillerBee) in IronPython. I’ve
> encountered a couple of issues along the way, some of which I’ve been able
> to fix. I’m hoping the mailing list can help me out with what I haven’t
> fixed. Here are the problems I’ve encountered and the steps I’ve taken:
>
>
>
> 1.       “Exception during object creation: no module named killerbee”
>
> a.       Per
> http://stackoverflow.com/questions/1371994/importing-external-module-in-ironpython,
> I added the following which allowed IronPython to recognize killerbee as a
> module and let me import it:
>
> var paths = engine.GetSearchPaths();
>
> paths.Add(@"/usr/lib/python2.7/site-packages/");
>
> engine.SetSearchPaths(paths);
>
> 2.       “Exception during object creation: cannot import _AES from
> Crypto.Cipher”
>
> a.       I tracked this error down to this line in a killerbee file
> “dot154decode.py”:
>
> “from Crypto.Cipher import AES”
>
> and then further to /usr/lib/python2.7/site-packages/Crypto/Cipher/AES.py:
>
>
> “from Crypto.Cipher import _AES”
>
> In the same directory as AES.py there is an _AES.so.
>
> b.      If I attempt this from the python interpreter, there are no errors:
>
> $ python
>
> Python 2.7.8 (default, Sep 24 2014, 18:26:21)
>
> [GCC 4.9.1 20140903 (prerelease)] on linux2
>
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> from Crypto.Cipher import AES
>>>> import Crypto
>>>> print Crypto.__version__
>
> 2.6.1
>
>>>>
>
> c.       If I attempt this from IronPython with the following code (instead
> of importing killerbee):
>
> engine.ImportModule("Crypto.Cipher.AES");
>
> I get the same error (“cannot import _AES from Crypto.Cipher”).
>
> d.      If I attempt to just import Crypto.Cipher
> (“engine.ImportModule("Crypto.Cipher");”) there are no errors.
>
> Before I start trying increasingly complicated workarounds, does anyone have
> an idea as to the possible root cause? I’ve searched around on the Internet
> generally and in outstanding IronPython issues specifically for other people
> with this problem, but I’ve only found the following semi-related hits
> around IronPython and pycrypto:
>
>
>
> ·
> http://stackoverflow.com/questions/2365661/how-to-create-a-package-in-c-sharp-for-use-in-ironpython
>
> ·         http://www.pyinstaller.org/ticket/881
>
> ·
> http://lists.ironpython.com/pipermail/users-ironpython.com/2006-November/018956.html
>
> ·         https://bitbucket.org/mvdk/ironpycrypto
>
>
>
> The relevant parts of the source look like this:
>
>
>
> using IronPython;
>
> using IronPython.Hosting;
>
> using Microsoft.Scripting;
>
> using Microsoft.Scripting.Hosting;
>
>
>
> ScriptEngine engine = Python.CreateEngine();
>
> var paths = engine.GetSearchPaths();
>
> paths.Add(@"/usr/lib/python2.7/site-packages/");
>
> engine.SetSearchPaths(paths);
>
> engine.ImportModule("Crypto.Cipher.AES");
>
>
>
> Thanks for your time! I’m happy to provide any other details or source code
> necessary to continue debugging.
>
>
>
> Baron
>
>
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> https://mail.python.org/mailman/listinfo/ironpython-users
>


More information about the Ironpython-users mailing list