Zach -
I don’t know. We struggled quite a bit with getting Bouncy Castle to
fit into to our mixed JRuby/Java Rails application. We felt really
fortunate when our use of Bouncy Castle was no longer needed.
One thing that was quite surprising for us (but doesn’t line up with
anything you’ve said) is that straight-up Jruby applications have a
noticeably different Java classloader than a Warble packaged .war file
running in a Java Servlet container (such as Tomcat). In the Servlet
container setup, Warbler has moved all of the Java jars into
WEB-INF/lib and the container gets those on the Java classpath before
JRuby starts and those jars are in a parent classloader, not JRuby’s
own classloader. A vanilla JRuby run doesn’t bring jars onto the
classpath until they are "require"d.
On Mon, Mar 24, 2014, at 09:15 PM, Zach Margolis wrote:
Bruce, thanks for responding.
As far as I understand it, requiring the -shaded JAR will set up the
classpath, but not load Bouncy Castle. Since Bouncy Castle Provider is
a signed JAR, it can’t be packaged as part of a shaded JAR, so instead
we have maven configured to copy it into target/lib-signed and added to
the classpath of the shaded JAR.
Your suggestion works, it makes the “bad” file run requiring the bouncy
castle JAR directly, adding require
‘target/lib-signed/bcprov-jdk15on.jar’ ahead of the ruby
bouncy-castle-java works.
Unfortunately applying the same order load changes in the actual
project I’m trying to use this in does not work. Is there any way to
insulate this part of the code that depends on 1.5?
Zach Margolis
On Mon, Mar 24, 2014 at 5:48 PM, Bruce A. <[1][email protected]>
wrote:
Zach -
I fear that I don’t understand your question.
You need to explicitly, in the Ruby code, pull in the 1.5 version of
Bouncy Castle before running (which may mean even loading) any code
that uses Bouncy Castle.
I’m not quite sure what your example is showing. Does
require 'target/multiple-bouncy-castle-HEAD-SNAPSHOT-shaded.jar'
include Bouncy Castle itself? What happens if you put that “require”
before this one:
require 'bouncy-castle-java'
Can you directly require the Bouncy Castle jar in your Ruby code and
make sure to do it early?
On Mon, Mar 24, 2014, at 08:31 PM, Zach Margolis wrote:
Hi there,
I would like to be able to load and run a JAR within a JRuby project.
The JAR in particular is compiled and runs against Bouncy Castle 1.5,
so it is not compatible with the version of Bouncy Castle bundled with
JRuby (1.47 in the JAR of JRuby that I have).
What is the right way to load this JAR and execute code from it?
I’ve created a small gist that reproduces the errors from my current
approach, loading the sample BouncyCastleClient from the JAR.
[2]Bouncy Castle Errors · GitHub
Here are a few of the errors from various approaches:
- NameError: missing class or uppercase package name
(`com.demo.BouncyCastleClient’)
- java.lang.SecurityException: class
“org.bouncycastle.jcajce.provider.symmetric.IDEA$Mappings”‘s signer
information does not match signer information of other classes in
the same package
Thanks in advance,
Zach Margolis
References
- mailto:[email protected]
- Bouncy Castle Errors · GitHub