I would like to load a MSCAPI keystore
within Java and examine available certificates in the MY store. However some keys for those certificates reside on hardware tokens and a popup asks for the token during load.
Is there a way to defer loading the private keys when loading the Windows keystore?
keyStore = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
keystore.load(null,null);
The popup is being activated from the MS-CAPI Cryptographic Service Provider (CSP) - the DLL supplied by the USB token manufacturer - which finally communicates to the token through a driver (also supplied by the token-manufacturer). KeyStore merely makes a call and the layers in between just pass it through; the firmware on the token is the one that throws up the authentication pop-up and maintains session-state, etc.
The key Java dll is sunmscapi.dll which has the implementation:
As you can see it always checks for a private key. You would have to modify this code and create a custom version of sunmscapi.dll to avoid this or otherwise defeat this check.
This issue has been solved in JDK 9.
https://bugs.openjdk.java.net/browse/JDK-8153438
http://hg.openjdk.java.net/jdk9/dev/jdk/rev/e7f78523d41d