Search code examples
mavenosgibouncycastleapache-karaf

bundle will not start when bouncy castle is imported


I am trying to add bouncy castle as a service provider to my java product running on apache karaf. When I am trying to start the bundle which imports bouncy castle I get an error message

java.lang.Exception: Could not start bundle mvn:com.xxx.yyy.zzz/docsservice/1.0.0-SNAPSHOT/war in feature(s) server-docs-1.0.0-SNAPSHOT: Unresolved constraint in bundle docs [245]: Unable to resolve 245.0: missing requirement [245.0] osgi.wiring.package; (&(osgi.wiring.package=org.bouncycastle.jce.provider)(version>=1.51.0)) at org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:472)

In the pom file I imported the package org.bouncycastle.jce.provider and I added bouncycastle as a dependency. Also, i made all the changes described on this page, http://karaf.apache.org/manual/latest/users-guide/security.html, see below

  1. I put provider jar in lib/ext
  2. I Modified the etc/config.properties configuration file to add the following property org.apache.karaf.security.providers = xxx,yyy

org.apache.karaf.security.providers = org.bouncycastle.jce.provider.BouncyCastleProvider

  1. I provided access to the classes from those providers from the system bundle so that all bundles can access those. I did this by modifying the org.osgi.framework.bootdelegation property in the same configuration file:

org.osgi.framework.bootdelegation = ...,org.bouncycastle*

  1. On some forum I found another suggestion so I modified *org.osgi.framework.system.packages.extra = * in the config.properties as well and I added here packages exported from bouncycastle

Nonetheless I wasn't able to load the bundle successfully. I looked at all the bundles loaded by karaf and none of them was exporting bouncy castle package. What am I missing here? How can I make the bundles to start?


Solution

  • By adding the package to the boot delegation you made it available like java.* packages. For these you do not need an Import-Package. So one way would be to remove the Import-Package for it in your bundle. You should rather explore though if you can work without boot delegation.

    Please try to remove the boot delegation and add the package to

    org.osgi.framework.system.packages.extra = org.bouncycastle.jce.provider
    

    This adds the package to the packages the system bundle exports. It should then be wired to your bundle.