javaappletjrubysigner

How to make gems work properly in a Jruby applet?


I've been trying to solve this problem for 3 days now and I simply can't find a solution.

So, I have downloaded the Jruby-complete-1.7.3 jar. After which, I have attempted to install the gem 'nokogiri' using the basic method:

java -jar jruby-complete-1.7.3 -S gem install nokogiri

In addition, I have a separate jar which was created using the Gem-In-A-Jar method. Note that this extra jar is only a result of trying to fix the problem below.

In both cases, when I test it out via the irb, it shows me the following:

require 'nokogiri'
=> true

Now, the problem arises when I try to use the jruby jar in an applet within my web application. To be specific, I'll mention that I can load the jar itself and interact with it from my applet, if I don't try to access any gem files (specifically nokogiri in this case). However, to make this happen, I am required to sign the jar.

If the jar is unsigned, it fails to work, as my Ruby instance fails to be created. When it is signed, it works fine.

The issue is that once the jar is signed, I attempt to call the same command I did before, and I get the following error:

require 'nokogiri'

LoadError: load error: nokogiri/nokogiri -- java.lang.RuntimeException: 
(LoadError) class "nokogiri.EncodingHandler$INVOKDER$s$1$0$get"'s signer
information does not match signer information of other classes in the same
package.

I've been searching around quite a bit in regards to the cause and potential solutions to this error, but I am unable to figure out why the gem itself is causing it. While using the Gem-In-A-Jar method, I did use the same key to sign the gem_jar.

UPDATE: Turns out I was wrong. Each gem installed comes with its own jar file within the lib directory. These jars need to be signed with the same key. After doing so, the above issue was resolved. However, the one below remains.

Additionally, when I attempt to run it in my web-application, I get the following message:

classpath:/META-INF/jruby.home/lib/ruby/shared/rubygems.rb:396 warning: 
can't canonicalize loaded names due to security restrictions; disabling

I assume this is the exception thrown when the error mentioned above occurs, but I can't say for sure.

I would sincerely appreciate anyone that can tell me what I've done wrong, or provide suggestions on how to fix it. If I have phrased the question wrong or have not provided enough information, do let me know.

Thanks


Solution

  • One solution is to use the SDK tools to strip the signatures from every Jar and digitally sign them all freshly.