Search code examples
encryptionosgiequinoxclassloader

Access to com.sun.crypto.provider in Equinox


I am trying to integrate some pre-existing code that relies on the com.sun.crypto.provider.SunJCE class into our Equinox based application (version 3.7.1). Now I know by default the com.sun packages are not accessible to bundles, so I made a fragment with the idea of extending the framework to export the package. Here is its manifest:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Extension
Bundle-SymbolicName: extension
Bundle-Version: 1.0.0.qualifier
Fragment-Host: system.bundle; extension:=framework
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: com.sun.crypto.provider

Clue 1: The PDE marks the Export-Package line and says that com.sun.crypto.provider does not exist in this plugin.

I created a sample bundle that just instantiates the class in question in the bundle activator. That bundle's manifest is:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Cryptotest
Bundle-SymbolicName: cryptotest
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: cryptotest.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.sun.crypto.provider,
 org.osgi.framework;version="1.3.0"

Clue 2: The PDE marks the instantiation with an access restriction.

Despite the two errors, the project does compile and I am able to start debugging. When starting the sample bundle, I receive a class not found exception. However, when I do a "packages 0" in the console, it appears Equinox is claiming to export this package:

com.sun.crypto.provider;
version="0.0.0"<org.eclipse.osgi_3.7.1.R37x_v20110808-1106 [0]>
 cryptotest_1.0.0.qualifier [2] imports

Now, I have found an ugly work around that appears to work in my minimal example. It is to basically wrap Java's jce provider jar in a separate plugin and include that with my application, but that just seems wrong.

Could somebody please provide some insight into what's going on? Is there something obvious I am missing?


Solution

  • This looks like a package that is present in your JVM, but only when running on a Sun one. These are not exposed by the system bundle by default, because OSGi is not built solely for Sun VMs.

    You can, however, instruct the framework to expose this package. To do so, you set the org.osgi.framework.system.packages.extra property to a list of packages, which includes your com.sun.crypto.provider package. There are several ways to do this, but you could, for instance start Equinox with a system property,

    -Dorg.osgi.framework.system.packages.extra=com.sun.crypto.provider
    

    By the way, this is not Equinox-specific, but a standard OSGi-construct.