我的JavaWS应用程序将在一个实习网络中运行,因此它使用公司自己的证书签名,SSL证书也来自公司的根CA。因此,我用一个类扩展了我的应用程序,该类应该自动导入证书,这可以从控制台和IDE运行,但如果应用程序由javawebstart执行则不行:(
密码
cf = CertificateFactory.getInstance("X.509");
signCertIn = ClassLoader.class.getResourceAsStream((pack + signCertName + ".cer"));
sslCertIn = ClassLoader.class.getResourceAsStream((pack + sslCertName) + ".crt");
File file = new File(new File(System.getProperty("java.home") + SEP + "lib" + SEP + "security"), "cacerts");
javaCertIn = new FileInputStream(file);
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(javaCertIn, passphrase);
javaCertIn.close();
if (!keystore.containsAlias(signCertName)) {
bis = new BufferedInputStream(signCertIn); // <<<<<<< Exception thrown here
while (bis.available() > 0) {
Certificate cert = cf.generateCertificate(bis);
keystore.setCertificateEntry(signCertName, cert);
}
save = true;
signCertIn.close();
}
if (!keystore.containsAlias(sslCertName)) {
bis = new BufferedInputStream(sslCertIn);
while (bis.available() > 0) {
Certificate cert = cf.generateCertificate(bis);
keystore.setCertificateEntry(sslCertName, cert);
}
save = true;
sslCertIn.close();
}
if (save) {
OutputStream out = new FileOutputStream(file);
keystore.store(out, passphrase);
out.close();
}
JavaWS控制台输出
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.available(Unknown Source)
at at.sviss.util.cert.Certificates.install(Certificates.java:48)
at at.sviss.Main.main(Main.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)