How to use SunMSCAPI in the plugin ?

Answered

Hello guys, I'm going to use the sun.security.mscapi.SunMSCAPI to get the Windwos' CA-Certs to verify the https connection. Because the jdk9 had move the SunMSCAPI  to the jdk.crypto.mscapi module, I add the compile arg like :

compileJava {
options.compilerArgs << "--add-modules=jdk.crypto.mscapi" << "--add-exports=jdk.crypto.mscapi/sun.security.mscapi=ALL-UNNAMED"
}

which works fine when compileJava. But in the runtime it come up with an ClassNotFoundException like :  

Caused by: java.lang.ClassNotFoundException: sun.security.mscapi.SunMSCAPI PluginClassLoader[PluginDescriptor....

Here is my code:

private void test() {
try {
SunMSCAPI sunMSCAPI = new SunMSCAPI();
Security.addProvider(sunMSCAPI);
KeyStore keyStore = KeyStore.getInstance("Windows-MY");
keyStore.load(null, null);
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String element = aliases.nextElement();
Certificate[] chain = keyStore.getCertificateChain(element);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

Any idea how I can do this? or maybe I should just give up to verify the peer Cert?

BTW, the peer Cert is signed by our company's CA-Cert, which is not in the jdk's keyStore

0
4 comments

Using which IDE version do you test your plugin so it fails in the runtime?

0

Using the 2020.2 IU.

0

2020.2 is based on Java 8. Java 11 was introduced with 2020.3.
If you want to use JDK classes introduced in Java 9, you need to start using 2020.3 as a minimal targeted platform along with Java 11.

0

OK  thanks, I'll try to upgrade my IDE. Maybe disable this fearture when the user's IDE is under 2020.3

0

Please sign in to leave a comment.