Sitelet https://github.com/jruby/jruby/issues/2854
Skip to content

OpenSSL hexdigest raises error with empty key #2854

Description

@Magicdream

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions