This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Creating native binaries using GNU-Crypto
On Wed, 2003-12-10 at 16:33, Andrew Haley wrote:
> Stefan Prelle writes:
> > I'm trying to build a native executable that uses the GNU-Crypto JCE
> > implementation. I can link against the libraries that were installed by
> > GNU-Crypto but when I execute the program it fails to load the providers
> > class.
> >
> > The code is roughly like this:
> >
> > Provider prov = (Provider)Class.forName("gnu.crypto.jce.GnuCrypto");
> > Security.addProvider(prov);
> >
> > On execution Class.forName fails although the class exists in the shared
> > library and the corresponding jar-file.
>
> This should work. You need to say much more precisely what you did,
> with examples. We also need to know what system you were using.
Of course.
The environment is a Linux/x86,
gcc version is 3.4 20030925 (experimental)
GNU crypto was installed at prefix /home/prelle/platform/linuxpc
where it placed two shared objects (lib-gnu-crypto.so and
lib-javax-crypto.so) in the lib-path.
-- Source code (reduced):
public class JCETest {
public static void main(String[] argv) {
try {
Class cls = Class.forName("gnu.crypto.jce.GnuCrypto");
System.out.println("Shouldn't be null: "+cls);
} catch (Exception e){
e.printStackTrace();
}
}
}
The environment is a Linux/x86,
gcc version is 3.4 20030925 (experimental)
-- Compiling my application
-----------------------------
if gcj -g -O2 -MT org/mbus/apps/JCETest.o -MD -MP -MF
"org/mbus/apps/.deps/JCETest.Tpo" \
-c -o org/mbus/apps/JCETest.o `test -f 'org/mbus/apps/JCETest.java' ||
echo './'`org/mbus/apps/JCETest.java; \
then mv -f "org/mbus/apps/.deps/JCETest.Tpo"
"org/mbus/apps/.deps/JCETest.Po"; \
else rm -f "org/mbus/apps/.deps/JCETest.Tpo"; exit 1; \
fi
-- Linking
-----------------------------
/bin/sh ../libtool --mode=link gcj -g -O2 -o jcetest -l-javax-crypto
-l-gnu-crypto --main=org.mbus.apps.JCETest org/mbus/apps/JCETest.o
libjmbus.la
gcj -g -O2 -o .libs/jcetest --main=org.mbus.apps.JCETest
org/mbus/apps/JCETest.o -L/local/prelle/src/gnu-crypto-1.1.0/build/jce
./.libs/libjmbus /home/prelle/platform/linuxpc/lib/lib-gnu-crypto.so
/home/prelle/platform/linuxpc/lib/lib-javax-crypto.so -Wl,--rpath
-Wl,/home/prelle/platform/linuxpc/lib
-- Result
-----------------------------
rubin->jcetest
java.lang.ClassNotFoundException: gnu.crypto.jce.GnuCrypto not found in
[file:./, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String)
(/local/prelle/lib/libgcj.so.4.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String)
(/local/prelle/lib/libgcj.so.4.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean)
(/local/prelle/lib/libgcj.so.4.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader)
(/local/prelle/lib/libgcj.so.4.0.0)
at java.lang.Class.forName(java.lang.String, boolean,
java.lang.ClassLoader) (/local/prelle/lib/libgcj.so.4.0.0)
at java.lang.Class.forName(java.lang.String)
(/local/prelle/lib/libgcj.so.4.0.0)
at gnu.gcj.runtime.FirstThread.call_main()
(/local/prelle/lib/libgcj.so.4.0.0)
at gnu.gcj.runtime.FirstThread.run()
(/local/prelle/lib/libgcj.so.4.0.0)
at _Jv_ThreadRun(java.lang.Thread)
(/local/prelle/lib/libgcj.so.4.0.0)
at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean)
(/local/prelle/lib/libgcj.so.4.0.0)
at JvRunMain (/local/prelle/lib/libgcj.so.4.0.0)
at __libc_start_main (/lib/libc-2.2.4.so)
The symbol is defined in the shared library:
rubin->nm --demangle /home/prelle/platform/linuxpc/lib/lib-gnu-crypto.so
|grep GnuCrypto
000bbac0 d _CD_gnu_crypto_jce_GnuCrypto
000b38a0 d _CT_gnu_crypto_jce_GnuCrypto
000bb900 d _MT_gnu_crypto_jce_GnuCrypto
00089b40 T gnu::crypto::jce::GnuCrypto::getMacNames()
00089b70 T gnu::crypto::jce::GnuCrypto::getCipherNames()
00089c30 T gnu::crypto::jce::GnuCrypto::getSignatureNames()
00089cc0 T gnu::crypto::jce::GnuCrypto::getSecureRandomNames()
00089c90 T gnu::crypto::jce::GnuCrypto::getMessageDigestNames()
00089c60 T gnu::crypto::jce::GnuCrypto::getKeyPairGeneratorNames()
000bba40 D gnu::crypto::jce::GnuCrypto::class$
00089f50 T gnu::crypto::jce::GnuCrypto::GnuCrypto()
000bb9a0 D vtable for gnu::crypto::jce::GnuCrypto
Regards,
Stefan