Unable to use smack in OSGi environment

openHAB (a smart home platform) uses the Smack library in several bindings. After upgrading to version 4.4.0 or later, we ran into issues loading the library in Karaf.

  1. smack-core depends on sun.security.pkcs11. This is a Sun‑specific package that is not supported by all JREs, which limits the range of compatible runtimes. It is generally best practice not to use sun.* packages directly. In addition, OSGi environments like Karaf do not export these packages, which prevents Smack from being used there. Typically, Bouncy Castle is used as an alternative for PKCS#11 functionality.
  2. smack-core depends on hsluv 0.2, whose manifest is missing OSGi headers. We have already opened an issue in their repository (hsluv/hsluv#93) but also wanted to make you aware. If possible, it might make sense to drop or replace this dependency.

Thanks for your post. I’ll have a look into the situation.

And thanks for trying to bump Smack in OpenHAB from a fellow OpenHAB user. :slight_smile:

Looking for references to sun.security.pkcs11
I found it at ConnectionConfiguration.java:1273
and that leads to SSLContext config PR

I created pullrequest 654

That’s only a soft dependency via reflection, isn’t it? Could you elaborate on the issues you are seeing?

As far as I can tell, it’s not smack-core that depends on hsluv, but smack-experimental.

If you don’t use o.j.smackx.colors, then you don’t need the hsluv library in the classpath. Some build systems, like gradle, allow to filter out dependencies in such cases. Maybe that is an option for you? Alternatively, OpenHAB may not require smack-experimental?

i might filter out hsluv. Thanks.

The most problematic is the depndency on sun.security.pkcs11

When the bundle is loaded in Karaf, it throws this error:

missing requirement [smack-core/4.4.8] osgi.wiring.package; filter:=“(osgi.wiring.package=sun.security.pkcs11)”]]]

From what i understand one should not rely on this package. Searching the smack code, i found only the related part in the PR. Possibly this dependency is added by reflection into the manifest.
When digging into it, i noticed the code is a bad practice and updated it to the suggested code.

Avoid using sun.security.pkcs11 directly. It is an internal JDK package, not part of the official Java API, and may change or be removed in future Java versions. For compatibility and stability, use standard Java security APIs or official PKCS#11 libraries instead.

I was able to filter sun.security.pkcssee

Could you give Smack 4.5.0-beta8 a try and report back?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.