javajarbouncycastlesshj

How to implement bouncycastle into one-jar?


I'm using SSHJ-library in a project. SSHJ library utilized the bouncycastle crypto.

In eclipse all is good but after I use one-jar to package all in single jar package, I'm facing issues with the bouncycastle lib. The bcprov-jdk15on-1.51.jar is included in the JAR package in /lib, where is all the other libraries, as well as eg. sshj.jar.

On log I have these:

Security Provider class 'org.bouncycastle.jce.provider.BouncyCastleProvider' not found

and this

WARNING: Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy

And with the functionality the SFTP connection is resulting into:

net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [diffie-hellman-group1-sha1, diffie-hellman-group-exchange-sha1] and [diffie-hellman-group-exchange-sha256]

What I have tried:

This is how all work "as expected":

So, clearly there is some classpath issue with the BC libary? Somewhere I read something about signed security provider library having an issues implementing, did not quite understand that one... Maybe that is the reason here too?

Any ideas how this issue is solved? Any help on this issue is appreciated, thanks!

EDIT: My build.xml with suggested code-signing implemented:

    <target name="package_x" depends="package_y">
    <!-- Create manifest file for x -->
    <delete file="MANIFEST.MF"/>
    <manifest file="MANIFEST.MF">
        <attribute name="Main-Class" value="com.simontuffs.onejar.Boot"/>
        <attribute name="One-Jar-Main-Class" value="com.some.main.class.name"/>
        <attribute name="Class-Path" value="some_other_libs lib/bcprov-jdk15on.jar ." />
    </manifest>

    <!-- Copy properties file -->
    <copy todir="${module.dist.dir}">
        <fileset dir="${module.x.build.dir}/classes">
            <include name="**/*.properties"/>
        </fileset>
    </copy>

        <signjar destDir="${basedir}/distribute/lib/" 
                alias="server" keystore="${module.x.src.dir}/keystore/myCSC.jks"
                storepass="pass"
                preservelastmodified="true">
            <path>
                <fileset dir="${basedir}/distribute/lib/" includes="bcprov-jdk15on.jar" />
            </path>
            <flattenmapper />
        </signjar>

    <!-- Construct the One-JAR file -->
    <echo message="Creating a ONE-jar package of the x files..." />

    <one-jar destfile="${module.dist.dir}/${module.x.package}" manifest="MANIFEST.MF">
        <main>
            <fileset dir="${module.x.build.dir}/classes/">
                <exclude name="x-config.properties"/>
            </fileset>
        </main>

        <lib>               
            <fileset dir="${basedir}/distribute/lib/" />
            <fileset dir="${module.common.dist.dir}" />

        </lib>
    </one-jar>

        <signjar destDir="${module.dist.dir}" 
                alias="server" keystore="${module.agent.src.dir}/keystore/myCSC.jks"
                storepass="pass"
                preservelastmodified="true">
            <path>
                <fileset dir="${module.dist.dir}" includes="**/*.jar" />
            </path>
            <flattenmapper />
        </signjar>

</target>

Solution

  • Answering my own guestion:

    Two solutions:

    1. Add library to Java's lib/ext
      • this really was not a solution for me but might work for someone else.
    2. Use JDotSoft JarClassLoader
      • Simple to use and seems to provide support for adding JCE providers such as Bouncycastle.
      • added the BC-jar into main JAR by Ant build: <zipfileset dir="/build/libsToInclude/" includes="*.jar" prefix="lib/"/> and the classloader did the rest.