-
Notifications
You must be signed in to change notification settings - Fork 83
Closed
Labels
Description
When using an instance of the class OpenSSL::ASN1::PrintableString
, it raises an IllegalArgumentException
when it is encoded back to a DERPrintableString
, e.g. when calling #to_der
.
require 'openssl'
printable = OpenSSL::ASN1::PrintableString.new("test1234")
printable.to_der # raises exception
This generates the following stack trace:
NativeException: java.lang.IllegalArgumentException: encoding error in getInstance: java.io.EOFException: DEF length 101 object truncated by 95
from org.bouncycastle.asn1.DERPrintableString:-1:in `getInstance'
from sun/reflect/NativeMethodAccessorImpl.java:-2:in `invoke0'
from sun/reflect/NativeMethodAccessorImpl.java:62:in `invoke'
from sun/reflect/DelegatingMethodAccessorImpl.java:43:in `invoke'
from java/lang/reflect/Method.java:498:in `invoke'
from org/jruby/ext/openssl/ASN1.java:693:in `typeInstance'
from org/jruby/ext/openssl/ASN1.java:1736:in `toASN1'
from org/jruby/ext/openssl/ASN1.java:1612:in `toDER'
from org/jruby/ext/openssl/ASN1.java:1430:in `to_der'
from org/jruby/ext/openssl/ASN1.java:1523:in `to_der'
from org/jruby/ext/openssl/ASN1$Primitive$INVOKER$i$0$0$to_der.gen:-1:in `call'
from org/jruby/runtime/callsite/CachingCallSite.java:306:in `cacheAndCall'
from org/jruby/runtime/callsite/CachingCallSite.java:136:in `call'
from org/jruby/ast/CallNoArgNode.java:60:in `interpret'
from org/jruby/ast/NewlineNode.java:105:in `interpret'
from org/jruby/ast/RootNode.java:129:in `interpret'
... 132 levels...
The same function works fine on C-Ruby and returns a String. The program above was tested with JRuby 1.7.25.
My best guess is the object that is given to the method org.bouncycastle.asn1.DERPrintableString.getInstance
is not of type DERPrintableString
and is handled as a byte array leading to the exception.
If you need further information or if I can be of any help, please let me know.
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/36564466-openssl-asn1-printablestring-to_der-raises-exception?utm_campaign=plugin&utm_content=tracker%2F136995&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F136995&utm_medium=issues&utm_source=github).