leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.13k stars 247 forks source link

sha2 library fails for some reason #64

Closed qaisjp closed 8 years ago

qaisjp commented 11 years ago

sudo luarocks install sha2 The sha2 library works perfectly well in the Lua console

> require"sha2"
> print(sha2.sha512hex("tet"))
c28ca33f1069c6adaa16d0f056e3d7d9039f58584ee4ac424b465279c1f4cf3f37ea23ce372710ad8163aca0506d06b9784f3bb91d6d866e48737b7e5dbde961
>  

but when trying it in lapis. after doing screen -r lapis I typed lapis server and the regular lapis information shows up (including lua_cache stuff) those stuff disappeared.

vagrant@precise32:/vagrant/web$ screen -dmS lapis
vagrant@precise32:/vagrant/web$ screen -r lapis

b6b3b000-b6b5b000 rw-p 00000000 00:00 0 
b6b5b000-b6b64000 r-xp 00000000 fc:00 2234938    /usr/local/lib/lua/5.1/lpeg.so
b6b64000-b6b65000 r--p 00008000 fc:00 2234938    /usr/local/lib/lua/5.1/lpeg.so
b6b65000-b6b66000 rw-p 00009000 fc:00 2234938    /usr/local/lib/lua/5.1/lpeg.so
b6b66000-b6b6b000 r-xp 00000000 fc:00 2234678    /usr/local/openresty/lualib/cjson.so
b6b6b000-b6b6c000 ---p 00005000 fc:00 2234678    /usr/local/openresty/lualib/cjson.so
b6b6c000-b6b6d000 r--p 00005000 fc:00 2234678    /usr/local/openresty/lualib/cjson.so
b6b6d000-b6b6e000 rw-p 00006000 fc:00 2234678    /usr/local/openresty/lualib/cjson.so
b6b6e000-b6b8e000 rw-p 00000000 00:00 0 
b6b8e000-b6bb2000 rw-p 00000000 00:00 0 
b6bb2000-b6c54000 r-xp 00000000 fc:00 1840134    /usr/lib/i386-linux-gnu/libsqlite3.so.0.8.6
b6c54000-b6c55000 r--p 000a2000 fc:00 1840134    /usr/lib/i386-linux-gnu/libsqlite3.so.0.8.6
b6c55000-b6c56000 rw-p 000a3000 fc:00 1840134    /usr/lib/i386-linux-gnu/libsqlite3.so.0.8.6
b6c56000-b6c57000 rw-p 00000000 00:00 0 
b6c57000-b6c9a000 r-xp 00000000 fc:00 1843382    /usr/lib/i386-linux-gnu/libhx509.so.5.0.0
b6c9a000-b6c9b000 ---p 00043000 fc:00 1843382    /usr/lib/i386-linux-gnu/libhx509.so.5.0.0
b6c9b000-b6c9c000 r--p 00043000 fc:00 1843382    /usr/lib/i386-linux-gnu/libhx509.so.5.0.0
b6c9c000-b6c9e000 rw-p 00044000 fc:00 1843382    /usr/lib/i386-linux-gnu/libhx509.so.5.0.0
b6c9e000-b6cab000 r-xp 00000000 fc:00 1843376    /usr/lib/i386-linux-gnu/libheimbase.so.1.0.0
b6cab000-b6cac000 r--p 0000c000 fc:00 1843376    /usr/lib/i386-linux-gnu/libheimbase.so.1.0.0
b6cac000-b6cad000 rw-p 0000d000 fc:00 1843376    /usr/lib/i386-linux-gnu/libheimbase.so.1.0.0
b6cad000-b6cd4000 r-xp 00000000 fc:00 1843379    /usr/lib/i386-linux-gnu/libwind.so.0.0.0
b6cd4000-b6cd5000 r--p 00027000 fc:00 1843379    /usr/lib/i386-linux-gnu/libwind.so.0.0.0
b6cd5000-b6cd6000 rw-p 00028000 fc:00 1843379    /usr/lib/i386-linux-gnu/libwind.so.0.0.0
b6cd6000-b6cd9000 r-xp 00000000 fc:00 2883894    /lib/i386-linux-gnu/libgpg-error.so.0.8.0
b6cd9000-b6cda000 r--p 00002000 fc:00 2883894    /lib/i386-linux-gnu/libgpg-error.so.0.8.0
b6cda000-b6cdb000 rw-p 00003000 fc:00 2883894    /lib/i386-linux-gnu/libgpg-error.so.0.8.0
b6cdb000-b6cdc000 rw-p 00000000 00:00 0 
b6cdc000-b6cec000 r-xp 00000000 fc:00 1843351    /usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
b6cec000-b6ced000 r--p 0000f000 fc:00 1843351    /usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
b6ced000-b6cee000 rw-p 00010000 fc:00 1843351    /usr/lib/i386-linux-gnu/libp11-kit.so.0.0.0
b6cee000-b6cfe000 r-xp 00000000 fc:00 1843353    /usr/lib/i386-linux-gnu/libtasn1.so.3.1.12
b6cfe000-b6cff000 r--p 0000f000 fc:00 1843353    /usr/lib/i386-linux-gnu/libtasn1.so.3.1.12
b6cff000-b6d00000 rw-p 00010000 fc:00 1843353    /usr/lib/i386-linux-gnu/libtasn1.so.3.1.12
b6d00000-b6d14000 r-xp 00000000 fc:00 1843345    /usr/lib/i386-linux-gnu/libroken.so.18.1.0
b6d14000-b6d15000 r--p 00013000 fc:00 1843345    /usr/lib/i386-linux-gnu/libroken.so.18.1.0
b6d15000-b6d16000 rw-p 00014000 fc:00 1843345    /usr/lib/i386-linux-gnu/libroken.so.18.1.0
b6d16000-b6d48000 r-xp 00000000 fc:00 1843373    /usr/lib/i386-linux-gnu/libhcrypto.so.4.1.0
b6d48000-b6d49000 r--p 00032000 fc:00 1843373    /usr/lib/i386-linux-gnu/libhcrypto.so.4.1.0
b6d49000-b6d4a000 rw-p 00033000 fc:00 1843373    /usr/lib/i386-linux-gnu/libhcrypto.so.4.1.0
b6d4a000-b6d4b000 rw-p 00000000 00:00 0 
b6d4b000-b6deb000 r-xp 00000000 fc:00 1843348    /usr/lib/i386-linux-gnu/libasn1.so.8.0.0
b6deb000-b6dec000 ---p 000a0000 fc:00 1843348    /usr/lib/i386-linux-gnu/libasn1.so.8.0.0
b6dec000-b6ded000 r--p 000a0000 fc:00 1843348    /usr/lib/i386-linux-gnu/libasn1.so.8.0.0
b6ded000-b6df0000 rw-p 000a1000 fc:00 1843348    /usr/lib/i386-linux-gnu/libasn1.so.8.0.0
b6df0000-b6df1000 rw-p 00000000 00:00 0 
b6df1000-b6e70000 r-xp 00000000 fc:00 1843385    /usr/lib/i386-linux-gnu/libkrb5.so.26.0.0
b6e70000-b6e72000 r--p 0007e000 fc:00 1843385    /usr/lib/i386-linux-gnu/libkrb5.so.26.0.0
b6e72000-b6e74000 rw-p 00080000 fc:00 1843385    /usr/lib/i386-linux-gnu/libkrb5.so.26.0.0
b6e74000-b6e7a000 r-xp 00000000 fc:00 1843388    /usr/lib/i386-linux-gnu/libheimntlm.so.0.1.0
b6e7a000-b6e7b000 r--p 00005000 fc:00 1843388    /usr/lib/i386-linux-gnu/libheimntlm.so.0.1.0
b6e7b000-b6e7c000 rw-p 00006000 fc:00 1843388    /usr/lib/i386-linux-gnu/libheimntlm.so.0.1.0
b6e7c000-b6efe000 r-xp 00000000 fc:00 2883896    /lib/i386-linux-gnu/libgcrypt.so.11.7.02013/10/30 11:39:32 [notice] 4020#0: signal 17 (SIGCHLD) received
2013/10/30 11:39:32 [alert] 4020#0: worker process 4021 exited on signal 6
2013/10/30 11:39:32 [notice] 4020#0: start worker process 4022

