Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL hexdigest raises error with empty key #2854

Closed
Magicdream opened this issue Apr 20, 2015 · 1 comment
Closed

OpenSSL hexdigest raises error with empty key #2854

Magicdream opened this issue Apr 20, 2015 · 1 comment
Labels
Milestone

Comments

@Magicdream
Copy link

I found incompatibility in Ruby and JRuby hexdigest implementation.

On Ruby

OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('md5'), "", "foo")
=> "4acb10ca3965a14a080297db0921950c"

On JRuby 1.7.19

OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('md5'), "", "foo")
raises error

Java::JavaLang::IllegalArgumentException: Empty key
    from javax.crypto.spec.SecretKeySpec.<init>(SecretKeySpec.java:96)
    from org.jruby.ext.openssl.HMAC.initialize(HMAC.java:142)
    from org.jruby.ext.openssl.HMAC$INVOKER$i$2$0$initialize.call(HMAC$INVOKER$i$2$0$initialize.gen)
    from org.jruby.internal.runtime.methods.JavaMethod$JavaMethodTwoOrN.call(JavaMethod.java:822)
    from org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:211)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:217)
    from org.jruby.RubyClass.newInstance(RubyClass.java:863)
    from org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)
    from org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZeroOrOneOrTwoOrNBlock.call(JavaMethod.java:314)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:346)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:204)
    from org.jruby.ast.CallTwoArgNode.interpret(CallTwoArgNode.java:59)
    from org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
    from org.jruby.ast.RootNode.interpret(RootNode.java:129)
    from org.jruby.evaluator.ASTInterpreter.INTERPRET_EVAL(ASTInterpreter.java:95)
    from org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:184)
... 120 levels...
    from org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
    from org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:74)
    from org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:139)
    from org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:187)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:306)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:136)
    from script.console.__file__(script/console:7)
    from script.console.load(script/console)
    from org.jruby.Ruby.runScript(Ruby.java:866)
    from org.jruby.Ruby.runScript(Ruby.java:859)
    from org.jruby.Ruby.runNormally(Ruby.java:728)
    from org.jruby.Ruby.runFromMain(Ruby.java:577)
    from org.jruby.Main.doRunFromMain(Main.java:395)
    from org.jruby.Main.internalRun(Main.java:290)
    from org.jruby.Main.run(Main.java:217)
    from org.jruby.Main.main(Main.java:197)jruby-1.7.19

I'm not sure is it possible to fix it, but this is a kind of incompatibility

@Magicdream
Copy link
Author

The ugly way I'm fixing it right now is console command

 %x[/bin/bash -c 'echo -n #{str.shellescape}' | openssl dgst -md5 -hmac '' | cut -d' ' -f 2].strip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants