OpenSSL and LuaSec/LuaCrypto are pretty common libraries within the Lua eco system. Where other cornerstone libraries are on their own (LuaSocket and LuaFileSystem/lfs), the issue with LuaSec/LuaCrypto is that they are bindings to OpenSSL, which requires a properly compiled OpenSSL version. (“properly compiled” is related to the runtime libraries used, they need to be compiled against the same versions, so just grabbing the OpenSSL dll files from some other project might deliver unexpected results/failures/crashes)
This post assumes: Using the GCC compiler with MinGW, and building 32 bit versions.
Download the OpenSSL source from http://www.openssl.org/source/ and unpack it in “c:\temp\openssl\”.
Two issues needed to be fixed in my case;
- I had to add ‘perl’ to my MinGW setup (see this post on how to setup MinGW for use with Lua on Windows). Just open the GUI (in my case in “C:\MinGW\libexec\mingw-get\guimain.exe”), under “all packages / MSYS / MinGW Developer Toolkit” select all the “msys-perl” packages, and select “Apply changes” from the “Installation” menu.
- With older openssl versions 3 files gave me errors, due to failed symlinks from the unpacked archive. Update the following files in “c:\temp\openssl\test\”; rc5test.c, md2test.c, jpaketest.c and change the line ‘dummytest.c’ to ‘#include “dummytest.c” ‘. (source of the resolution). Version 1.0.2f did not give me those errors anymore.
Start MSYS (comes with MinGW, in my case in “C:\MinGW\MSYS\1.0\msys.bat”). And execute the following;
cd /c/temp/openssl ./configure mingw shared make make test
This should build and test OpenSSL (takes a few minutes). Now add the OpenSSL libraries to the Lua config (next to lua.exe), using the file explorer, or type the following (with adjusted paths) into a commandshell;
copy "c:\temp\openssl\apps\*eay32.dll" "c:\program files (x86)\Lua\5.1\bin"
Building the LuaSec and LuaCrypto bindings
Let LuaRocks build and install the LuaSec binding between Lua and OpenSSL, by doing from a commandshell;
luarocks install luasec OPENSSL_INCDIR=/temp/openssl/include/ OPENSSL_LIBDIR=/temp/openssl/ OPENSSL_BINDIR=/temp/openssl/apps/
NOTE: At the time of writing the official published rockspec would not work, so instead of the `install luasec` part in the LuaRocks command I had to use the full path to the rockspec on github; `install https://raw.githubusercontent.com/brunoos/luasec/master/luasec-0.6alpha-3.rockspec`.
For LuaCrypto we can use a similar command, just replace `luasec` with `luacrypto`;
luarocks install luacrypto OPENSSL_INCDIR=/temp/openssl/include/ OPENSSL_LIBDIR=/temp/openssl/ OPENSSL_BINDIR=/temp/openssl/apps/
That’s all there is to it!