I can then CTRL+C out of there and proceed to leave my screen.

leafo commented 11 years ago

If you uninstall the sha2 module everything starts up okay?

qaisjp commented 11 years ago

this only occurs when the function is called. right now its being required at the top of my auth subapp and only being used there, the site works fine (and i can see route logs) until i send a login request. the minute i send a login request my route logs disappear from terminal, that thing appears and I get a "No data received :(" error in chrome.

leafo commented 11 years ago

hmm, okay. I would create and issue on the OpenResty mailing list. First try creating a new app with just an Nginx config and a content_by_lua block that runs sha2 and see if it breaks the server.

This is the config, I used, I was unable to reproduce the crash: (You can just put this in a directory and run lapis server if you don't know how to start nginx manually)

worker_processes 1;
error_log stderr notice;
daemon off;

events {
  worker_connections 1024;
}

http {
  server {
    listen 8181;
    location / {
      default_type text/html;
      content_by_lua '
        local sha2 = require("sha2")
        ngx.say(sha2.sha512hex("hello world"))
      ';
    }
  }
}
leafo commented 11 years ago

Also if you are hashing passwords I recommend using bcrypt or scrypt. Here's a bcrypt binding I use in my apps: https://github.com/leafo/luabcrypt

qaisjp commented 11 years ago

I'll use bcrypt for now, I'll test out that sha2 thing an a little bit.

qaisjp commented 11 years ago

I was going to ask on the luabcrypt repo but its got issues disabled, what is your recommended way of installing openssl?

Using that thing you sent me the same thing appears:


b70b1000-b70b2000 r--p 00013000 fc:00 2883622    /lib/i386-linux-gnu/libresolv-2.15.so
b70b2000-b70b3000 rw-p 00014000 fc:00 2883622    /lib/i386-linux-gnu/libresolv-2.15.so
b70b3000-b70b5000 rw-p 00000000 00:00 0 
b70b5000-b70b7000 r-xp 00000000 fc:00 2883899    /lib/i386-linux-gnu/libkeyutils.so.1.4
b70b7000-b70b8000 r--p 00002000 fc:00 2883899    /lib/i386-linux-gnu/libkeyutils.so.1.4
b70b8000-b70b9000 rw-p 00003000 fc:00 2883899    /lib/i386-linux-gnu/libkeyutils.so.1.4
b70b9000-b70c0000 r-xp 00000000 fc:00 1837163    /usr/lib/i386-linux-gnu/libkrb5support.so.0.1
b70c0000-b70c1000 r--p 00006000 fc:00 1837163    /usr/lib/i386-linux-gnu/libkrb5support.so.0.1
b70c1000-b70c2000 rw-p 00007000 fc:00 1837163    /usr/lib/i386-linux-gnu/libkrb5support.so.0.1
b70c2000-b70c3000 rw-p 00000000 00:00 0 
b70c3000-b70e9000 r-xp 00000000 fc:00 1837156    /usr/lib/i386-linux-gnu/libk5crypto.so.3.1
b70e9000-b70ea000 r--p 00025000 fc:00 1837156    /usr/lib/i386-linux-gnu/libk5crypto.so.3.1
b70ea000-b70eb000 rw-p 00026000 fc:00 1837156    /usr/lib/i386-linux-gnu/libk5crypto.so.3.1
b70eb000-b7107000 r-xp 00000000 fc:00 2883628    /lib/i386-linux-gnu/libgcc_s.so.1
b7107000-b7108000 r--p 0001b000 fc:00 2883628    /lib/i386-linux-gnu/libgcc_s.so.1
b7108000-b7109000 rw-p 0001c000 fc:00 2883628    /lib/i386-linux-gnu/libgcc_s.so.1
b7109000-b710c000 r-xp 00000000 fc:00 2883610    /lib/i386-linux-gnu/libdl-2.15.so
b710c000-b710d000 r--p 00002000 fc:00 2883610    /lib/i386-linux-gnu/libdl-2.15.so
b710d000-b710e000 rw-p 00003000 fc:00 2883610    /lib/i386-linux-gnu/libdl-2.15.so
b710e000-b7138000 r-xp 00000000 fc:00 2883611    /lib/i386-linux-gnu/libm-2.15.so
b7138000-b7139000 r--p 00029000 fc:00 2883611    /lib/i386-linux-gnu/libm-2.15.so
b7139000-b713a000 rw-p 0002a000 fc:00 2883611    /lib/i386-linux-gnu/libm-2.15.so
b713a000-b7188000 r-xp 00000000 fc:00 1843398    /usr/lib/i386-linux-gnu/libldap_r-2.4.so.2.8.1
b7188000-b7189000 ---p 0004e000 fc:00 1843398    /usr/lib/i386-linux-gnu/libldap_r-2.4.so.2.8.1
b7189000-b718a000 r--p 0004e000 fc:00 1843398    /usr/lib/i386-linux-gnu/libldap_r-2.4.so.2.8.1
b718a000-b718b000 rw-p 0004f000 fc:00 1843398    /usr/lib/i386-linux-gnu/libldap_r-2.4.so.2.8.1
b718b000-b718d000 rw-p 00000000 00:00 0 
b718d000-b71c8000 r-xp 00000000 fc:00 1837158    /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2.2
b71c8000-b71c9000 ---p 0003b000 fc:00 1837158    /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2.2
b71c9000-b71ca000 r--p 0003b000 fc:00 1837158    /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2.2
b71ca000-b71cb000 rw-p 0003c000 fc:00 1837158    /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2.2
b71cb000-b71ce000 r-xp 00000000 fc:00 2883596    /lib/i386-linux-gnu/libcom_err.so.2.1
b71ce000-b71cf000 r--p 00002000 fc:00 2883596    /lib/i386-linux-gnu/libcom_err.so.2.1
b71cf000-b71d0000 rw-p 00003000 fc:00 2883596    /lib/i386-linux-gnu/libcom_err.so.2.1
b71d0000-b7298000 r-xp 00000000 fc:00 1837161    /usr/lib/i386-linux-gnu/libkrb5.so.3.3
b7298000-b729e000 r--p 000c7000 fc:00 1837161    /usr/lib/i386-linux-gnu/libkrb5.so.3.3
b729e000-b729f000 rw-p 000cd000 fc:00 1837161    /usr/lib/i386-linux-gnu/libkrb5.so.3.3
b729f000-b743e000 r-xp 00000000 fc:00 2883603    /lib/i386-linux-gnu/libc-2.15.so
b743e000-b7440000 r--p 0019f000 fc:00 2883603    /lib/i386-linux-gnu/libc-2.15.so
b7440000-b7441000 rw-p 001a1000 fc:00 2883603    /lib/i386-linux-gnu/libc-2.15.so
b7441000-b7444000 rw-p 00000000 00:00 0 
b7444000-b7458000 r-xp 00000000 fc:00 2883815    /lib/i386-linux-gnu/libz.so.1.2.3.4
b7458000-b7459000 r--p 00013000 fc:00 2883815    /lib/i386-linux-gnu/libz.so.1.2.3.4
b7459000-b745a000 rw-p 00014000 fc:00 2883815    /lib/i386-linux-gnu/libz.so.1.2.3.4
b745a000-b745b000 rw-p 00000000 00:00 0 
b745b000-b75ed000 r-xp 00000000 fc:00 2883764    /lib/i386-linux-gnu/libcrypto.so.1.0.0
b75ed000-b75fc000 r--p 00192000 fc:00 2883764    /lib/i386-linux-gnu/libcrypto.so.1.0.0
b75fc000-b7603000 rw-p 001a1000 fc:00 2883764    /lib/i386-linux-gnu/libcrypto.so.1.0.0
b7603000-b7606000 rw-p 00000000 00:00 0 
b7606000-b7657000 r-xp 00000000 fc:00 2883656    /lib/i386-linux-gnu/libssl.so.1.0.0
b7657000-b7659000 r--p 00050000 fc:00 2883656    /lib/i386-linux-gnu/libssl.so.1.0.0
b7659000-b765d000 rw-p 00052000 fc:00 2883656    /lib/i386-linux-gnu/libssl.so.1.0.0
2013/10/30 18:56:19 [notice] 17799#0: signal 17 (SIGCHLD) received
2013/10/30 18:56:19 [alert] 17799#0: worker process 17800 exited on signal 6
2013/10/30 18:56:19 [notice] 17799#0: start worker process 17801

If you want to explore the error on my system, I'm running Vagrant ( http://vagrantup.com ) so I could send you my current system if you want. I rebuilt my system recently so I can confirm it wasn't that instance of an installation.

leafo commented 11 years ago

The bcrypt library I linked to has no dependencies. Are you talking about the sha2 library?

qaisjp commented 11 years ago

You require openssl for bcrypt http://qs.lc/5pww

leafo commented 11 years ago

oh, ooops. It's actually just a library I forked. I have no answer for you then. I just install openssl from my distro

seanlai commented 11 years ago

If you are on Debian, try installing libssl-dev first

qaisjp commented 11 years ago

how do i compile luabcrypt, i've tried both the fork and original and i get this:

vagrant@precise32:/vagrant/luabcrypt-master$ make
gcc -o bcrypt.so src/luabcrypt.c src/bcrypt.c src/blowfish.c -O2 -shared -fPIC -lcrypto -Wall -Wextra -Werror
src/luabcrypt.c:4:17: fatal error: lua.h: No such file or directory
compilation terminated.
make: *** [bcrypt] Error 1
vagrant@precise32:/vagrant/luabcrypt-master$ 

Do I need the lua source?

leafo commented 11 years ago

try

luarocks install https://raw.github.com/leafo/luabcrypt/master/rockspec/bcrypt-scm-1.rockspec
qaisjp commented 11 years ago

did that already before. https requires luasec, which fails to install because of

sudo luarocks install luasec
Error: Could not find expected file libssl.a, or libssl.so, or libssl.so.* for OPENSSL -- you may have to install OPENSSL in your system and/or pass OPENSSL_DIR or OPENSSL_LIBDIR to the luarocks command. Example: luarocks install luasec OPENSSL_DIR=/usr/local
vagrant@precise32:/vagrant/luabcrypt-master$ sudo apt-get install libssl-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libssl-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 146 not upgraded.
leafo commented 11 years ago

What distro are you using? Sounds like you need to install libssl-dev (or the equivalent) as @seanlai suggested

leafo commented 11 years ago

Run this in the folder where you checked out the repo to avoid having LuaRocks make an https request:

luarocks install bcrypt-scm-1.rockspec
qaisjp commented 11 years ago

wget https://raw.github.com/leafo/luabcrypt/master/rockspec/bcrypt-scm-1.rockspec success sudo apt-get install git success sudo luarocks install bcrypt-scm-1.rockspec success bcrypt scm-1 is now built and installed in /usr/local/ (license: MIT)

> require "bcrypt"
error loading module 'bcrypt' from file '/usr/local/lib/lua/5.1/bcrypt.so':
    /usr/local/lib/lua/5.1/bcrypt.so: undefined symbol: RAND_bytes
stack traceback:
    [C]: ?
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: ?
> ```
leafo commented 11 years ago

Do you have openssl dev installed?

qaisjp commented 11 years ago

openssl-dev doesn't exist, tried doing sudo apt-get install openssl and i installed it. same error. i read somewhere that "openssl-dev" is basically "libssl-dev"

seanlai commented 11 years ago

Hey qaisjp, did you try sudo apt-get install libssl-dev. It works for me.

If it doesn't work, you should really try asking on StackOverflow. You might have better luck getting help there.

qaisjp commented 11 years ago
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
 * Documentation:  https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Thu Oct 31 01:46:04 2013 from 10.0.2.2
vagrant@precise32:~$ sudo apt-get install libssl-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libssl-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 145 not upgraded.
vagrant@precise32:~$ 

@seanlai :(

qaisjp commented 11 years ago

http://stackoverflow.com/questions/19712859/issue-installing-libssl-for-use-with-bcrypt lets just hope i dont get negative repped for not doing this on superuser, im sure this should be on soverflow because its lua related but its superuser related due to it being an issue with openssl.

leafo commented 11 years ago

If you're still looking for things to try the bcrypt library I had forked has been updated to use a different library, maybe you can see if that runs: https://github.com/mikejsavage/lua-bcrypt It doesn't appear to use openssl anymore.

qaisjp commented 11 years ago

Why oh why.

vagrant@precise32:/vagrant$ rm bcrypt-scm-1.rockspec 
vagrant@precise32:/vagrant$ wget https://raw.github.com/mikejsavage/lua-bcrypt/master/rockspec/bcrypt-scm-1.rockspec
--2013-10-31 17:20:25--  https://raw.github.com/mikejsavage/lua-bcrypt/master/rockspec/bcrypt-scm-1.rockspec
Resolving raw.github.com (raw.github.com)... 185.31.19.133
Connecting to raw.github.com (raw.github.com)|185.31.19.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 418 [text/plain]
Saving to: `bcrypt-scm-1.rockspec'

100%[=========================================================================================================================================================================>] 418         --.-K/s   in 0s      

2013-10-31 17:20:26 (4.39 MB/s) - `bcrypt-scm-1.rockspec' saved [418/418]

vagrant@precise32:/vagrant$ luarocks install bcrypt-scm-1.rockspec 

Error: Your user does not have write permissions in /usr/local/ 
-- you may want to run as a privileged user or use your local tree with --local.
vagrant@precise32:/vagrant$ sudo luarocks install bcrypt-scm-1.rockspec 
Using bcrypt-scm-1.rockspec... switching to 'build' mode
Cloning into 'lua-bcrypt'...
remote: Counting objects: 24, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 24 (delta 3), reused 21 (delta 3)
Receiving objects: 100% (24/24), 28.35 KiB, done.
Resolving deltas: 100% (3/3), done.
Warning: variable CFLAGS was not passed in build_variables
make -C lib/bcrypt
make[1]: Entering directory `/tmp/luarocks_bcrypt-scm-1-1014/lua-bcrypt/lib/bcrypt'
gcc -c -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith -O2 -fomit-frame-pointer -funroll-loops -fPIC crypt_blowfish.c
gcc -c x86.S
gcc -c -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith -O2 -fomit-frame-pointer -funroll-loops -fPIC crypt_gensalt.c
gcc -c -W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith -O2 -fomit-frame-pointer -funroll-loops -fPIC wrapper.c
make[1]: Leaving directory `/tmp/luarocks_bcrypt-scm-1-1014/lua-bcrypt/lib/bcrypt'
gcc -o bcrypt.so src/main.c lib/bcrypt/crypt_blowfish.o lib/bcrypt/x86.o lib/bcrypt/crypt_gensalt.o lib/bcrypt/wrapper.o -O2 -shared -fPIC -fomit-frame-pointer -funroll-loops -lcrypto -Ilib/bcrypt -Wall -Wextra -Werror -Wbad-function-cast -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Wundef -Wpointer-arith
src/main.c:7:17: fatal error: lua.h: No such file or directory
compilation terminated.
make: *** [bcrypt] Error 1

Error: Build error: Failed building.
vagrant@precise32:/vagrant$ 
leafo commented 11 years ago

This is why I forked the library, the Makefile included doesn't work on all systems. You can edit the top level Makefile to add -I /path/to/lua/headers and that should fix it.

leafo commented 11 years ago

Okay, sorry you're having so much trouble :)

I patched the latest version of lua-bcrypt to use LuaRock's build system instead of make so it should install on your system:

Try running this command:

luarocks install http://leafo.net/dump/bcrypt-leafo-1.rockspec

I'll push this patch upstream if it works for you.

qaisjp commented 11 years ago

no problem :) i'll just carry on development without password hashing and fakes passes for now. This is my log, ended up with a different error now:

...
bcrypt leafo-1 is now built and installed in /usr/local/ (license: MIT)
...
vagrant@precise32:/vagrant$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require "bcrypt"
error loading module 'bcrypt' from file '/usr/local/lib/lua/5.1/bcrypt.so':
    /usr/local/lib/lua/5.1/bcrypt.so: undefined symbol: _BF_body_r
stack traceback:
    [C]: ?
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: ?
> 
qaisjp commented 11 years ago

Okay I re-read the build information before it was finished installing, seems it failed somewhere:

vagrant@precise32:/vagrant$ sudo luarocks install http://leafo.net/dump/bcrypt-leafo-1.rockspec
Using http://leafo.net/dump/bcrypt-leafo-1.rockspec... switching to 'build' mode
Cloning into 'luabcrypt'...
remote: Counting objects: 37, done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 37 (delta 7), reused 27 (delta 5)
Receiving objects: 100% (37/37), 36.81 KiB, done.
Resolving deltas: 100% (7/7), done.
Branch latest set up to track remote branch latest from origin.
gcc -O2 -fPIC -I/usr/include/lua5.1 -c lib/bcrypt/crypt_blowfish.c -o lib/bcrypt/crypt_blowfish.o -Ilib/bcrypt/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c lib/bcrypt/crypt_gensalt.c -o lib/bcrypt/crypt_gensalt.o -Ilib/bcrypt/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c lib/bcrypt/wrapper.c -o lib/bcrypt/wrapper.o -Ilib/bcrypt/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/main.c -o src/main.o -Ilib/bcrypt/
src/main.c: In function 'randomBytes':
src/main.c:39:6: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
gcc -shared -o bcrypt.so -L/usr/local/lib lib/bcrypt/crypt_blowfish.o lib/bcrypt/crypt_gensalt.o lib/bcrypt/wrapper.o src/main.o
Updating manifest for /usr/local/lib/luarocks/rocks

bcrypt leafo-1 is now built and installed in /usr/local/ (license: MIT)
leafo commented 11 years ago

Cool, so everything is working?

qaisjp commented 11 years ago

Nope :(

vagrant@precise32:/vagrant$ sudo luarocks install http://leafo.net/dump/bcrypt-leafo-1.rockspec
...
Branch latest set up to track remote branch latest from origin.
gcc -O2 -fPIC -I/usr/include/lua5.1 -c lib/bcrypt/crypt_blowfish.c -o lib/bcrypt/crypt_blowfish.o -Ilib/bcrypt/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c lib/bcrypt/crypt_gensalt.c -o lib/bcrypt/crypt_gensalt.o -Ilib/bcrypt/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c lib/bcrypt/wrapper.c -o lib/bcrypt/wrapper.o -Ilib/bcrypt/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/main.c -o src/main.o -Ilib/bcrypt/
src/main.c: In function 'randomBytes':
src/main.c:39:6: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
gcc -shared -o bcrypt.so -L/usr/local/lib lib/bcrypt/crypt_blowfish.o lib/bcrypt/crypt_gensalt.o lib/bcrypt/wrapper.o src/main.o
Updating manifest for /usr/local/lib/luarocks/rocks

bcrypt leafo-1 is now built and installed in /usr/local/ (license: MIT)
leafo commented 11 years ago

It says it built, you should be able to ignore the warning.

qaisjp commented 11 years ago
vagrant@precise32:/vagrant/web$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require "bcrypt"
error loading module 'bcrypt' from file '/usr/local/lib/lua/5.1/bcrypt.so':
    /usr/local/lib/lua/5.1/bcrypt.so: undefined symbol: _BF_body_r
stack traceback:
    [C]: ?
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: ?
> 

Then this happens :/

blablacio commented 10 years ago

@qaisjp Take a look at this change, it might fix your problem: https://github.com/blablacio/luabcrypt/commit/da76b3979a7a46ef7163c70147e41e55cfd506d1

qaisjp commented 10 years ago

thanks @blablacio - i'll test it one day.

qaisjp commented 8 years ago

bcrypt works all fine and dandy now :tada: