PKCS11PrivateKeyFactoryBean doesn't work under Java 11

Description

The PKCS11PrivateKeyFactoryBean acquires a configured PKCS#11 provider by:

  • Using reflection to get the 1-string-arg constructor for the keystore provider class,

  • Calling that constructor with the pkcs11Config value to generate the Provider to use.

As far as I'm aware, that was the only way to do this (without editing the global java.security file) when we pulled this code together originally; it may or may not be the only way to do it in Java 8 but as described below I don't know of one.

This doesn't work in Java 9; that constructor has been removed. Instead, you must acquire an unconfigured provider using Security.getProvider("SunPKCS11") and calling its #configure to generate a new, configured, provider.

The existence by default of the unconfigured provider, and the presence of the #configure API, starts with Java 9, the same release in which I think reflective access stopped working.

As a result, I don't think there's a way to fix this on the 5.x (IdP 3.x) branch. On the other hand, this was a relatively late addition and I guess it turns out no-one who has used it is running Java 11 yet.

It's a relatively simple fix for the 6.x (IdP 4.x) branch. I'll add some kind of test while I am there, although I will need to disable the bulk of it as our test environments don't include hardware crypto tokens.

Environment

None

Activity

Show:

Ian Young September 24, 2020 at 3:59 PM

Commit a59192aebd2334001bcff44749ec0933dbcb5fce fixes this for the 6.x (IdP 4.x, MDA 0.10/1.0) branch.

This is a WONTFIX for the 5.x branch.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Fix versions

Affects versions

Created September 15, 2020 at 4:39 PM
Updated March 22, 2021 at 9:52 PM
Resolved September 24, 2020 at 3:59 PM