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

Calling .to_der raises " undefined method `[]' for #<OpenSSL::ASN1::Sequence>" error #282

Closed
skunkworker opened this issue Aug 11, 2023 · 3 comments

Comments

@skunkworker
Copy link
Contributor

Recently I've been running into this error and was able to make a minimum reproducible example.

Expected (MRI openssl)

data_sequence = ::OpenSSL::ASN1::Sequence([::OpenSSL::ASN1::Integer(0)])
asn1 = ::OpenSSL::ASN1::Sequence(data_sequence)
asn1.to_der =>  "0\x03\x02\x01\x00"

Actual (JRuby-openssl)

data_sequence = ::OpenSSL::ASN1::Sequence([::OpenSSL::ASN1::Integer(0)])
asn1 = ::OpenSSL::ASN1::Sequence(data_sequence)
asn1.to_der => NoMethodError (undefined method `[]' for #<OpenSSL::ASN1::Sequence:0x389a9ff6>)
@skunkworker
Copy link
Contributor Author

Some of the backtrace.

 => #<OpenSSL::ASN1::Sequence:0xcb29b75 @value=[#<OpenSSL::ASN1::Integer:0x3674164b @value=0, @tag=2, @indefinite_length=false, @tagging=nil, @tag_class=:UNIVERSAL>], @tag=16, @indefinite_length=false, @tagging=nil, @tag_class=:UNIVERSAL>
jruby-9.3.9.0 :002 > asn1 = ::OpenSSL::ASN1::Sequence(data_sequence); asn1.to_der
2023-08-14T15:35:28.938-07:00 [main] INFO TraceType : Exception raised: NoMethodError : undefined method `[]' for #<OpenSSL::ASN1::Sequence:0xcb29b75>
2023-08-14T15:35:28.939-07:00 [main] INFO TraceType : Backtrace generated:
               getStackTrace at java/lang/Thread.java:1610
            getBacktraceData at org/jruby/runtime/backtrace/TraceType.java:247
                getBacktrace at org/jruby/runtime/backtrace/TraceType.java:53
            captureBacktrace at org/jruby/RubyException.java:402
                    preRaise at org/jruby/exceptions/RaiseException.java:208
                      <init> at org/jruby/exceptions/RaiseException.java:65
                      <init> at org/jruby/exceptions/Exception.java:39
                      <init> at org/jruby/exceptions/StandardError.java:38
                      <init> at org/jruby/exceptions/NameError.java:38
                      <init> at org/jruby/exceptions/NoMethodError.java:38
          constructThrowable at org/jruby/RubyNoMethodError.java:68
                 toThrowable at org/jruby/RubyException.java:364
            newNoMethodError at org/jruby/Ruby.java:4141
               methodMissing at org/jruby/RubyKernel.java:227
               methodMissing at org/jruby/RubyKernel.java:211
                        call at org/jruby/RubyKernel.java:130
                        call at org/jruby/internal/runtime/methods/DynamicMethod.java:222
           callMethodMissing at org/jruby/runtime/Helpers.java:143
                     finvoke at org/jruby/RubyClass.java:792
                      invoke at org/jruby/runtime/Helpers.java:652
                  callMethod at org/jruby/RubyBasicObject.java:357
       toASN1EncodableVector at org/jruby/ext/openssl/ASN1.java:1942
                      toASN1 at org/jruby/ext/openssl/ASN1.java:1824
                       toDER at org/jruby/ext/openssl/ASN1.java:1422
                       toDER at org/jruby/ext/openssl/ASN1.java:1883
                      to_der at org/jruby/ext/openssl/ASN1.java:1412
                      to_der at org/jruby/ext/openssl/ASN1.java:1856
                        call at org/jruby/ext/openssl/ASN1$Constructive$INVOKER$i$0$0$to_der.gen:-1
                cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:351
                        call at org/jruby/runtime/callsite/CachingCallSite.java:144
                 processCall at org/jruby/ir/interpreter/InterpreterEngine.java:345
                   interpret at org/jruby/ir/interpreter/StartupInterpreterEngine.java:72
              INTERPRET_EVAL at org/jruby/ir/interpreter/Interpreter.java:106
                  evalCommon at org/jruby/ir/interpreter/Interpreter.java:157
             evalWithBinding at org/jruby/ir/interpreter/Interpreter.java:182
                  evalCommon at org/jruby/RubyKernel.java:1129
                        eval at org/jruby/RubyKernel.java:1091

@skunkworker
Copy link
Contributor Author

Also fails for ASN1::Set nested set objects.

::OpenSSL::ASN1::Set.new(::OpenSSL::ASN1::Set.new([::OpenSSL::ASN1::Integer(0), ::OpenSSL::ASN1::Integer(1)])).to_der

@kares
Copy link
Member

kares commented Apr 11, 2024

seems to be fixed now in JOSSL 0.14.4 (likely thanks to @HoneyryderChuck e1cdc0a)

@kares kares closed this as completed Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants