jruby / jruby-openssl

JRuby's OpenSSL gem
http://www.jruby.org
Other
47 stars 80 forks source link

SSLContext#ciphers= exposes internal exceptions #220

Closed p-mongo closed 3 years ago

p-mongo commented 4 years ago

If I try to assign ciphers to an empty array or an array containing nil, I get a Java::JavaLang::StringIndexOutOfBoundsException.

I expected either an OpenSSL error or a Ruby standard library error in this case.

irb(main):017:0> c=OpenSSL::SSL::SSLContext.new
=> #<OpenSSL::SSL::SSLContext:0x20d87335>
irb(main):018:0> c.ciphers=[]
Traceback (most recent call last):
       16: from org.jruby.RubyKernel.eval(RubyKernel.java:1048)
       15: from org.jruby.RubyKernel.evalCommon(RubyKernel.java:1086)
       14: from org.jruby.ir.interpreter.Interpreter.evalWithBinding(Interpreter.java:182)
       13: from org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:158)
       12: from org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:106)
       11: from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)
       10: from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:361)
        9: from org.jruby.ir.instructions.specialized.OneArgOperandAttrAssignInstr.interpret(OneArgOperandAttrAssignInstr.java:37)
        8: from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:174)
        7: from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:375)
        6: from org.jruby.ext.openssl.SSLContext$INVOKER$i$1$0$set_ciphers.call(SSLContext$INVOKER$i$1$0$set_ciphers.gen)
        5: from org.jruby.ext.openssl.SSLContext.set_ciphers(SSLContext.java:506)
        4: from org.jruby.ext.openssl.SSLContext.matchedCiphers(SSLContext.java:469)
        3: from org.jruby.ext.openssl.CipherStrings.matchingCiphers(CipherStrings.java:515)
        2: from java.base/java.lang.String.charAt(String.java:693)
        1: from java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47)
Java::JavaLang::StringIndexOutOfBoundsException (String index out of range: 0)
irb(main):019:0> c.ciphers=[nil]
Traceback (most recent call last):
       16: from org.jruby.RubyKernel.eval(RubyKernel.java:1048)
       15: from org.jruby.RubyKernel.evalCommon(RubyKernel.java:1086)
       14: from org.jruby.ir.interpreter.Interpreter.evalWithBinding(Interpreter.java:182)
       13: from org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:158)
       12: from org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:106)
       11: from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)
       10: from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:361)
        9: from org.jruby.ir.instructions.specialized.OneArgOperandAttrAssignInstr.interpret(OneArgOperandAttrAssignInstr.java:37)
        8: from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:174)
        7: from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:375)
        6: from org.jruby.ext.openssl.SSLContext$INVOKER$i$1$0$set_ciphers.call(SSLContext$INVOKER$i$1$0$set_ciphers.gen)
        5: from org.jruby.ext.openssl.SSLContext.set_ciphers(SSLContext.java:506)
        4: from org.jruby.ext.openssl.SSLContext.matchedCiphers(SSLContext.java:469)
        3: from org.jruby.ext.openssl.CipherStrings.matchingCiphers(CipherStrings.java:515)
        2: from java.base/java.lang.String.charAt(String.java:693)
        1: from java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47)
Java::JavaLang::StringIndexOutOfBoundsException (String index out of range: 0)

jruby 9.2.13.0 (2.5.7) 2020-08-03 9a89c94bcc OpenJDK 64-Bit Server VM 11.0.9+11-post-Debian-1 on 11.0.9+11-post-Debian-1 +jit [linux-x86_64]

p-mongo commented 3 years ago

MRI behavior:

serene% irb -ropenssl
irb(main):001:0> c=OpenSSL::SSL::SSLContext.new
=> #<OpenSSL::SSL::SSLContext:0x0000558711862638>
irb(main):002:0> c.ciphers=[]
Traceback (most recent call last):
        5: from /home/w/.rbenv/versions/2.7/bin/irb:23:in `<main>'
        4: from /home/w/.rbenv/versions/2.7/bin/irb:23:in `load'
        3: from /home/w/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        2: from (irb):2
        1: from (irb):2:in `ciphers='
OpenSSL::SSL::SSLError (SSL_CTX_set_cipher_list: no cipher match)