Search code examples
ruby-on-railsrubygemsjrubyscrypt

jruby bundle install not working at gem 'scrypt'


I am trying to do a bundle install for jruby (Windows) and I am getting this error:

C:/jruby-1.7.19/bin/jruby.exe -rubygems C:/jruby-1.7.19/lib/ruby/gems/shared/gems/rake-10.1.0/bin/rake RUBYARCHDIR=C:/jruby-1.7.19/lib/ruby/gems/shared/extensions/universal-java-1.8/1.9/scrypt-2.0.2 RUBYLIBDIR=C:/jruby-1.7.19/lib/ruby/gems/shared/extensions/universal-java-1.8/1.9/scrypt-2.0.2
io/console not supported; tty will not be manipulated
mkdir -p i386-windows
cc -fexceptions -O -fno-omit-frame-pointer -fno-strict-aliasing -Wall -msse -msse2 -fPIC  -o i386-windows/crypto_scrypt-sse.o -c ./crypto_scrypt-sse.c
rake aborted!
Command failed with status (127): [cc -fexceptions -O -fno-omit-frame-pointer...]
org/jruby/RubyProc.java:271:in `call'
org/jruby/RubyProc.java:271:in `call'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyArray.java:1613:in `each'
Tasks: TOP => default => i386-windows/scrypt_ext.dll => i386-windows/crypto_scrypt-sse.o
(See full trace by running task with --trace)

rake failed, uncaught signal 1

I have installed jruby and JVM.


Solution

  • You're trying to install a gem with native extensions inside a java version of ruby: usually a bad idea...

    I found a pure java implementation of scrypt algorithm at https://github.com/wg/scrypt.

    You need to download the jar file from Maven (http://search.maven.org/remotecontent?filepath=com/lambdaworks/scrypt/1.4.0/scrypt-1.4.0.jar), add it to your library path or require the jar in your code.

    Next is to write a wrapper to imitate the scrypt behavior to use it as a drop-in replacement in your ruby/rails code.

    Alternatively, you could just remove the scrypt bits and use the java library directly. Here's a snippet tested in jirb (1.7.20)...

    >> require 'java'
    => true
    >> require './scrypt-1.4.0.jar'
    => true
    >> java_import 'com.lambdaworks.crypto.SCryptUtil'
    => [Java::ComLambdaworksCrypto::SCryptUtil]
    >> passwd,n,r,p = 'secret',16384,8,1
    => ["secret", 16384, 8, 1]
    >> hashed_passwd = SCryptUtil.scrypt(passwd,n,r,p)
    => "$s0$e0801$MzcxaOBVz7kaVU6E5HV0cg==$RAx9ADWVeyZE5JRl+J1NpiBSEPNabEcVdR7drddpgMw="
    >> SCryptUtil.check(passwd,hashed_passwd)
    => true
    >> SCryptUtil.check('wrong password',hashed_passwd)
    => false