提交 c0de421c 编写于 作者: X xuelei

7059709: close the IO in a final block

Reviewed-by: smarks, mullan, wetmore
上级 01983949
...@@ -567,42 +567,46 @@ public abstract class SSLContextImpl extends SSLContextSpi { ...@@ -567,42 +567,46 @@ public abstract class SSLContextImpl extends SSLContextSpi {
} }
FileInputStream fs = null; FileInputStream fs = null;
if (defaultKeyStore.length() != 0 && !NONE.equals(defaultKeyStore)) {
fs = AccessController.doPrivileged(
new PrivilegedExceptionAction<FileInputStream>() {
public FileInputStream run() throws Exception {
return new FileInputStream(defaultKeyStore);
}
});
}
String defaultKeyStorePassword = props.get("keyStorePasswd");
char[] passwd = null;
if (defaultKeyStorePassword.length() != 0) {
passwd = defaultKeyStorePassword.toCharArray();
}
/**
* Try to initialize key store.
*/
KeyStore ks = null; KeyStore ks = null;
if ((defaultKeyStoreType.length()) != 0) { char[] passwd = null;
if (debug != null && Debug.isOn("defaultctx")) { try {
System.out.println("init keystore"); if (defaultKeyStore.length() != 0 &&
!NONE.equals(defaultKeyStore)) {
fs = AccessController.doPrivileged(
new PrivilegedExceptionAction<FileInputStream>() {
public FileInputStream run() throws Exception {
return new FileInputStream(defaultKeyStore);
}
});
} }
if (defaultKeyStoreProvider.length() == 0) {
ks = KeyStore.getInstance(defaultKeyStoreType); String defaultKeyStorePassword = props.get("keyStorePasswd");
} else { if (defaultKeyStorePassword.length() != 0) {
ks = KeyStore.getInstance(defaultKeyStoreType, passwd = defaultKeyStorePassword.toCharArray();
defaultKeyStoreProvider);
} }
// if defaultKeyStore is NONE, fs will be null /**
ks.load(fs, passwd); * Try to initialize key store.
} */
if (fs != null) { if ((defaultKeyStoreType.length()) != 0) {
fs.close(); if (debug != null && Debug.isOn("defaultctx")) {
fs = null; System.out.println("init keystore");
}
if (defaultKeyStoreProvider.length() == 0) {
ks = KeyStore.getInstance(defaultKeyStoreType);
} else {
ks = KeyStore.getInstance(defaultKeyStoreType,
defaultKeyStoreProvider);
}
// if defaultKeyStore is NONE, fs will be null
ks.load(fs, passwd);
}
} finally {
if (fs != null) {
fs.close();
fs = null;
}
} }
/* /*
......
...@@ -164,72 +164,75 @@ abstract class TrustManagerFactoryImpl extends TrustManagerFactorySpi { ...@@ -164,72 +164,75 @@ abstract class TrustManagerFactoryImpl extends TrustManagerFactorySpi {
* If none exists, we use an empty keystore. * If none exists, we use an empty keystore.
*/ */
storeFileName = props.get("trustStore"); try {
if (!"NONE".equals(storeFileName)) { storeFileName = props.get("trustStore");
if (storeFileName != null) { if (!"NONE".equals(storeFileName)) {
storeFile = new File(storeFileName); if (storeFileName != null) {
fis = getFileInputStream(storeFile); storeFile = new File(storeFileName);
} else {
String javaHome = props.get("javaHome");
storeFile = new File(javaHome + sep + "lib" + sep
+ "security" + sep +
"jssecacerts");
if ((fis = getFileInputStream(storeFile)) == null) {
storeFile = new File(javaHome + sep + "lib" + sep
+ "security" + sep +
"cacerts");
fis = getFileInputStream(storeFile); fis = getFileInputStream(storeFile);
} else {
String javaHome = props.get("javaHome");
storeFile = new File(javaHome + sep + "lib" + sep
+ "security" + sep +
"jssecacerts");
if ((fis = getFileInputStream(storeFile)) == null) {
storeFile = new File(javaHome + sep + "lib" + sep
+ "security" + sep +
"cacerts");
fis = getFileInputStream(storeFile);
}
} }
}
if (fis != null) { if (fis != null) {
storeFileName = storeFile.getPath(); storeFileName = storeFile.getPath();
} else { } else {
storeFileName = "No File Available, using empty keystore."; storeFileName = "No File Available, using empty keystore.";
}
} }
}
defaultTrustStoreType = props.get("trustStoreType"); defaultTrustStoreType = props.get("trustStoreType");
defaultTrustStoreProvider = props.get("trustStoreProvider"); defaultTrustStoreProvider = props.get("trustStoreProvider");
if (debug != null && Debug.isOn(dbgname)) {
System.out.println("trustStore is: " + storeFileName);
System.out.println("trustStore type is : " +
defaultTrustStoreType);
System.out.println("trustStore provider is : " +
defaultTrustStoreProvider);
}
/*
* Try to initialize trust store.
*/
if (defaultTrustStoreType.length() != 0) {
if (debug != null && Debug.isOn(dbgname)) { if (debug != null && Debug.isOn(dbgname)) {
System.out.println("init truststore"); System.out.println("trustStore is: " + storeFileName);
} System.out.println("trustStore type is : " +
if (defaultTrustStoreProvider.length() == 0) { defaultTrustStoreType);
ks = KeyStore.getInstance(defaultTrustStoreType); System.out.println("trustStore provider is : " +
} else { defaultTrustStoreProvider);
ks = KeyStore.getInstance(defaultTrustStoreType,
defaultTrustStoreProvider);
} }
char[] passwd = null;
String defaultTrustStorePassword = props.get("trustStorePasswd");
if (defaultTrustStorePassword.length() != 0)
passwd = defaultTrustStorePassword.toCharArray();
// if trustStore is NONE, fis will be null /*
ks.load(fis, passwd); * Try to initialize trust store.
*/
if (defaultTrustStoreType.length() != 0) {
if (debug != null && Debug.isOn(dbgname)) {
System.out.println("init truststore");
}
if (defaultTrustStoreProvider.length() == 0) {
ks = KeyStore.getInstance(defaultTrustStoreType);
} else {
ks = KeyStore.getInstance(defaultTrustStoreType,
defaultTrustStoreProvider);
}
char[] passwd = null;
String defaultTrustStorePassword =
props.get("trustStorePasswd");
if (defaultTrustStorePassword.length() != 0)
passwd = defaultTrustStorePassword.toCharArray();
// if trustStore is NONE, fis will be null
ks.load(fis, passwd);
// Zero out the temporary password storage // Zero out the temporary password storage
if (passwd != null) { if (passwd != null) {
for (int i = 0; i < passwd.length; i++) { for (int i = 0; i < passwd.length; i++) {
passwd[i] = (char)0; passwd[i] = (char)0;
}
} }
} }
} } finally {
if (fis != null) {
if (fis != null) { fis.close();
fis.close(); }
} }
return ks; return ks;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册