未验证 提交 c9a36993 编写于 作者: J Jai Asher 提交者: GitHub

Fixing resource leak due to open file descriptors in SecurityUtility.java (#1851)

上级 b3d52562
......@@ -58,7 +58,7 @@ public class SecurityUtility {
}
public static SslContext createNettySslContextForClient(boolean allowInsecureConnection, String trustCertsFilePath)
throws GeneralSecurityException, SSLException, FileNotFoundException {
throws IOException, GeneralSecurityException, SSLException, FileNotFoundException {
return createNettySslContextForClient(allowInsecureConnection, trustCertsFilePath, (Certificate[]) null,
(PrivateKey) null);
}
......@@ -73,7 +73,7 @@ public class SecurityUtility {
public static SslContext createNettySslContextForClient(boolean allowInsecureConnection, String trustCertsFilePath,
String certFilePath, String keyFilePath)
throws GeneralSecurityException, SSLException, FileNotFoundException {
throws IOException, GeneralSecurityException, SSLException, FileNotFoundException {
X509Certificate[] certificates = loadCertificatesFromPemFile(certFilePath);
PrivateKey privateKey = loadPrivateKeyFromPemFile(keyFilePath);
return createNettySslContextForClient(allowInsecureConnection, trustCertsFilePath, certificates, privateKey);
......@@ -81,13 +81,15 @@ public class SecurityUtility {
public static SslContext createNettySslContextForClient(boolean allowInsecureConnection, String trustCertsFilePath,
Certificate[] certificates, PrivateKey privateKey)
throws GeneralSecurityException, SSLException, FileNotFoundException {
throws GeneralSecurityException, IOException, FileNotFoundException {
SslContextBuilder builder = SslContextBuilder.forClient();
if (allowInsecureConnection) {
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
} else {
if (trustCertsFilePath != null && trustCertsFilePath.length() != 0) {
builder.trustManager(new FileInputStream(trustCertsFilePath));
try (FileInputStream input = new FileInputStream(trustCertsFilePath)) {
builder.trustManager(input);
}
}
}
builder.keyManager(privateKey, (X509Certificate[]) certificates);
......@@ -96,7 +98,7 @@ public class SecurityUtility {
public static SslContext createNettySslContextForServer(boolean allowInsecureConnection, String trustCertsFilePath,
String certFilePath, String keyFilePath)
throws GeneralSecurityException, SSLException, FileNotFoundException {
throws IOException, GeneralSecurityException, SSLException, FileNotFoundException {
X509Certificate[] certificates = loadCertificatesFromPemFile(certFilePath);
PrivateKey privateKey = loadPrivateKeyFromPemFile(keyFilePath);
......@@ -105,7 +107,9 @@ public class SecurityUtility {
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
} else {
if (trustCertsFilePath != null && trustCertsFilePath.length() != 0) {
builder.trustManager(new FileInputStream(trustCertsFilePath));
try (FileInputStream input = new FileInputStream(trustCertsFilePath)) {
builder.trustManager(input);
}
} else {
builder.trustManager((File) null);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册